linked-files: delete pathsToObjs.js; use new Tree.inflatePaths instead.
This commit is contained in:
parent
94f04f18a1
commit
93414ac714
|
|
@ -1,36 +0,0 @@
|
||||||
// Original source - https://stackoverflow.com/a/44681235
|
|
||||||
// Posted by le_m
|
|
||||||
// Retrieved 2026-03-11, License - CC BY-SA 3.0
|
|
||||||
// Insert path into directory tree structure:
|
|
||||||
//
|
|
||||||
//modified to construct an object instead of an array.
|
|
||||||
|
|
||||||
function insert(tree = {}, [head, ...tail]) {
|
|
||||||
|
|
||||||
if (tail.length > 0) {
|
|
||||||
tree[head] = insert(tree[head], tail)
|
|
||||||
} else {
|
|
||||||
tree[head] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return tree;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example:
|
|
||||||
let examplepaths = [
|
|
||||||
'css/style.css',
|
|
||||||
'about/bird.svg',
|
|
||||||
];
|
|
||||||
|
|
||||||
//naive! assumes relative path like in example.
|
|
||||||
//A more robust implementation would need to resolve paths first, but to what.
|
|
||||||
export default function process(paths) {
|
|
||||||
return paths
|
|
||||||
.map(path => path.split('/')
|
|
||||||
.slice(1) //if path starts with / or ./
|
|
||||||
)
|
|
||||||
.reduce((tree, path) => insert(tree, path), {});
|
|
||||||
}
|
|
||||||
|
|
||||||
//test:
|
|
||||||
// console.log(process(examplepaths));
|
|
||||||
|
|
@ -69,7 +69,9 @@
|
||||||
|
|
||||||
linksByFile: Tree.map(Tree.map(renderedPages, (a) => a/html), ./linked-files/getLinkedFilesFromHtml.js)
|
linksByFile: Tree.map(Tree.map(renderedPages, (a) => a/html), ./linked-files/getLinkedFilesFromHtml.js)
|
||||||
uniqueLinks: Tree.flat(linksByFile) → (a) => [...new Set(a)]
|
uniqueLinks: Tree.flat(linksByFile) → (a) => [...new Set(a)]
|
||||||
linksAsTree: ./linked-files/pathsToObjs.js(uniqueLinks)
|
//linksAsTree: ./linked-files/pathsToObjs.js(uniqueLinks)
|
||||||
|
linksAsTree: Tree.inflatePaths(Tree.withKeys(() => true, uniqueLinks))
|
||||||
|
|
||||||
onlyLinkedFiles: Tree.mask(list, linksAsTree)
|
onlyLinkedFiles: Tree.mask(list, linksAsTree)
|
||||||
|
|
||||||
index.html: ori-templates/indexPage.ori(final, all)
|
index.html: ori-templates/indexPage.ori(final, all)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue