Add tag to search result and remove home note tag

This commit is contained in:
Ole Eskild Steensen 2023-01-09 17:11:28 +01:00 committed by GitHub
parent 8f32df6bb8
commit 2c3bddded8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 9 deletions

View File

@ -11,8 +11,6 @@ const handler = async (event) => {
const index = lunrjs.Index.load(indexJson); const index = lunrjs.Index.load(indexJson);
console.log('index made'); console.log('index made');
let results = index.search(search);
let results = let results =
search[0] == "#" search[0] == "#"
? index.search(`tags:${search.substring(1)}`) ? index.search(`tags:${search.substring(1)}`)
@ -23,6 +21,7 @@ const handler = async (event) => {
r.content = truncate(data[r.ref].content, 400); r.content = truncate(data[r.ref].content, 400);
r.date = data[r.ref].date; r.date = data[r.ref].date;
r.url = data[r.ref].url; r.url = data[r.ref].url;
r.tags = data[r.ref].tags;
delete r.ref; delete r.ref;
}); });

View File

@ -206,12 +206,8 @@
<a class="search-link" href="${r.url}">${r.title}</a> <a class="search-link" href="${r.url}">${r.title}</a>
<div onclick="window.location='${r.url}'"> <div onclick="window.location='${r.url}'">
<div class="header-meta"> <div class="header-meta">
{% if tags %}
<div class="header-tags"> <div class="header-tags">
{% for tag in tags %} ${r.tags.map(tag=>'<a class="tag" href="JavaScript:Void(0);">#'+tag+'</a>').join("")}
<a class="tag" href="JavaScript:Void(0);">#{{tag}}</a>
{% endfor %}</a>
{% endif %}
</div> </div>
</div> </div>
${r.content} ${r.content}

View File

@ -25,7 +25,17 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
<h1>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1> <h1>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1>
{% endif %} {% endif %}
<div class="header-meta"> <div class="header-meta">
{% if tags %}<div class="header-tags">{% for tag in tags %}<a class="tag" onclick="toggleTagSearch(this)">#{{tag}}</a>{% endfor %}</div>{% endif %} {% if tags %}
<div class="header-tags">
{% for tag in tags %}
{% if tag != 'gardenEntry' %}
<a class="tag" onclick="toggleTagSearch(this)">
#{{tag}}
</a>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div> </div>
{{ content | link | highlight | safe}} {{ content | link | highlight | safe}}
</div> </div>

View File

@ -9,6 +9,6 @@ eleventyExcludeFromCollections: true
"date":"{{ post.date }}", "date":"{{ post.date }}",
"url":"{{ post.url }}", "url":"{{ post.url }}",
"content": {{ post.templateContent | striptags(true) | link | jsonify | safe }}, "content": {{ post.templateContent | striptags(true) | link | jsonify | safe }},
"tags": [{% if post.data.tags %}{% for tag in post.data.tags %}"{{tag}}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %}] "tags": [{% if post.data.tags %}{% for tag in post.data.tags %}{% if tag != 'gardenEntry' %}"{{tag}}"{% endif %}{% if not loop.last %},{% endif %}{% endfor %}{% endif %}]
}{% if not loop.last %},{% endif %} }{% if not loop.last %},{% endif %}
{% endfor %}] {% endfor %}]