-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-for-publish.ts
executable file
·29 lines (27 loc) · 1.01 KB
/
prepare-for-publish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env -S deno run --allow-read --allow-write
import { join } from "https://deno.land/std/path/mod.ts";
import { walk } from "https://deno.land/std/fs/walk.ts";
for await (
const note of walk(Deno.cwd(), {
includeDirs: false,
exts: ["md"],
skip: [/^\.git$/, /README.md/],
})
) {
const contents = await Deno.readTextFile(note.path);
const match = contents.match(/^---\n(.+)---\n(.+)$/s);
const publish = "dg-publish: true";
const isHome = note.path === join(Deno.cwd(), "Wine.md");
const homeTag = "\ndg-home: true";
const frontmatter = `---\n${match ? match[1] : ""}${publish}${
!isHome ? "" : homeTag
}\n---\n`;
const homeFooter = `
\n\nThis website was created with [Obsidian Digital Garden](https://dg-docs.ole.dev/).
The Obsidian Vault is [available on GitHub](https://github.com/danforbes/wset-notes).
Dan Forbes <[danforbes.dev](https://danforbes.dev/)>`;
Deno.writeTextFileSync(
note.path,
`${frontmatter}${match ? match[2] : contents}${!isHome ? "" : homeFooter}`,
);
}