74 lines
2.5 KiB
Plaintext
74 lines
2.5 KiB
Plaintext
(all) => {
|
|
//put the file selection part in a closure, so that the list of all files is kept private.
|
|
pages: {
|
|
/*
|
|
list is all the files in current directory.
|
|
allfiles is all source files: ending with `.md` and not starting with `_`.
|
|
pubfiles is the subset containing the string `_pub`.
|
|
files selects either of these depending on the argument passed to this file.
|
|
|
|
NOTES:
|
|
|
|
- if markdown files are empty, Origami.document() will error.
|
|
*/
|
|
|
|
/*
|
|
this is the external filename method.
|
|
*/
|
|
// allfiles: allfiles.sh() //reads MD files.
|
|
// pubfiles: pubfiles.sh(allfiles)
|
|
(list): ..
|
|
allfiles: Tree.filter(list, (val, key) => key.endsWith('.md') && !key.startsWith('_'))
|
|
→ (items) => Tree.map(items, {value: (value) => Origami.document(value)}) //if I don't use the verbose syntax I get the filename characters as part of value!
|
|
→ (items) => Tree.map(items, { value: (value, key) => addFilenameData.js(value, key)})
|
|
|
|
pubfiles: Tree.filter(allfiles, (val, key) => val.fnd.tags?.includes('pub'))
|
|
|
|
/*
|
|
Now convert to html.
|
|
*/
|
|
asHtml: Tree.map(all ? allfiles: pubfiles, {
|
|
value: (value) => Origami.mdHtml(value)
|
|
key: (value, key) => `${value.fnd.name}.html`
|
|
})
|
|
|
|
/*
|
|
after converting to html, we can extract a 'summary' from the file.
|
|
With markdown, the title is taken from the YAML frontmatter,
|
|
and ends up in a separate field of the document.
|
|
So we dont have to worry about the title being part of the summary.
|
|
*/
|
|
withSummary: Tree.map(asHtml, extractSummary.js)
|
|
|
|
/*
|
|
Removing private content coming below the html comment `<!--private-below-->`
|
|
Only remove this if in public mode. So if this file is called as `site.ori("all")`,
|
|
then final output is `withSummary`, otherwise it's `privateRemoved`.
|
|
*/
|
|
privateRemoved: Tree.map(withSummary, removePrivate.js)
|
|
final: (all ? withSummary : privateRemoved)
|
|
|
|
}.final
|
|
|
|
renderedPages: Tree.map(pages, (page) => <page.ori>(page, all))
|
|
/*
|
|
the rendered pages contain links and images.
|
|
We want to find those, and insert a tree of their maps into the output.
|
|
First test is whether that works.
|
|
Second test is whether the paths will be correct.
|
|
*/
|
|
hast = Tree.map(renderedPages, parseHtml.js)
|
|
links: Tree.flat(hast, 2) → (a) => [...new Set(a)]
|
|
|
|
/*
|
|
assets are relative to the pubfiles directory
|
|
*/
|
|
css
|
|
|
|
/*
|
|
Now, I think I have enough to build both the individual pages and the index page!
|
|
*/
|
|
index.html: indexPage.ori(pages, all)
|
|
...renderedPages/
|
|
}
|