More slots for dynamic components (#70)

* more slots for dynamic components

* more slots on sidebar and filetree
This commit is contained in:
Utsob Roy 2023-02-14 22:14:43 +06:00
parent fc5f39cbf4
commit 008bf71166
5 changed files with 143 additions and 92 deletions

View File

@ -1,44 +1,60 @@
const fsFileTree = require("fs-file-tree"); const fsFileTree = require("fs-file-tree");
const BASE_PATH = "src/site/_includes/components/user" const BASE_PATH = "src/site/_includes/components/user";
const STYLE_PATH = "src/site/styles/user" const STYLE_PATH = "src/site/styles/user";
const NAMESPACES = ["index", "notes", "common"]; const NAMESPACES = ["index", "notes", "common"];
const SLOTS = ["header", "afterContent", "footer"] const SLOTS = ["head", "header", "beforeContent", "afterContent", "footer"];
const FILE_TREE_NAMESPACE = "filetree";
const FILE_TREE_SLOTS = ["beforeTitle", "afterTitle"];
const SIDEBAR_NAMESPACE = "sidebar";
const SIDEBAR_SLOTS = ["top", "bottom"];
const STYLES_NAMESPACE = "styles";
const generateComponentPaths = async (namespace) => { const generateComponentPaths = async (namespace, slots) => {
const data = {}; const data = {};
for (let index = 0; index < SLOTS.length; index++) { for (let index = 0; index < slots.length; index++) {
const slot = SLOTS[index]; const slot = slots[index];
try { try {
const tree = await fsFileTree(`${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}`); let comps = Object.keys(tree)
comps.sort() .filter((p) => p.indexOf(".njk") != -1)
.map((p) => `components/user/${namespace}/${slot}/${p}`);
comps.sort();
data[slot] = comps; data[slot] = comps;
} catch { } catch {
data[slot] = []; data[slot] = [];
} }
} }
return data; return data;
} };
const generateStylesPaths = async () => { const generateStylesPaths = async () => {
try { try {
const tree = await fsFileTree(`${STYLE_PATH}`); const tree = await fsFileTree(`${STYLE_PATH}`);
let comps = Object.keys(tree).map((p) => `/styles/user/${p}`.replace('.scss', '.css')); let comps = Object.keys(tree).map((p) =>
comps.sort() `/styles/user/${p}`.replace(".scss", ".css")
return comps );
comps.sort();
return comps;
} catch { } catch {
return []; return [];
} }
} };
module.exports = async () => { module.exports = async () => {
const data = {}; const data = {};
for (let index = 0; index < NAMESPACES.length; index++) { for (let index = 0; index < NAMESPACES.length; index++) {
const ns = NAMESPACES[index]; const ns = NAMESPACES[index];
data[ns] = await generateComponentPaths(ns); data[ns] = await generateComponentPaths(ns, SLOTS);
} }
data['styles'] = await generateStylesPaths() data[FILE_TREE_NAMESPACE] = await generateComponentPaths(
FILE_TREE_NAMESPACE,
FILE_TREE_SLOTS
);
data[SIDEBAR_NAMESPACE] = await generateComponentPaths(
SIDEBAR_NAMESPACE,
SIDEBAR_SLOTS
);
data[STYLES_NAMESPACE] = await generateStylesPaths();
return data; return data;
} };

View File

@ -1,9 +1,15 @@
<nav class="navbar"> <nav class="navbar">
<div class="navbar-inner"> <div class="navbar-inner">
<i style="font-size: 1.5rem; margin-right: 10px;" @click="showFilesMobile=!showFilesMobile" class="fa fa-bars"></i> <i style="font-size: 1.5rem; margin-right: 10px;" @click="showFilesMobile=!showFilesMobile" class="fa fa-bars"></i>
{% for imp in dynamics.filetree.beforeTitle %}
{% include imp %}
{% endfor %}
<a href="/" style="text-decoration: none;"> <a href="/" style="text-decoration: none;">
<h1 style="margin: 15px !important;">{{meta.siteName}}</h1> <h1 style="margin: 15px !important;">{{meta.siteName}}</h1>
</a> </a>
{% for imp in dynamics.filetree.afterTitle %}
{% include imp %}
{% endfor %}
</div> </div>
{% if settings.dgEnableSearch === true%} {% if settings.dgEnableSearch === true%}

View File

@ -1,7 +1,9 @@
<aside> <aside>
<div class="sidebar"> <div class="sidebar">
<div class="sidebar-container"> <div class="sidebar-container">
{% for imp in dynamics.sidebar.top %}
{% include imp %}
{% endfor %}
{%if settings.dgShowLocalGraph === true%} {%if settings.dgShowLocalGraph === true%}
<div class="graph"> <div class="graph">
<div class="graph-title-container"> <div class="graph-title-container">
@ -82,10 +84,13 @@
</div> </div>
{%endif%} {%endif%}
{%endif%} {%endif%}
{% for imp in dynamics.sidebar.bottom %}
{% include imp %}
{% endfor %}
</div> </div>
</div> </div>
</aside> </aside>
{%if settings.dgShowLocalGraph === true %} {%if settings.dgShowLocalGraph === true %}
{%include "components/graphScript.njk"%} {%include "components/graphScript.njk"%}
{% endif %} {% endif %}

View File

@ -6,6 +6,12 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
<head> <head>
<title>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</title> <title>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</title>
{%include "components/pageheader.njk"%} {%include "components/pageheader.njk"%}
{% for imp in dynamics.common.head %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.notes.head %}
{% include imp %}
{% endfor %}
</head> </head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section {{meta.bodyClasses}}"> <body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section {{meta.bodyClasses}}">
{%include "components/notegrowthhistory.njk"%} {%include "components/notegrowthhistory.njk"%}
@ -45,6 +51,12 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
{% include imp %} {% include imp %}
{% endfor %} {% endfor %}
</header> </header>
{% for imp in dynamics.common.beforeContent %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.notes.beforeContent %}
{% include imp %}
{% endfor %}
{{ content | hideDataview | link | taggify | highlight | safe}} {{ content | hideDataview | link | taggify | highlight | safe}}
{% for imp in dynamics.common.afterContent %} {% for imp in dynamics.common.afterContent %}
{% include imp %} {% include imp %}

View File

@ -3,6 +3,12 @@
<head> <head>
<title>{{ noteTitle }}</title> <title>{{ noteTitle }}</title>
{%include "components/pageheader.njk"%} {%include "components/pageheader.njk"%}
{% for imp in dynamics.common.head %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.index.head %}
{% include imp %}
{% endfor %}
</head> </head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section {{meta.bodyClasses}}"> <body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section {{meta.bodyClasses}}">
{%include "components/notegrowthhistory.njk"%} {%include "components/notegrowthhistory.njk"%}
@ -40,6 +46,12 @@
{% include imp %} {% include imp %}
{% endfor %} {% endfor %}
</header> </header>
{% for imp in dynamics.common.beforeContent %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.index.beforeContent %}
{% include imp %}
{% endfor %}
{%- for garden in collections.gardenEntry -%} {%- for garden in collections.gardenEntry -%}
{{garden.templateContent | hideDataview | link | taggify | highlight | safe }} {{garden.templateContent | hideDataview | link | taggify | highlight | safe }}
{%- endfor -%} {%- endfor -%}