Skip to content

Commit

Permalink
Merge branch 'uroybd-dynamic-include'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Feb 7, 2023
2 parents 818ae56 + baa3191 commit 905ddc1
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion plugin-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"src/site/_data/versionednotes.js",
"src/site/_data/meta.js",
"src/site/_data/filetree.js",
"src/site/_data/dynamics.js",
"src/site/img/outgoing.svg",
"src/helpers/constants.js",
"src/helpers/utils.js",
Expand All @@ -56,4 +57,4 @@
"src/site/_data/eleventyComputed.js",
"src/site/graph.njk"
]
}
}
44 changes: 44 additions & 0 deletions src/site/_data/dynamics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fsFileTree = require("fs-file-tree");

const BASE_PATH = "src/site/_includes/components/user"
const STYLE_PATH = "src/site/styles/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 {
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;
}

const generateStylesPaths = async () => {
try {
const tree = await fsFileTree(`${STYLE_PATH}`);
let comps = Object.keys(tree).map((p) => `/styles/user/${p}`.replace('.scss', '.css'));
comps.sort()
return comps
} catch {
return [];
}
}


module.exports = async () => {
const data = {};
for (let index = 0; index < NAMESPACES.length; index++) {
const ns = NAMESPACES[index];
data[ns] = await generateComponentPaths(ns);
}
data['styles'] = await generateStylesPaths()
return data;
}
3 changes: 3 additions & 0 deletions src/site/_includes/components/pageheader.njk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
{%endif%}

<link href="/styles/custom-style.css" rel="stylesheet">
{%- for style in dynamics.styles -%}
<link href="{{style}}" rel="stylesheet">
{%- endfor -%}

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand Down
18 changes: 18 additions & 0 deletions src/site/_includes/layouts/note.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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%}
Expand All @@ -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>
18 changes: 18 additions & 0 deletions src/site/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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%}
Expand All @@ -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>

0 comments on commit 905ddc1

Please sign in to comment.