everything: save state bc need to start again
This commit is contained in:
commit
a93570d6b7
|
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
title: foobar
|
||||
---
|
||||
|
||||
(see test.ori. This is confusing!)
|
||||
So I was wondering the following, but I believe by default the path `..` returns a shallow tree by default, so the question is moot. That is: I was stuck on how to apply a regex to a nested tree of file paths, but I was erroneously assuming the tree was deep, but it's not.
|
||||
|
||||
My original solution therefore works because the input is already just the top-level flat directory contents:
|
||||
|
||||
```
|
||||
{
|
||||
all: ..
|
||||
filtered: Tree.filter(raw, (val, key) => key.endsWith('.md')) //yes, should really use globKeys for this, but actually I'm doing a more complex comparison with AND here
|
||||
}
|
||||
```
|
||||
|
||||
Nevertheless, I can't figure out if its possible to achieve the goal stated in the subject.
|
||||
|
||||
`globKeys` supports a limited set of glob patterns. I guess `mask` with `regExpKeys` is probably the closest, but it's not going to work across deep paths?
|
||||
|
||||
given this directory structure:
|
||||
|
||||
```
|
||||
/src
|
||||
readme.md
|
||||
installation.md
|
||||
node_modules/
|
||||
package/
|
||||
readme.md
|
||||
```
|
||||
|
||||
I only want `src/readme.md` and `src/installation.md`.
|
||||
|
||||
I came up with this, except is it going to be a deep operation?
|
||||
|
||||
```
|
||||
{
|
||||
all: ..
|
||||
selected: Tree.map(all, Tree.regExpKeys({"^[^\/]+?\/.*\.md$": false}))
|
||||
}
|
||||
```
|
||||
the regex returns false if the string ends with `.md` but also has a folder name with slash at the beginning. So these are excluded from the result.
|
||||
|
||||
huh: would you have to do some rewriting of keys to a flat map with concatenated paths?
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: ok
|
||||
id: testit
|
||||
date: today
|
||||
---
|
||||
|
||||
# My file
|
||||
|
||||
${<_index.md>}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: My Public File
|
||||
cuid: 26e4-a1
|
||||
---
|
||||
|
||||
This is a public file with some nice text.
|
||||
|
||||
It's easy to write in this file.
|
||||
<!--summary-above-->
|
||||
I can write more things after the comment if I want.
|
||||
|
||||
|
||||
<!--private-below-->
|
||||
Whatever!
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
files: site.ori('')/filenames
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
files: site.ori("all")/filenames
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fd -e md --color=never
|
||||
#fd -e txt
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Another Public File
|
||||
cuid: 26ef-a0
|
||||
---
|
||||
|
||||
This file is also public. But not all of it.
|
||||
<!--private-below-->
|
||||
This part will not be shown.
|
||||
Everything following here will be hidden from private view!
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Another File
|
||||
cuid: 26e4-a2
|
||||
---
|
||||
|
||||
Just some text, in this file.
|
||||
<!--summary-above-->
|
||||
This file should only be shown if site was built with `site.ori("all")`,
|
||||
because it does not have `_pub` in its filename.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
//base page template
|
||||
(page) => Tree.indent`
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>${page.title}</title>
|
||||
<link href="/css/style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
${page.indexPage ? '' : '<a href="/">↖index</a>'}
|
||||
${page._body}
|
||||
</html>
|
||||
`
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
body {
|
||||
font-family: "Jost*";
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
const reg = /^(?<summary>.+)?<!--summary-above-->/s
|
||||
export default (doc) => {
|
||||
const result = reg.exec(doc._body);
|
||||
if (result) {
|
||||
doc.summary = result.groups.summary;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
(pages) => base_html.ori({
|
||||
indexPage: true
|
||||
title: 'Hans Fast'
|
||||
_body: Tree.indent`
|
||||
<h1>Hans Fast</h1>
|
||||
${Origami.mdHtml(_index.md)}
|
||||
${Tree.map(pages, (value, key) => pageSummaries.ori.html(value, key))}
|
||||
</body>
|
||||
`
|
||||
})
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@weborigami/origami": "^0.6.12"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(page) => base_html.ori({
|
||||
indexPage: false
|
||||
title: page.title
|
||||
_body: Tree.indent`
|
||||
<h1>${page.title}</h1>
|
||||
${page._body}
|
||||
<a href="/">↖index</a>
|
||||
`
|
||||
})
|
||||
|
|
@ -0,0 +1 @@
|
|||
//a templ
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
//return title and html ...
|
||||
export default (doc) => {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
(value, key) => _template()
|
||||
---
|
||||
<article>
|
||||
<a href=${key}><h1>${value.title}</h1></a>
|
||||
${value.summary || ""}
|
||||
</article>
|
||||
|
|
@ -0,0 +1 @@
|
|||
rg '_pub' || true
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import {promises} from 'fs';
|
||||
const {readFile} = promises;
|
||||
export default async function readFiles(filelist) {
|
||||
const filenames = filelist.split('\n').filter(name => name !== '')
|
||||
const files = {};
|
||||
for (const file of filenames) {
|
||||
const contents = await readFile(file, 'utf-8');
|
||||
files[file] = contents;
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
const reg = /^(?<public>.+)<!--private-below-->.+$/s
|
||||
export default (doc) => {
|
||||
const result = reg.exec(doc._body);
|
||||
if (result) {
|
||||
doc._body = result.groups.public;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
(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.
|
||||
*/
|
||||
// allfiles: allfiles.sh() //reads MD files.
|
||||
// pubfiles: pubfiles.sh(allfiles)
|
||||
(list): ..
|
||||
allfiles: Tree.filter(list, (val, key) => key.endsWith('.md') && !key.startsWith('_'))
|
||||
pubfiles: Tree.filter(allfiles, (val, key) => key.includes('_pub'))
|
||||
files: Tree.map( all ? allfiles : pubfiles, {value: (val) => Origami.document(val)})
|
||||
asHtml: Tree.map(files, (value) => Origami.mdHtml(value))
|
||||
→ (values) => Tree.mapExtension(values, '.md→.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.ori)
|
||||
|
||||
/*
|
||||
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)
|
||||
...renderedPages/
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
echo "$1"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
while read line
|
||||
do echo "$line"
|
||||
done
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
test: {
|
||||
"readme.md": "hello world"
|
||||
"index.js" : "import nest from './a/nested.js'"
|
||||
a: {
|
||||
"nested.md": "myfile"
|
||||
"nested.js": "export default nest = ''"
|
||||
b: {
|
||||
"deeper.md" : "deep inside"
|
||||
}
|
||||
}
|
||||
}
|
||||
raw: ..
|
||||
files: Tree.filter(raw, (val, key) => key.endsWith('.md') && /^[a-p]+_/.test(key))
|
||||
regexpd: Tree.mask(test, Tree.regExpKeys({"^[^\/]+?\/.*\.md$": false}))
|
||||
//regexpdtop: Tree.mask(test, Tree.globKeys({"**": {"*.md": true}}))
|
||||
regexpdtest: Tree.mask(test, {
|
||||
...Tree.constant(true)
|
||||
...Tree.regExpKeys({
|
||||
"^[^\/]+?\/.*\.md$": false
|
||||
})})
|
||||
regexpdfiles: Tree.mask(files, {
|
||||
...Tree.constant(true)
|
||||
...Tree.regExpKeys({
|
||||
"^[^\/]+?\/.*\.md$": false
|
||||
})})
|
||||
paths: Tree.paths(test)
|
||||
regexpaths: Tree.map(Tree.filter(paths, (value) => /^[^\/]+?\/.*\.md$/.test(value)), {key: (value, key) => value, value: (value) => true})
|
||||
excluded: Tree.mask(paths, regexpaths)
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
export default async (value) => {
|
||||
if (value.unpack) {
|
||||
const unpacked = await value.unpack();
|
||||
console.log(unpacked);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
test: testfile.ori.md/
|
||||
all: .
|
||||
allmd: Tree.filter(all, (val, key) => key.endsWith('.md') && !key.startsWith('_'))
|
||||
docs: Tree.map(allmd, {value: (val) => Origami.unpack(val)})
|
||||
}
|
||||
Loading…
Reference in New Issue