4 ms·
I made my own static site generator in a very similar fashion, a small recommendation/tip I found is that instead of creating your own "use this template" defin
by franciscop 5y ago
I made my own static site generator in a very similar fashion, a small recommendation/tip I found is that instead of creating your own "use this template" definition, you could use "Front Matter"[1] to define this initially:
---
template: custom.html
---
# My normal markdown
Since it's a fairly standard tool, parsing it is trivial with npm packages[2] and you don't need to be manually parsing the strings:
import fm from "front-matter";
const data = await fs.readFile(...);
const { attributes, body } = await fm(data);
// attributes: { template: "custom.html" }
// body: "# My normal markdown ..."
[1] https://jekyllrb.com/docs/front-matter/ https://jekyllrb.com/docs/front-matter/
[2] https://www.npmjs.com/package/front-matter https://www.npmjs.com/package/front-matter
- Zababa 5y agoFront matter are YAML. I wouldn't call parsing it trivial, though if you want to create a simpler alternative and don't think about it, you're probably going to end up with something worse than YAML.
- franciscop 5y agoI never did. I call trivial using an existing tool designed for this, I would def not expect the author be parsing front-matter code manually (as shown in my example).
- yakkomajuri 5y agoHey, thanks for pointing out the `front-matter` library. I've updated Teeny to use that instead of HTML comments.