From d5ef45f3cf570580877c512b0d9fa0d2a648cd84 Mon Sep 17 00:00:00 2001 From: Utsob Roy Date: Tue, 14 Feb 2023 22:14:43 +0600 Subject: [PATCH] More slots for dynamic components (#70) * more slots for dynamic components * more slots on sidebar and filetree --- src/site/_data/dynamics.js | 84 ++++++++------ .../_includes/components/filetreeNavbar.njk | 6 + src/site/_includes/components/sidebar.njk | 103 +++++++++--------- src/site/_includes/layouts/note.njk | 12 ++ src/site/index.njk | 12 ++ 5 files changed, 134 insertions(+), 83 deletions(-) diff --git a/src/site/_data/dynamics.js b/src/site/_data/dynamics.js index d356a2c83..13128c966 100644 --- a/src/site/_data/dynamics.js +++ b/src/site/_data/dynamics.js @@ -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; -} \ No newline at end of file + 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; +}; diff --git a/src/site/_includes/components/filetreeNavbar.njk b/src/site/_includes/components/filetreeNavbar.njk index d3e714431..612c03edb 100644 --- a/src/site/_includes/components/filetreeNavbar.njk +++ b/src/site/_includes/components/filetreeNavbar.njk @@ -1,9 +1,15 @@