From 040ab398b910c6889ddb67b0b7c5c9c4454e8bd5 Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Sun, 8 Jan 2023 20:00:01 +0600 Subject: [PATCH 1/7] tags support --- netlify/functions/search/search.js | 5 +++++ src/site/_includes/components/searchScript.njk | 8 ++++++++ src/site/_includes/layouts/note.njk | 3 +++ src/site/lunr-index.js | 1 + src/site/lunr.njk | 3 ++- src/site/styles/style.scss | 10 ++++++++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/netlify/functions/search/search.js b/netlify/functions/search/search.js index b9501c0..1518535 100644 --- a/netlify/functions/search/search.js +++ b/netlify/functions/search/search.js @@ -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); diff --git a/src/site/_includes/components/searchScript.njk b/src/site/_includes/components/searchScript.njk index 367da67..e266f1b 100644 --- a/src/site/_includes/components/searchScript.njk +++ b/src/site/_includes/components/searchScript.njk @@ -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() { diff --git a/src/site/_includes/layouts/note.njk b/src/site/_includes/layouts/note.njk index b59afe7..436fe42 100644 --- a/src/site/_includes/layouts/note.njk +++ b/src/site/_includes/layouts/note.njk @@ -24,6 +24,9 @@ permalink: "notes/{{ page.fileSlug | slugify }}/" {% if settings.dgShowInlineTitle === true %}

{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}

{% endif %} +
+ {% if tags %}
{% for tag in tags %}#{{tag}}{% endfor %}
{% endif %} +
{{ content | link | highlight | safe}} diff --git a/src/site/lunr-index.js b/src/site/lunr-index.js index 5846ea3..03a84d2 100644 --- a/src/site/lunr-index.js +++ b/src/site/lunr-index.js @@ -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; diff --git a/src/site/lunr.njk b/src/site/lunr.njk index d52c19a..5dd4074 100644 --- a/src/site/lunr.njk +++ b/src/site/lunr.njk @@ -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 %}] diff --git a/src/site/styles/style.scss b/src/site/styles/style.scss index c507eeb..0ff6378 100644 --- a/src/site/styles/style.scss +++ b/src/site/styles/style.scss @@ -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; +} \ No newline at end of file From 0c830fc1db922be322eb613bf2a9bcd2e5a3f629 Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Sun, 8 Jan 2023 20:02:23 +0600 Subject: [PATCH 2/7] tag in search results --- src/site/_includes/components/searchScript.njk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/site/_includes/components/searchScript.njk b/src/site/_includes/components/searchScript.njk index e266f1b..74aaef3 100644 --- a/src/site/_includes/components/searchScript.njk +++ b/src/site/_includes/components/searchScript.njk @@ -156,7 +156,9 @@ resultsHTML += '
'; // we need to add title, url from ref results.forEach(r => { - resultsHTML += `
${r.title}${r.content}
`; + resultsHTML += `
${r.title}
+ {% if tags %}
{% for tag in tags %}#{{tag}}
{% endfor %}{% endif %} +
${r.content}
`; }); resultsHTML += '
'; resultsDiv.innerHTML = resultsHTML; From 43c28d459f401b7d9ce49b2855fee01641c3060f Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Sun, 8 Jan 2023 20:03:01 +0600 Subject: [PATCH 3/7] tag fix in search --- src/site/_includes/components/searchScript.njk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/_includes/components/searchScript.njk b/src/site/_includes/components/searchScript.njk index 74aaef3..fc1ce27 100644 --- a/src/site/_includes/components/searchScript.njk +++ b/src/site/_includes/components/searchScript.njk @@ -157,7 +157,7 @@ // we need to add title, url from ref results.forEach(r => { resultsHTML += `
${r.title}
- {% if tags %}
{% for tag in tags %}#{{tag}}
{% endfor %}{% endif %} + {% if tags %}
{% for tag in tags %}#{{tag}}{% endfor %}{% endif %}
${r.content}
`; }); resultsHTML += '
'; From b6bd818cb94c954051b81b25b3a51ef25246cd5e Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Sun, 8 Jan 2023 20:12:02 +0600 Subject: [PATCH 4/7] search representation fix --- src/site/_includes/components/searchScript.njk | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/site/_includes/components/searchScript.njk b/src/site/_includes/components/searchScript.njk index fc1ce27..2ebe62e 100644 --- a/src/site/_includes/components/searchScript.njk +++ b/src/site/_includes/components/searchScript.njk @@ -156,9 +156,21 @@ resultsHTML += '
'; // we need to add title, url from ref results.forEach(r => { - resultsHTML += `
${r.title}
- {% if tags %}
{% for tag in tags %}#{{tag}}{% endfor %}{% endif %} -
${r.content}
`; + resultsHTML += `
+ ${r.title} +
+
+ {% if tags %} +
+ {% for tag in tags %} + #{{tag}} + {% endfor %} + {% endif %} +
+
+ ${r.content} +
+
`; }); resultsHTML += '
'; resultsDiv.innerHTML = resultsHTML; From 8f32df6bb83bed11ee90292c05e1f6c33649854a Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Mon, 9 Jan 2023 11:47:25 +0600 Subject: [PATCH 5/7] gap in tags --- src/site/styles/style.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/src/site/styles/style.scss b/src/site/styles/style.scss index 0ff6378..7712853 100644 --- a/src/site/styles/style.scss +++ b/src/site/styles/style.scss @@ -97,6 +97,7 @@ p>code { display: flex; flex-wrap: wrap; margin-top: 10px; + gap: 5px; } .header-meta { From 2c3bddded83d37eb6c18ba5dffb0b6504eaf4157 Mon Sep 17 00:00:00 2001 From: Ole Eskild Steensen Date: Mon, 9 Jan 2023 17:11:28 +0100 Subject: [PATCH 6/7] Add tag to search result and remove home note tag --- netlify/functions/search/search.js | 3 +-- src/site/_includes/components/searchScript.njk | 6 +----- src/site/_includes/layouts/note.njk | 12 +++++++++++- src/site/lunr.njk | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/netlify/functions/search/search.js b/netlify/functions/search/search.js index 1518535..cc8ce7b 100644 --- a/netlify/functions/search/search.js +++ b/netlify/functions/search/search.js @@ -11,8 +11,6 @@ const handler = async (event) => { const index = lunrjs.Index.load(indexJson); console.log('index made'); - let results = index.search(search); - let results = search[0] == "#" ? index.search(`tags:${search.substring(1)}`) @@ -23,6 +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; delete r.ref; }); diff --git a/src/site/_includes/components/searchScript.njk b/src/site/_includes/components/searchScript.njk index 4a76442..7d449ae 100644 --- a/src/site/_includes/components/searchScript.njk +++ b/src/site/_includes/components/searchScript.njk @@ -206,12 +206,8 @@ ${r.title}
- {% if tags %}
- {% for tag in tags %} - #{{tag}} - {% endfor %} - {% endif %} + ${r.tags.map(tag=>'#'+tag+'').join("")}
${r.content} diff --git a/src/site/_includes/layouts/note.njk b/src/site/_includes/layouts/note.njk index 436fe42..af48190 100644 --- a/src/site/_includes/layouts/note.njk +++ b/src/site/_includes/layouts/note.njk @@ -25,7 +25,17 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"

{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}

{% endif %}
- {% if tags %}
{% for tag in tags %}#{{tag}}{% endfor %}
{% endif %} + {% if tags %} +
+ {% for tag in tags %} + {% if tag != 'gardenEntry' %} + + #{{tag}} + + {% endif %} + {% endfor %} +
+ {% endif %}
{{ content | link | highlight | safe}}
diff --git a/src/site/lunr.njk b/src/site/lunr.njk index 5dd4074..1b7506e 100644 --- a/src/site/lunr.njk +++ b/src/site/lunr.njk @@ -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 %}"{{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 %} {% endfor %}] From d9e75704bb2bf83c76a2aa7424bb95b2e03678ce Mon Sep 17 00:00:00 2001 From: Ole Eskild Steensen Date: Mon, 9 Jan 2023 17:53:13 +0100 Subject: [PATCH 7/7] Fix errors and remove internally used tags --- netlify/functions/search/search.js | 4 +-- src/helpers/constants.js | 3 +- src/site/_includes/components/filetree.njk | 4 +-- .../_includes/components/searchScript.njk | 35 ++++++++++++------- src/site/_includes/layouts/note.njk | 4 +-- src/site/index.11tydata.js | 7 ++++ src/site/index.njk | 15 ++++++++ src/site/lunr.njk | 2 +- src/site/styles/digital-garden-base.scss | 13 ++++++- src/site/styles/style.scss | 11 ------ 10 files changed, 66 insertions(+), 32 deletions(-) diff --git a/netlify/functions/search/search.js b/netlify/functions/search/search.js index cc8ce7b..fc15843 100644 --- a/netlify/functions/search/search.js +++ b/netlify/functions/search/search.js @@ -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; }); diff --git a/src/helpers/constants.js b/src/helpers/constants.js index dc6df6b..e7cea58 100644 --- a/src/helpers/constants.js +++ b/src/helpers/constants.js @@ -7,5 +7,6 @@ exports.ALL_NOTE_SETTINGS= [ "dgShowFileTree", "dgEnableSearch", "dgShowToc", - "dgLinkPreview" + "dgLinkPreview", + "dgShowTags" ]; \ No newline at end of file diff --git a/src/site/_includes/components/filetree.njk b/src/site/_includes/components/filetree.njk index 51bd03c..c26d571 100644 --- a/src/site/_includes/components/filetree.njk +++ b/src/site/_includes/components/filetree.njk @@ -26,13 +26,13 @@ x-on:resize.window="isDesktop = (window.innerWidth>=1400) ? true : false;" x-data="{isDesktop: true, showFilesMobile: false}"> -
+
{%include "components/filetreeNavbar.njk"%}
-