tags support

This commit is contained in:
Utsob Roy 2023-01-08 20:00:01 +06:00
parent ea3199f4f1
commit 040ab398b9
6 changed files with 29 additions and 1 deletions

View File

@ -13,6 +13,11 @@ const handler = async (event) => {
let results = index.search(search);
let results =
search[0] == "#"
? index.search(`tags:${search.substring(1)}`)
: index.search(search);
results.forEach(r => {
r.title = data[r.ref].title;
r.content = truncate(data[r.ref].content, 400);

View File

@ -11,6 +11,14 @@
}
}
window.toggleTagSearch=function(evt) {
console.log(evt.textContent);
const term = evt.textContent;
window.document.getElementById('term').value = term;
window.toggleSearch();
window.search();
}
function debounce(func, wait, immediate) {
var timeout;
return function() {

View File

@ -24,6 +24,9 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
{% if settings.dgShowInlineTitle === true %}
<h1>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1>
{% endif %}
<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 %}
</div>
{{ content | link | highlight | safe}}
</div>

View File

@ -8,6 +8,7 @@ function createIndex(posts) {
this.field('title');
this.field('content');
this.field('date');
this.field("tags");
posts.forEach((p, idx) => {
p.id = idx;

View File

@ -8,6 +8,7 @@ eleventyExcludeFromCollections: true
"title": {% if post.data.title %}{{post.data.title | jsonify | safe }}{% else %}{{post.fileSlug | jsonify | safe }}{% endif %},
"date":"{{ post.date }}",
"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 %}]
}{% if not loop.last %},{% endif %}
{% endfor %}]

View File

@ -92,3 +92,13 @@ p>code {
color: #c7254e;
background-color: #1a1a1a;
}
.header-tags {
display: flex;
flex-wrap: wrap;
margin-top: 10px;
}
.header-meta {
margin-bottom: 1.8em;
}