-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'uroybd-dynamic-include'
- Loading branch information
Showing
6 changed files
with
88 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fsFileTree = require("fs-file-tree"); | ||
|
||
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 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 () => { | ||
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; | ||
} |
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