Skip to content

Commit

Permalink
🦄 feature: Add frontmatter support (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrosenbauer authored Dec 12, 2024
1 parent f5a9ec4 commit 052b0a6
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 39 deletions.
12 changes: 8 additions & 4 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import path from 'node:path';

const __dirname = path.dirname(new URL(import.meta.url).pathname);

import exampleBasic from './lib/basic';
import exampleCode from './lib/code';
import exampleTable from './lib/table';
import exampleBasic from './inputs/basic';
import exampleCode from './inputs/code';
import exampleFrontmatter from './inputs/frontmatter';
import exampleTable from './inputs/table';

/*
|----------------------------------
Expand All @@ -25,16 +26,19 @@ import exampleTable from './lib/table';
const basicResult = exampleBasic();
const codeResult = exampleCode();
const tableResult = exampleTable();
const frontmatterResult = exampleFrontmatter();

const examplesDir = path.join(__dirname, '..', 'examples', 'docs');
const examplesDir = path.join(__dirname, '..', 'examples', 'outputs');
const basicFile = path.join(examplesDir, 'basic.md');
const codeFile = path.join(examplesDir, 'code.md');
const tableFile = path.join(examplesDir, 'table.md');
const frontmatterFile = path.join(examplesDir, 'frontmatter.md');

Promise.all([
fs.writeFile(basicFile, basicResult),
fs.writeFile(codeFile, codeResult),
fs.writeFile(tableFile, tableResult),
fs.writeFile(frontmatterFile, frontmatterResult),
]);

console.log('Examples built successfully.');
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/basic.ts → examples/inputs/basic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tempo from '../../src';
import tempo from '../../packages/tempo/src';

function run() {
return tempo()
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/code.ts → examples/inputs/code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tempo from '../../src';
import tempo from '../../packages/tempo/src';

function run() {
return tempo()
Expand Down
31 changes: 31 additions & 0 deletions examples/inputs/frontmatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import tempo from '../../packages/tempo/src';

function run() {
return tempo()
.frontmatter({
title: 'Frontmatter Example',
description: 'This is an example of frontmatter',
tags: ['example', 'frontmatter'],
published: true,
version: 1,
})
.h1('Hello World')
.paragraph('This is a paragraph')
.h2((text) => text.plainText('This is a heading with ').bold('bold text'))
.paragraph((text) => text.bold('This is bold text'))
.paragraph(
(text) => `This is inline text ${text.italic('with italic text')}`
)
.paragraph((text) =>
text.plainText('Foobar is a thing').bold('that is bold')
)
.h2('Lists')
.alert('This is an alert', 'caution')
.paragraph('This is a list')
.bulletList(['Item 1', 'Item 2', 'Item 3'])
.paragraph('This is a numbered list')
.numberList(['Item 1', 'Item 2', 'Item 3'])
.toString();
}

export default run;
2 changes: 1 addition & 1 deletion examples/lib/table.ts → examples/inputs/table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tempo from '../../src';
import tempo from '../../packages/tempo/src';

function run() {
return tempo()
Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions examples/outputs/frontmatter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Frontmatter Example
description: This is an example of frontmatter
tags:
- example
- frontmatter
published: true
version: 1
---
# Hello World

This is a paragraph

## This is a heading with **bold text**

**This is bold text**

This is inline text _with italic text_

Foobar is a thing **that is bold**

## Lists

> [!CAUTION]
> This is an alert
This is a list

- Item 1
- Item 2
- Item 3

This is a numbered list

1. Item 1
2. Item 2
3. Item 3
File renamed without changes.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"packages/*"
],
"scripts": {
"generate:examples": "tsx examples/index.ts",
"analyze": "biome check",
"analyze:types": "turbo analyze:types",
"analyze:ci": "biome ci --diagnostic-level=error",
Expand Down
4 changes: 3 additions & 1 deletion packages/tempo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"dev": "rslib build --watch",
"build": "rslib build",
"test": "vitest --coverage",
"generate:examples": "tsx examples/index.ts",
"analyze:types": "tsc --noEmit"
},
"devDependencies": {
Expand All @@ -43,5 +42,8 @@
"type-fest": "^4.30.0",
"typescript": "^5.7.2",
"vitest": "^2.1.8"
},
"dependencies": {
"yaml": "^2.6.1"
}
}
Loading

0 comments on commit 052b0a6

Please sign in to comment.