dynamic import implementation

This commit is contained in:
Utsob Roy 2023-02-06 14:29:23 +06:00
parent 818ae56774
commit 705e80e5f2
4 changed files with 72 additions and 0 deletions

View File

@ -11,6 +11,9 @@ const { headerToId, namedHeadingsFilter } = require("./src/helpers/utils");
const tagRegex = /(^|\s|\>)(#[^\s!@#$%^&*()=+\.,\[{\]};:'"?><]+)(?!([^<]*>))/g;
module.exports = function (eleventyConfig) {
eleventyConfig.setLiquidOptions({
dynamicPartials: true,
});
let markdownLib = markdownIt({
breaks: true,
html: true,

View File

@ -0,0 +1,33 @@
const fsFileTree = require("fs-file-tree");
const BASE_PATH = "src/site/_includes/components/user"
const NAMESPACES = ["index", "notes", "common"];
const SLOTS = ["header", "afterContent", "footer"]
const generateComponentPaths = async (namespace) => {
const data = {};
for (let index = 0; index < SLOTS.length; index++) {
const slot = SLOTS[index];
try {
console.log(`${BASE_PATH}/${namespace}/${slot}`);
const tree = await fsFileTree(`${BASE_PATH}/${namespace}/${slot}`);
let comps = Object.keys(tree).filter((p) => p.indexOf(".njk") != -1).map((p) => `components/user/${namespace}/${slot}/${p}`);
comps.sort()
data[slot] = comps;
} catch {
data[slot] = [];
}
}
return data;
}
module.exports = async () => {
const data = {};
for (let index = 0; index < NAMESPACES.length; index++) {
const ns = NAMESPACES[index];
data[ns] = await generateComponentPaths(ns);
}
console.log(data);
return data;
}

View File

@ -38,8 +38,20 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
</div>
{% endif %}
</div>
{% for imp in dynamics.common.header %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.notes.header %}
{% include imp %}
{% endfor %}
</header>
{{ content | hideDataview | link | taggify | highlight | safe}}
{% for imp in dynamics.common.afterContent %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.notes.afterContent %}
{% include imp %}
{% endfor %}
</main>
{% if settings.dgShowBacklinks === true or settings.dgShowLocalGraph === true or settings.dgShowToc === true%}
@ -50,5 +62,11 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
{%include "components/linkPreview.njk"%}
{% endif %}
{% include "components/references.njk" %}
{% for imp in dynamics.common.footer %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.notes.footer %}
{% include imp %}
{% endfor %}
</body>
</html>

View File

@ -33,10 +33,22 @@
</div>
{% endif %}
</div>
{% for imp in dynamics.common.header %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.index.header %}
{% include imp %}
{% endfor %}
</header>
{%- for garden in collections.gardenEntry -%}
{{garden.templateContent | hideDataview | link | taggify | highlight | safe }}
{%- endfor -%}
{% for imp in dynamics.common.afterContent %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.index.afterContent %}
{% include imp %}
{% endfor %}
</main>
{% if settings.dgShowBacklinks === true or settings.dgShowLocalGraph === true or settings.dgShowToc === true%}
@ -46,5 +58,11 @@
{% if settings.dgLinkPreview === true %}
{%include "components/linkPreview.njk"%}
{% endif %}
{% for imp in dynamics.common.footer %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.index.footer %}
{% include imp %}
{% endfor %}
</body>
</html>