Skip to content

Commit d5ef45f

Browse files
authored
More slots for dynamic components (#70)
* more slots for dynamic components * more slots on sidebar and filetree
1 parent c3c2729 commit d5ef45f

File tree

5 files changed

+134
-83
lines changed

5 files changed

+134
-83
lines changed

src/site/_data/dynamics.js

+50-34
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,60 @@
11
const fsFileTree = require("fs-file-tree");
22

3-
const BASE_PATH = "src/site/_includes/components/user"
4-
const STYLE_PATH = "src/site/styles/user"
3+
const BASE_PATH = "src/site/_includes/components/user";
4+
const STYLE_PATH = "src/site/styles/user";
55
const NAMESPACES = ["index", "notes", "common"];
6-
const SLOTS = ["header", "afterContent", "footer"]
6+
const SLOTS = ["head", "header", "beforeContent", "afterContent", "footer"];
7+
const FILE_TREE_NAMESPACE = "filetree";
8+
const FILE_TREE_SLOTS = ["beforeTitle", "afterTitle"];
9+
const SIDEBAR_NAMESPACE = "sidebar";
10+
const SIDEBAR_SLOTS = ["top", "bottom"];
11+
const STYLES_NAMESPACE = "styles";
712

8-
const generateComponentPaths = async (namespace) => {
9-
const data = {};
10-
for (let index = 0; index < SLOTS.length; index++) {
11-
const slot = SLOTS[index];
12-
try {
13-
const tree = await fsFileTree(`${BASE_PATH}/${namespace}/${slot}`);
14-
let comps = Object.keys(tree).filter((p) => p.indexOf(".njk") != -1).map((p) => `components/user/${namespace}/${slot}/${p}`);
15-
comps.sort()
16-
data[slot] = comps;
17-
} catch {
18-
data[slot] = [];
19-
}
20-
}
21-
return data;
22-
}
23-
24-
const generateStylesPaths = async () => {
13+
const generateComponentPaths = async (namespace, slots) => {
14+
const data = {};
15+
for (let index = 0; index < slots.length; index++) {
16+
const slot = slots[index];
2517
try {
26-
const tree = await fsFileTree(`${STYLE_PATH}`);
27-
let comps = Object.keys(tree).map((p) => `/styles/user/${p}`.replace('.scss', '.css'));
28-
comps.sort()
29-
return comps
18+
const tree = await fsFileTree(`${BASE_PATH}/${namespace}/${slot}`);
19+
let comps = Object.keys(tree)
20+
.filter((p) => p.indexOf(".njk") != -1)
21+
.map((p) => `components/user/${namespace}/${slot}/${p}`);
22+
comps.sort();
23+
data[slot] = comps;
3024
} catch {
31-
return [];
25+
data[slot] = [];
3226
}
33-
}
27+
}
28+
return data;
29+
};
3430

31+
const generateStylesPaths = async () => {
32+
try {
33+
const tree = await fsFileTree(`${STYLE_PATH}`);
34+
let comps = Object.keys(tree).map((p) =>
35+
`/styles/user/${p}`.replace(".scss", ".css")
36+
);
37+
comps.sort();
38+
return comps;
39+
} catch {
40+
return [];
41+
}
42+
};
3543

3644
module.exports = async () => {
37-
const data = {};
38-
for (let index = 0; index < NAMESPACES.length; index++) {
39-
const ns = NAMESPACES[index];
40-
data[ns] = await generateComponentPaths(ns);
41-
}
42-
data['styles'] = await generateStylesPaths()
43-
return data;
44-
}
45+
const data = {};
46+
for (let index = 0; index < NAMESPACES.length; index++) {
47+
const ns = NAMESPACES[index];
48+
data[ns] = await generateComponentPaths(ns, SLOTS);
49+
}
50+
data[FILE_TREE_NAMESPACE] = await generateComponentPaths(
51+
FILE_TREE_NAMESPACE,
52+
FILE_TREE_SLOTS
53+
);
54+
data[SIDEBAR_NAMESPACE] = await generateComponentPaths(
55+
SIDEBAR_NAMESPACE,
56+
SIDEBAR_SLOTS
57+
);
58+
data[STYLES_NAMESPACE] = await generateStylesPaths();
59+
return data;
60+
};

