Skip to content

Commit

Permalink
More slots for dynamic components (#70)
Browse files Browse the repository at this point in the history
* more slots for dynamic components

* more slots on sidebar and filetree
  • Loading branch information
uroybd authored Feb 14, 2023
1 parent c3c2729 commit d5ef45f
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 83 deletions.
84 changes: 50 additions & 34 deletions src/site/_data/dynamics.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,60 @@
const fsFileTree = require("fs-file-tree");

const BASE_PATH = "src/site/_includes/components/user"
const STYLE_PATH = "src/site/styles/user"
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 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 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 () => {
const generateComponentPaths = async (namespace, slots) => {
const data = {};
for (let index = 0; index < slots.length; index++) {
const slot = slots[index];
try {
const tree = await fsFileTree(`${STYLE_PATH}`);
let comps = Object.keys(tree).map((p) => `/styles/user/${p}`.replace('.scss', '.css'));
comps.sort()
return comps
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 {
return [];
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;
}
const data = {};
for (let index = 0; index < NAMESPACES.length; index++) {
const ns = NAMESPACES[index];
data[ns] = await generateComponentPaths(ns, SLOTS);
}
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;
};
6 changes: 6 additions & 0 deletions src/site/_includes/components/filetreeNavbar.njk
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<nav class="navbar">
<div class="navbar-inner">
<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;">
<h1 style="margin: 15px !important;">{{meta.siteName}}</h1>
</a>
{% for imp in dynamics.filetree.afterTitle %}
{% include imp %}
{% endfor %}
</div>

{% if settings.dgEnableSearch === true%}
Expand Down
103 changes: 54 additions & 49 deletions src/site/_includes/components/sidebar.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<aside>
<div class="sidebar">
<div class="sidebar-container">

{% for imp in dynamics.sidebar.top %}
{% include imp %}
{% endfor %}
{%if settings.dgShowLocalGraph === true%}
<div class="graph">
<div class="graph-title-container">
Expand All @@ -27,65 +29,68 @@
</div>
<div id="link-graph"></div>
</div>
{%endif%}
{%endif%}

{%if settings.dgShowToc === true%}
{%set tocHtml= (content and (content|toc)) %}
{%if tocHtml %}
<div class="toc">
<div class="toc-title-container">
<div class="toc-title">
On this page
</div>
</div>
<div class="toc-container">
{{ tocHtml | safe }}
{%if settings.dgShowToc === true%}
{%set tocHtml= (content and (content|toc)) %}
{%if tocHtml %}
<div class="toc">
<div class="toc-title-container">
<div class="toc-title">
On this page
</div>
</div>
{%endif%}

<div class="toc-container">
{{ tocHtml | safe }}
</div>
</div>
{%endif%}

{%endif%}

{%if settings.dgShowBacklinks === true %}
{%if settings.dgShowBacklinks === true %}
{%if settings.dgShowBacklinks === true %}
<div class="backlinks">
<div class="backlink-title" style="margin: 4px 0 !important;">Pages mentioning this page</div>
<div class="backlink-list">
{%- if page.url == "/" -%}
{%- if graph.nodes[graph.homeAlias].backLinks.length === 0 -%}
<div class="backlink-card">
<span class="no-backlinks-message">No other pages mentions this page</span>
</div>
{%- endif -%}
{%- for backlink in graph.nodes[graph.homeAlias].backLinks -%}
{%- if graph.nodes[backlink].url != graph.homeAlias -%}
<div class="backlinks">
<div class="backlink-title" style="margin: 4px 0 !important;">Pages mentioning this page</div>
<div class="backlink-list">
{%- if page.url == "/" -%}
{%- if graph.nodes[graph.homeAlias].backLinks.length === 0 -%}
<div class="backlink-card">
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
<span class="no-backlinks-message">No other pages mentions this page</span>
</div>
{%- endif -%}
{%- endfor -%}
{%- else -%}
{%- if graph.nodes[page.url].backLinks.length === 0 -%}
<div class="backlink-card">
<span class="no-backlinks-message">No other pages mentions this page</span>
</div>
{%- endif -%}
{%- for backlink in graph.nodes[page.url].backLinks -%}
{%- if graph.nodes[backlink].url != page.url -%}
{%- endif -%}
{%- for backlink in graph.nodes[graph.homeAlias].backLinks -%}
{%- if graph.nodes[backlink].url != graph.homeAlias -%}
<div class="backlink-card">
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
</div>
{%- endif -%}
{%- endfor -%}
{%- else -%}
{%- if graph.nodes[page.url].backLinks.length === 0 -%}
<div class="backlink-card">
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
<span class="no-backlinks-message">No other pages mentions this page</span>
</div>
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- for backlink in graph.nodes[page.url].backLinks -%}
{%- if graph.nodes[backlink].url != page.url -%}
<div class="backlink-card">
<i class="fa fa-link"></i> <a href="{{graph.nodes[backlink].url}}">{{graph.nodes[backlink].title}}</a>
</div>
</div>
{%endif%}
{%endif%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
</div>
</div>
</div>
</aside>
{%endif%}
{%endif%}
{% for imp in dynamics.sidebar.bottom %}
{% include imp %}
{% endfor %}
</div>
</div>
</aside>

{%if settings.dgShowLocalGraph === true %}
{%include "components/graphScript.njk"%}
{% endif %}
{%if settings.dgShowLocalGraph === true %}
{%include "components/graphScript.njk"%}
{% endif %}
12 changes: 12 additions & 0 deletions src/site/_includes/layouts/note.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
<head>
<title>{% if title %}{{ title }}{% else %}{{ page.fileSlug }}{% endif %}</title>
{%include "components/pageheader.njk"%}
{% for imp in dynamics.common.head %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.notes.head %}
{% include imp %}
{% endfor %}
</head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section">
{%include "components/notegrowthhistory.njk"%}
Expand Down Expand Up @@ -45,6 +51,12 @@ permalink: "notes/{{ page.fileSlug | slugify }}/"
{% include imp %}
{% endfor %}
</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}}
{% for imp in dynamics.common.afterContent %}
{% include imp %}
Expand Down
12 changes: 12 additions & 0 deletions src/site/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<head>
<title>{{ noteTitle }}</title>
{%include "components/pageheader.njk"%}
{% for imp in dynamics.common.head %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.index.head %}
{% include imp %}
{% endfor %}
</head>
<body class="theme-{{meta.baseTheme}} markdown-preview-view markdown-rendered markdown-preview-section">
{%include "components/notegrowthhistory.njk"%}
Expand Down Expand Up @@ -40,6 +46,12 @@
{% include imp %}
{% endfor %}
</header>
{% for imp in dynamics.common.beforeContent %}
{% include imp %}
{% endfor %}
{% for imp in dynamics.index.beforeContent %}
{% include imp %}
{% endfor %}
{%- for garden in collections.gardenEntry -%}
{{garden.templateContent | hideDataview | link | taggify | highlight | safe }}
{%- endfor -%}
Expand Down

0 comments on commit d5ef45f

Please sign in to comment.