Show top-level title in seach, hide to-do's.
This commit is contained in:
parent
7bad44cfb6
commit
d71c28d1e8
@ -55,7 +55,7 @@ def create_db(path):
|
||||
os.unlink(path)
|
||||
|
||||
db = sqlite3.connect(path)
|
||||
db.execute('CREATE VIRTUAL TABLE note_search USING fts5(note_id, title, body);')
|
||||
db.execute('CREATE VIRTUAL TABLE note_search USING fts5(note_id, title, body, top_level_title, is_done, is_todo);')
|
||||
return db
|
||||
|
||||
def load_all(top_dir_relative):
|
||||
@ -191,12 +191,19 @@ def regen_all(src_top, dest_top, *, docs=None, db=None):
|
||||
"depth": headline.depth,
|
||||
}
|
||||
|
||||
topLevelHeadline = headline
|
||||
while isinstance(topLevelHeadline.parent, org_rw.Headline):
|
||||
topLevelHeadline = topLevelHeadline.parent
|
||||
|
||||
# Save for full-text-search
|
||||
cur.execute('''INSERT INTO note_search(note_id, title, body) VALUES (?, ?, ?);''',
|
||||
cur.execute('''INSERT INTO note_search(note_id, title, body, top_level_title, is_done, is_todo) VALUES (?, ?, ?, ?, ?, ?);''',
|
||||
(
|
||||
headline.id,
|
||||
headline.title.get_text(),
|
||||
''.join(headline.get_contents('raw')),
|
||||
topLevelHeadline.title.get_text(),
|
||||
headline.is_done,
|
||||
headline.is_todo,
|
||||
))
|
||||
|
||||
# Render HTML
|
||||
|
@ -64,7 +64,7 @@ func main() {
|
||||
|
||||
query := c.Query("q")
|
||||
|
||||
stm, err := db.Prepare("SELECT note_id, title FROM note_search WHERE title LIKE ?")
|
||||
stm, err := db.Prepare("SELECT note_id, title, top_level_title, is_done, is_todo FROM note_search WHERE title LIKE ?")
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -90,8 +90,17 @@ func main() {
|
||||
for rows.Next() {
|
||||
var note_id string
|
||||
var note_title string
|
||||
var note_top_level_title string
|
||||
var note_is_done string
|
||||
var note_is_todo string
|
||||
|
||||
err = rows.Scan(¬e_id, ¬e_title)
|
||||
err = rows.Scan(
|
||||
¬e_id,
|
||||
¬e_title,
|
||||
¬e_top_level_title,
|
||||
¬e_is_done,
|
||||
¬e_is_todo,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
c.JSON(500, gin.H{
|
||||
@ -104,6 +113,9 @@ func main() {
|
||||
item := make(map[string]string)
|
||||
item["id"] = note_id
|
||||
item["title"] = note_title
|
||||
item["top_level_title"] = note_top_level_title
|
||||
item["is_done"] = note_is_done
|
||||
item["is_todo"] = note_is_todo
|
||||
results = append(results, item)
|
||||
}
|
||||
|
||||
|
@ -73,13 +73,17 @@ function _codigoparallevar_enable_search_box(selector, options) {
|
||||
|
||||
resultsList.innerHTML = '';
|
||||
for (const note of body.results.notes) {
|
||||
if (note.is_todo === "1") {
|
||||
return;
|
||||
}
|
||||
|
||||
const resultCard = document.createElement('li');
|
||||
|
||||
const resultContents = document.createElement('a');
|
||||
resultContents.setAttribute('href', './' + note.id + '.node.html');
|
||||
|
||||
const resultTitle = document.createElement('h2');
|
||||
resultTitle.innerText = note.title;
|
||||
resultTitle.innerText = `${note.title} (${note.top_level_title})`;
|
||||
|
||||
resultContents.appendChild(resultTitle);
|
||||
resultCard.appendChild(resultContents);
|
||||
|
Loading…
Reference in New Issue
Block a user