src/site/_includes/components/filetreeNavbar.njk

+6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<nav class="navbar">
22
<div class="navbar-inner">
33
<i style="font-size: 1.5rem; margin-right: 10px;" @click="showFilesMobile=!showFilesMobile" class="fa fa-bars"></i>
4+
{% for imp in dynamics.filetree.beforeTitle %}
5+
{% include imp %}
6+
{% endfor %}
47
<a href="/" style="text-decoration: none;">
58
<h1 style="margin: 15px !important;">{{meta.siteName}}</h1>
69
</a>
10+
{% for imp in dynamics.filetree.afterTitle %}
11+
{% include imp %}
12+
{% endfor %}
713
</div>
814

915
{% if settings.dgEnableSearch === true%}
+54-49
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<aside>
22
<div class="sidebar">
33
<div class="sidebar-container">
4-
4+
{% for imp in dynamics.sidebar.top %}
5+
{% include imp %}
6+
{% endfor %}
57
{%if settings.dgShowLocalGraph === true%}
68
<div class="graph">
79
<div class="graph-title-container">
@@ -27,65 +29,68 @@
2729
</div>
2830
<div id="link-graph"></div>
2931
</div>
30-
{%endif%}
32+
{%endif%}
3133

32-
{%if settings.dgShowToc === true%}
33-
{%set tocHtml= (content and (content|toc)) %}
34-
{%if tocHtml %}
35-
<div class="toc">
36-
<div class="toc-title-container">
37-
<div class="toc-title">
38-
On this page
39-
</div>
40-
</div>
41-
<div class="toc-container">
42-
{{ tocHtml | safe }}
34+
{%if settings.dgShowToc === true%}
35+
{%set tocHtml= (content and (content|toc)) %}
36+
{%if tocHtml %}
37+
<div class="toc">
38+
<div class="toc-title-container">
39+
<div class="toc-title">
40+
On this page
4341
</div>
4442
</div>
45-
{%endif%}
46-
43+
<div class="toc-container">
44+
{{ tocHtml | safe }}
45+
</div>
46+
</div>
4747
{%endif%}
4848

