|
|
|
@ -1,3 +1,10 @@ |
|
|
|
|
/* |
|
|
|
|
* Implements a simple markdown blog loader that's used primarily in the |
|
|
|
|
* `rendered/pages/blog` example. It supports generating an RSS/Atom/JSON |
|
|
|
|
* feed of pages, loading an index of .md pages, and render markdown with |
|
|
|
|
* the headers. It uses the `lib/docgen.js:render_with_code` to do the |
|
|
|
|
* main markdown processing. |
|
|
|
|
*/ |
|
|
|
|
import path from "path"; |
|
|
|
|
import glob from "fast-glob"; |
|
|
|
|
import assert from "assert"; |
|
|
|
@ -7,10 +14,18 @@ import { Feed } from "feed"; |
|
|
|
|
// have to use the client config to avoid pino crashing rollup with json errors
|
|
|
|
|
import { base_host } from "../client/config.js"; |
|
|
|
|
|
|
|
|
|
// caches the posts so we don't load them repeatedly during runs
|
|
|
|
|
const POSTS = {}; |
|
|
|
|
|
|
|
|
|
// this keeps POSTS alive, for some reason it disappears during processing
|
|
|
|
|
process.POSTS = POSTS; |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
Takes a directory of `.md` files and returns all of them rendered |
|
|
|
|
to HTML+Metadata using `lib/docgen.js:render_with_code`. |
|
|
|
|
|
|
|
|
|
+ `source string` -- Source directory to read. |
|
|
|
|
*/ |
|
|
|
|
export const load = (source) => { |
|
|
|
|
assert(source !== undefined, "source for markdown processing can't be undefined"); |
|
|
|
|
// just a dumb cache to avoid reading the files over and over
|
|
|
|
@ -45,6 +60,16 @@ export const load = (source) => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
Renders the `/public/feed.rss`, `/public/feed.atom`, and `/public/feed.json` files |
|
|
|
|
based on the `index_config` and posts from `load`. The `index_config` is a `.json` |
|
|
|
|
file that describes the blog. The current configuration can be |
|
|
|
|
found in `renderd/feed_config.json`. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ `index_config string` -- The path to the `feed_config.json` file. |
|
|
|
|
+ `posts Array` -- List of posts. |
|
|
|
|
*/ |
|
|
|
|
export const render_feed = (index_config, posts) => { |
|
|
|
|
const index = JSON.parse(fs.readFileSync(index_config)); |
|
|
|
|
const feed = new Feed(index); |
|
|
|
@ -69,9 +94,4 @@ export const render_feed = (index_config, posts) => { |
|
|
|
|
fs.writeFileSync('../public/feed.atom', feed.atom1()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const index = (source) => { |
|
|
|
|
assert(source !== undefined, "source must be defined"); |
|
|
|
|
return load(source); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default { load, index, render_feed }; |
|
|
|
|
export default { load, render_feed }; |
|
|
|
|