-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More slots for dynamic components (#70)
* more slots for dynamic components * more slots on sidebar and filetree
- Loading branch information
Showing
5 changed files
with
134 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters