Compare commits
No commits in common. "93414ac714a51d8e6d386cbe6c314574ce06b61a" and "4561924030504ce00d2446f3b8706839684ea6b6" have entirely different histories.
93414ac714
...
4561924030
|
|
@ -0,0 +1,36 @@
|
|||
// 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));
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
// pubfiles: pubfiles.sh(allfiles)
|
||||
(list): ..
|
||||
allfiles: Tree.filter(list, (val, key) => key.endsWith('.md') && !key.startsWith('_'))
|
||||
documents: Tree.map(allfiles, {value: (value) => Origami.document(value)}) //if I don't use the verbose syntax I get the filename characters as part of value, because Origami.document takes the key as its 'data' parameter.
|
||||
documents: Tree.map(allfiles, {value: (value) => Origami.document(value)}) //if I don't use the verbose syntax I get the filename characters as part of value!
|
||||
withfilenamedata: Tree.map(documents, { value: (value, key) => ./filenamedata/addFilenameData.js(value, Origami.slash.remove(key))})
|
||||
//files now have a key `fnd` for 'filenamedata`. This contains address, title, and tags parsed from the filename.
|
||||
|
||||
|
|
@ -69,9 +69,7 @@
|
|||
|
||||
linksByFile: Tree.map(Tree.map(renderedPages, (a) => a/html), ./linked-files/getLinkedFilesFromHtml.js)
|
||||
uniqueLinks: Tree.flat(linksByFile) → (a) => [...new Set(a)]
|
||||
//linksAsTree: ./linked-files/pathsToObjs.js(uniqueLinks)
|
||||
linksAsTree: Tree.inflatePaths(Tree.withKeys(() => true, uniqueLinks))
|
||||
|
||||
linksAsTree: ./linked-files/pathsToObjs.js(uniqueLinks)
|
||||
onlyLinkedFiles: Tree.mask(list, linksAsTree)
|
||||
|
||||
index.html: ori-templates/indexPage.ori(final, all)
|
||||
|
|
|
|||
Loading…
Reference in New Issue