From db6d4bb79b9492e9a5f400d0722349d59028b9d8 Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Sat, 4 Feb 2023 18:45:57 +0600 Subject: [PATCH] Hide dataview variable (#54) * hide dataview variable * Update note.njk --------- Co-authored-by: Ole Eskild Steensen --- .eleventy.js | 34 +++++++++++++++-------------- src/site/_includes/layouts/note.njk | 32 +++++++++++++-------------- src/site/index.njk | 2 +- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 7770b1e..43687d0 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -195,22 +195,15 @@ module.exports = function (eleventyConfig) { eleventyConfig.addFilter("taggify", function (str) { return ( str && - str.replace( - tagRegex, - function (match, precede, tag) { - return `${precede}${tag}`; - } - ) + str.replace(tagRegex, function (match, precede, tag) { + return `${precede}${tag}`; + }) ); }); eleventyConfig.addFilter("searchableTags", function (str) { let tags; - let match = - str && - str.match( - tagRegex, - ); + let match = str && str.match(tagRegex); if (match) { tags = match .map((m) => { @@ -225,6 +218,15 @@ module.exports = function (eleventyConfig) { } }); + eleventyConfig.addFilter("hideDataview", function (str) { + return ( + str && + str.replace(/\(\S+\:\:(.*)\)/g, function (_, value) { + return value.trim(); + }) + ); + }); + eleventyConfig.addTransform("callout-block", function (str) { const parsed = parse(str); @@ -290,11 +292,11 @@ module.exports = function (eleventyConfig) { return JSON.stringify(variable) || '""'; }); - eleventyConfig.addFilter('validJson', function (variable) { - if(Array.isArray((variable))){ - return variable.map(x=>x.replaceAll("\\", "\\\\")).join(","); - }else if(typeof(variable) === 'string'){ - return variable.replaceAll("\\", "\\\\"); + eleventyConfig.addFilter("validJson", function (variable) { + if (Array.isArray(variable)) { + return variable.map((x) => x.replaceAll("\\", "\\\\")).join(","); + } else if (typeof variable === "string") { + return variable.replaceAll("\\", "\\\\"); } return variable; }); diff --git a/src/site/_includes/layouts/note.njk b/src/site/_includes/layouts/note.njk index 56f4e2e..ecac13d 100644 --- a/src/site/_includes/layouts/note.njk +++ b/src/site/_includes/layouts/note.njk @@ -22,24 +22,24 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
- {% if settings.dgShowInlineTitle === true %} -

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

- {% endif %} -
- {% if settings.dgShowTags === true and tags %} -
- {% for tag in tags %} - {% if tag != 'gardenEntry' and tag !='note' %} - - #{{tag}} - - {% endif %} - {% endfor %} -
+ {% if settings.dgShowInlineTitle === true %} +

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

{% endif %} -
+
+ {% if settings.dgShowTags === true and tags %} +
+ {% for tag in tags %} + {% if tag != 'gardenEntry' and tag !='note' %} + + #{{tag}} + + {% endif %} + {% endfor %} +
+ {% endif %} +
- {{ content | link | taggify | highlight | safe}} + {{ content | hideDataview | link | taggify | highlight | safe}}
{% if settings.dgShowBacklinks === true or settings.dgShowLocalGraph === true or settings.dgShowToc === true%} diff --git a/src/site/index.njk b/src/site/index.njk index 2644114..f753a53 100644 --- a/src/site/index.njk +++ b/src/site/index.njk @@ -35,7 +35,7 @@ {%- for garden in collections.gardenEntry -%} - {{garden.templateContent | link | taggify | highlight | safe }} + {{garden.templateContent | hideDataview | link | taggify | highlight | safe }} {%- endfor -%}