Merge branch 'uroybd-main'

This commit is contained in:
Ole Eskild Steensen 2023-01-09 17:54:02 +01:00
commit 1bc283c4de
10 changed files with 131 additions and 48 deletions

View File

@ -11,13 +11,17 @@ const handler = async (event) => {
const index = lunrjs.Index.load(indexJson);
console.log('index made');
let results = index.search(search);
let results =
search[0] == "#" && search.length > 1
? 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);
r.date = data[r.ref].date;
r.url = data[r.ref].url;
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

@ -11,47 +11,58 @@
}
}
const loadingSvg = `<svg width="100" height="100" viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" stroke="#d9d9d9">
<g fill="none" fill-rule="evenodd" transform="translate(1 1)" stroke-width="2">
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate attributeName="r"
begin="1.5s" dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="1.5s" dur="3s"
values="1;0" calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-width"
begin="1.5s" dur="3s"
values="2;0" calcMode="linear"
repeatCount="indefinite" />
</circle>
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate attributeName="r"
begin="3s" dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="3s" dur="3s"
values="1;0" calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-width"
begin="3s" dur="3s"
values="2;0" calcMode="linear"
repeatCount="indefinite" />
</circle>
<circle cx="22" cy="22" r="8">
<animate attributeName="r"
begin="0s" dur="1.5s"
values="6;1;2;3;4;5;6"
calcMode="linear"
repeatCount="indefinite" />
</circle>
</g>
</svg>`;
window.toggleTagSearch=function(evt) {
console.log(evt.textContent);
const term = evt.textContent;
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">
<g fill="none" fill-rule="evenodd" transform="translate(1 1)" stroke-width="2">
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate attributeName="r"
begin="1.5s" dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="1.5s" dur="3s"
values="1;0" calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-width"
begin="1.5s" dur="3s"
values="2;0" calcMode="linear"
repeatCount="indefinite" />
</circle>
<circle cx="22" cy="22" r="6" stroke-opacity="0">
<animate attributeName="r"
begin="3s" dur="3s"
values="6;22"
calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="3s" dur="3s"
values="1;0" calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="stroke-width"
begin="3s" dur="3s"
values="2;0" calcMode="linear"
repeatCount="indefinite" />
</circle>
<circle cx="22" cy="22" r="8">
<animate attributeName="r"
begin="0s" dur="1.5s"
values="6;1;2;3;4;5;6"
calcMode="linear"
repeatCount="indefinite" />
</circle>
</g>
</svg>`;
function debounce(func, wait, immediate) {
var timeout;
@ -192,7 +203,26 @@
resultsHTML += '<div>';
// we need to add title, url from ref
results.forEach(r => {
resultsHTML += `<div class="searchresult"><a class="search-link" href="${r.url}">${r.title}</a><span onclick="window.location='${r.url}'">${r.content}</span></div>`;
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}'">
<div class="header-meta">
<div class="header-tags">
${r.tags.map(tag=>'<a class="tag" href="JavaScript:Void(0);">#'+tag+'</a>').join("")}
</div>
</div>
${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

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

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

@ -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

@ -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 {