@jk2908/mdsrc 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +46 -22
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1 - 2026-06-23
|
|
4
|
+
|
|
5
|
+
- Updated README to reflect the new schema API and removed outdated markdown-it references.
|
|
6
|
+
|
|
3
7
|
## 0.4.0 - 2026-06-23
|
|
4
8
|
|
|
5
9
|
- Breaking: replaced the verbose schema API with a simplified string-based syntax. Fields are now declared as `fieldName: 'type'` instead of `fieldName: { type: 'type' }`, optional fields use a `?` suffix (e.g. `'metadata?'`), and nested objects are declared inline without a `schema` wrapper.
|
package/README.md
CHANGED
|
@@ -11,27 +11,19 @@ npm install @jk2908/mdsrc
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import plugin
|
|
15
|
-
import comark from '@comark/markdown-it'
|
|
14
|
+
import plugin from '@jk2908/mdsrc'
|
|
16
15
|
import { defineConfig } from 'vite'
|
|
17
16
|
|
|
18
|
-
const markdownItConfig: MarkdownItConfig = {
|
|
19
|
-
linkify: true,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
17
|
export default defineConfig({
|
|
23
18
|
plugins: [
|
|
24
19
|
plugin({
|
|
25
|
-
markdown: {
|
|
26
|
-
plugins: [comark],
|
|
27
|
-
config: markdownItConfig,
|
|
28
|
-
},
|
|
29
20
|
collections: [
|
|
30
21
|
{
|
|
31
22
|
dir: 'content',
|
|
32
23
|
name: 'post',
|
|
33
24
|
schema: {
|
|
34
|
-
title:
|
|
25
|
+
title: 'string',
|
|
26
|
+
'date?': 'date',
|
|
35
27
|
},
|
|
36
28
|
},
|
|
37
29
|
],
|
|
@@ -40,18 +32,51 @@ export default defineConfig({
|
|
|
40
32
|
})
|
|
41
33
|
```
|
|
42
34
|
|
|
43
|
-
The plugin reads markdown content, validates frontmatter against your schema, and generates typed modules during build and watch. Root config uses `collections`, optional `
|
|
35
|
+
The plugin reads markdown content, validates frontmatter against your schema, and generates typed modules during build and watch. Root config uses `collections`, optional `compileOptions`, and `logger`. Collection config uses `name`, `dir`, and `schema`.
|
|
36
|
+
|
|
37
|
+
### Schema
|
|
38
|
+
|
|
39
|
+
Fields are declared as `fieldName: 'type'`. Supported types: `string`, `number`, `boolean`, `date`, `object`.
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
Optional fields use a `?` suffix: `'metadata?': { author: 'string' }`.
|
|
42
|
+
|
|
43
|
+
Nested objects are declared inline:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
schema: {
|
|
47
|
+
title: 'string',
|
|
48
|
+
'metadata?': {
|
|
49
|
+
author: 'string',
|
|
50
|
+
publishedAt: 'date',
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Compile Options
|
|
56
|
+
|
|
57
|
+
Pass `compileOptions` to customise markdown parsing via satteri:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
plugin({
|
|
61
|
+
compileOptions: {
|
|
62
|
+
features: {
|
|
63
|
+
gfm: true, // tables, footnotes, strikethrough, task lists
|
|
64
|
+
frontmatter: true, // YAML (---) and TOML (+++)
|
|
65
|
+
math: false, // LaTeX math blocks
|
|
66
|
+
smartPunctuation: true, // curly quotes, em-dashes, ellipses
|
|
67
|
+
},
|
|
68
|
+
mdastPlugins: [/* transform mdast tree */],
|
|
69
|
+
hastPlugins: [/* transform hast tree */],
|
|
70
|
+
},
|
|
71
|
+
collections: [/* ... */],
|
|
72
|
+
})
|
|
73
|
+
```
|
|
46
74
|
|
|
47
|
-
|
|
48
|
-
- Raw HTML is escaped by default because the renderer runs with `html: false`.
|
|
49
|
-
- `markdown` preserves the original body for custom renderers like `@comark/react`.
|
|
75
|
+
See [satteri](https://satteri.bruits.org/) for the full list of compile options and feature toggles.
|
|
50
76
|
|
|
51
|
-
|
|
52
|
-
`MarkdownItConfig` is re-exported from `@jk2908/mdsrc`, and `markdown.config` is merged with the default renderer options `{ html: false, breaks: true }`.
|
|
77
|
+
### Output
|
|
53
78
|
|
|
54
|
-
|
|
79
|
+
Each entry exports a `body` field containing the rendered HTML.
|
|
55
80
|
|
|
56
81
|
If you configure a collection with `name: 'post'`, `mdsrc` exposes `allPosts` from the package root.
|
|
57
82
|
|
|
@@ -61,8 +86,7 @@ import { allPosts } from '@jk2908/mdsrc'
|
|
|
61
86
|
export const summaries = allPosts.map(post => ({
|
|
62
87
|
title: post.title,
|
|
63
88
|
slug: post.__mdsrc.slug,
|
|
64
|
-
|
|
65
|
-
markdown: post.markdown,
|
|
89
|
+
body: post.body,
|
|
66
90
|
}))
|
|
67
91
|
```
|
|
68
92
|
|
|
@@ -76,4 +100,4 @@ The generated files live in `./.mdsrc` on disk, so you can import them directly
|
|
|
76
100
|
|
|
77
101
|
## License
|
|
78
102
|
|
|
79
|
-
MIT
|
|
103
|
+
MIT
|