49+
{%endif%}
50+
51+
{%if settings.dgShowBacklinks === true %}
4952
{%if settings.dgShowBacklinks === true %}
50-
{%if settings.dgShowBacklinks === true %}
51-
<div class="backlinks">
52-
<div class="backlink-title" style="margin: 4px 0 !important;">Pages mentioning this page</div>
53-
<div class="backlink-list">
54-
{%- if page.url == "/" -%}
55-
{%- if graph.nodes[graph.homeAlias].backLinks.length === 0 -%}
56-
<div class="backlink-card">
57-
<span class="no-backlinks-message">No other pages mentions this page</span>
58-
</div>
59-
{%- endif -%}
60-
{%- for backlink in graph.nodes[graph.homeAlias].backLinks -%}
61-
{%- if graph.nodes[backlink].url != graph.homeAlias -%}
53+
<div class="backlinks">
54+
<div class="backlink-title" style="margin: 4px 0 !important;">Pages mentioning this page</div>
55+
<div class="backlink-list">
56+
{%- if page.url == "/" -%}
57+
{%- if graph.nodes[graph.homeAlias].backLinks.length === 0 -%}
6258
<div class="backlink-card">
63-
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
59+
<span class="no-backlinks-message">No other pages mentions this page</span>
6460
</div>
65-
{%- endif -%}
66-
{%- endfor -%}
67-
{%- else -%}
68-
{%- if graph.nodes[page.url].backLinks.length === 0 -%}
69-
<div class="backlink-card">
70-
<span class="no-backlinks-message">No other pages mentions this page</span>
71-
</div>
72-
{%- endif -%}
73-
{%- for backlink in graph.nodes[page.url].backLinks -%}
74-
{%- if graph.nodes[backlink].url != page.url -%}
61+
{%- endif -%}
62+
{%- for backlink in graph.nodes[graph.homeAlias].backLinks -%}
63+
{%- if graph.nodes[backlink].url != graph.homeAlias -%}
64+
<div class="backlink-card">
65+
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
66+
</div>
67+
{%- endif -%}
68+
{%- endfor -%}
69+
{%- else -%}
70+
{%- if graph.nodes[page.url].backLinks.length === 0 -%}
7571
<div class="backlink-card">
76-
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
72+
<span class="no-backlinks-message">No other pages mentions this page</span>
7773
</div>
78-
{%- endif -%}
79-
{%- endfor -%}
8074
{%- endif -%}
75+
{%- for backlink in graph.nodes[page.url].backLinks -%}
76+
{%- if graph.nodes[backlink].url != page.url -%}
77+
<div class="backlink-card">
78+
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
8179
</div>
82-
</div>
83-
{%endif%}
84-
{%endif%}
80+
{%- endif -%}
81+
{%- endfor -%}
82+
{%- endif -%}
83+
</div>
8584
</div>
86-
</div>
87-
</aside>
85+
{%endif%}
86+
{%endif%}
87+
{% for imp in dynamics.sidebar.bottom %}
88+
{% include imp %}
89+
{% endfor %}
90+
</div>
91+
</div>
92+
</aside>
8893

89-
{%if settings.dgShowLocalGraph === true %}
90-
{%include "components/graphScript.njk"%}
91-
{% endif %}
94+
{%if settings.dgShowLocalGraph === true %}
95+
{%include "components/graphScript.njk"%}
96+
{% endif %}

src/site/_includes/layouts/note.njk

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
66
<head>
77
<title>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</title>
88
{%include "components/pageheader.njk"%}
9+
{% for imp in dynamics.common.head %}
10+
{% include imp %}
11+
{% endfor %}
12+
{% for imp in dynamics.notes.head %}
13+
{% include imp %}
14+
{% endfor %}
915
</head>
1016
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section">
1117
{%include "components/notegrowthhistory.njk"%}
@@ -45,6 +51,12 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
4551
{% include imp %}
4652
{% endfor %}
4753
</header>
54+
{% for imp in dynamics.common.beforeContent %}
55+
{% include imp %}
56+
{% endfor %}
57+
{% for imp in dynamics.notes.beforeContent %}
58+
{% include imp %}
59+
{% endfor %}
4860
{{ content | hideDataview | link | taggify | highlight | safe}}
4961
{% for imp in dynamics.common.afterContent %}
5062
{% include imp %}

src/site/index.njk

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
<head>
44
<title>{{ noteTitle }}</title>
55
{%include "components/pageheader.njk"%}
6+
{% for imp in dynamics.common.head %}
7+
{% include imp %}
8+
{% endfor %}
9+
{% for imp in dynamics.index.head %}
10+
{% include imp %}
11+
{% endfor %}
612
</head>
713
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section">
814
{%include "components/notegrowthhistory.njk"%}
@@ -40,6 +46,12 @@
4046
{% include imp %}
4147
{% endfor %}
4248
</header>
49+
{% for imp in dynamics.common.beforeContent %}
50+
{% include imp %}
51+
{% endfor %}
52+
{% for imp in dynamics.index.beforeContent %}
53+
{% include imp %}
54+
{% endfor %}
4355
{%- for garden in collections.gardenEntry -%}
4456
{{garden.templateContent | hideDataview | link | taggify | highlight | safe }}
4557
{%- endfor -%}

0 commit comments

Comments
 (0)