support for stripping off frontmatter

This commit is contained in:
2023-04-29 17:19:34 -07:00
parent 8c33dd7a1a
commit a26588835b
6 changed files with 64 additions and 1 deletions

View File

@@ -38,6 +38,28 @@ async function main() {
}
```
### Handling Frontmatter
```ts
import { process_frontmatter } from './build';
const raw_content = `---
title: Example Markdown with Frontmatter
foo:
- bar
- baz
---
# This is some markdown
`;
const { frontmatter, markdown } = process_frontmatter(raw_content);
console.log(frontmatter.title); // "Example Markdown with Frontmatter"
console.log(frontmatter.foo); // [ "bar", "baz" ]
console.log(markdown); // "\n# This is some markdown\n"
```
## Command Line Use
@@ -46,6 +68,22 @@ async function main() {
echo '# This is some markdown' | ./bin/markdown2html --base-url 'https://example.com' > output.html
```
### Handling Frontmatter
```bash
filecontents="---
title: Example Markdown with Frontmatter
foo:
- bar
- baz
---
# This is some markdown
"
echo "$filecontents" | ./bin/strip-frontmatter frontmatter.json > markdown.md
```
## Options