Fix errors and remove internally used tags

This commit is contained in:
Ole Eskild Steensen 2023-01-09 17:53:13 +01:00
parent 4487444510
commit d9e75704bb
10 changed files with 66 additions and 32 deletions

View File

@ -12,7 +12,7 @@ const handler = async (event) => {
console.log('index made');
let results =
search[0] == "#"
search[0] == "#" && search.length > 1
? index.search(`tags:${search.substring(1)}`)
: index.search(search);
@ -21,7 +21,7 @@ const handler = async (event) => {
r.content = truncate(data[r.ref].content, 400);
r.date = data[r.ref].date;
r.url = data[r.ref].url;
r.tags = data[r.ref].tags;
r.tags = data[r.ref].tags.filter(x=>x!="gardenEntry" && x!="note");//Note is automatically added by 11ty. GardenEntry is used internally to mark the home page
delete r.ref;
});

View File

@ -7,5 +7,6 @@ exports.ALL_NOTE_SETTINGS= [
"dgShowFileTree",
"dgEnableSearch",
"dgShowToc",
"dgLinkPreview"
"dgLinkPreview",
"dgShowTags"
];

View File

@ -26,13 +26,13 @@
x-on:resize.window="isDesktop = (window.innerWidth>=1400) ? true : false;"
x-data="{isDesktop: true, showFilesMobile: false}">
<div x-show.important="!isDesktop">
<div x-show.important="!isDesktop" style="display: none;">
{%include "components/filetreeNavbar.njk"%}
</div>
<div x-show="showFilesMobile && !isDesktop" @click="showFilesMobile = false" style="display:none;" class="fullpage-overlay"></div>
<nav class="filetree-sidebar" x-show.important="isDesktop || showFilesMobile" style="display: block">
<nav class="filetree-sidebar" x-show.important="isDesktop || showFilesMobile" style="display: none;">
<a href="/" style="text-decoration: none;">
<h1 style="text-align:center;">{{meta.siteName}}</h1>

View File

@ -14,10 +14,12 @@
window.toggleTagSearch=function(evt) {
console.log(evt.textContent);
const term = evt.textContent;
window.document.getElementById('term').value = term;
if(term){
window.document.getElementById('term').value = term.trim();
window.toggleSearch();
window.search();
}
}
const loadingSvg = `
<svg width="100" height="100" viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" stroke="#fff">
@ -201,6 +203,7 @@
resultsHTML += '<div>';
// we need to add title, url from ref
results.forEach(r => {
if(r.tags && r.tags.length > 0){
resultsHTML += `<div class="searchresult">
<a class="search-link" href="${r.url}">${r.title}</a>
<div onclick="window.location='${r.url}'">
@ -212,6 +215,14 @@
${r.content}
</div>
</div>`;
} else {
resultsHTML += `<div class="searchresult">
<a class="search-link" href="${r.url}">${r.title}</a>
<div onclick="window.location='${r.url}'">
${r.content}
</div>
</div>`;
}
});
resultsHTML += '</div>';
resultsDiv.innerHTML = resultsHTML;

View File

@ -25,10 +25,10 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
<h1>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</h1>
{% endif %}
<div class="header-meta">
{% if tags %}
{% if settings.dgShowTags === true and tags %}
<div class="header-tags">
{% for tag in tags %}
{% if tag != 'gardenEntry' %}
{% if tag != 'gardenEntry' and tag !='note' %}
<a class="tag" onclick="toggleTagSearch(this)">
#{{tag}}
</a>

View File

@ -37,6 +37,13 @@ module.exports = {
}
return "";
},
tags: (data) => {
const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0];
if (currentnote && currentnote.data) {
return currentnote.data.tags;
}
return [];
},
content: (data) => {
const currentnote = data.collections.gardenEntry && data.collections.gardenEntry[0];
if (currentnote && currentnote.template && currentnote.template.frontMatter && currentnote.template.frontMatter.content) {

View File

@ -19,6 +19,21 @@
{% if settings.dgShowInlineTitle === true %}
<h1>{{ noteTitle }}</h1>
{% endif %}
<div class="header-meta">
{% if settings.dgShowTags === true and tags %}
<div class="header-tags">
{% for tag in tags %}
{% if tag != 'gardenEntry' and tag !='note' %}
<a class="tag" onclick="toggleTagSearch(this)">
#{{tag}}
</a>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
{%- for garden in collections.gardenEntry -%}
{{garden.templateContent | link | highlight | safe }}
{%- endfor -%}

View File

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

@ -230,7 +230,7 @@ ul.task-list {
transform: none;
border-radius: 4px;
margin-top: 50px;
max-width: 800px;
max-width: 700px;
margin: auto;
border-radius: 0;
border-top: 2px solid var(--background-secondary);
@ -522,6 +522,17 @@ div[class*="callout-"] {
white-space: normal !important;
}
.header-tags {
display: flex;
flex-wrap: wrap;
margin-top: 10px;
gap: 5px;
}
.header-meta {
margin-bottom: 10px;
}
div.language-ad-note,
div.callout-note {
.admonition-title::before {

View File

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