-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
pipeline.ts
83 lines (70 loc) · 2.4 KB
/
pipeline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Launch with `pnpm pipeline` */
import { remark } from 'remark';
import remarkFrontmatter from 'remark-frontmatter';
import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema';
import type { JSONSchema7 } from 'json-schema';
import { reporter } from 'vfile-reporter';
/* —————————————————————————————————————————————————————————————————————————— */
const mySchema: JSONSchema7 = {
allOf: [
{
/* Works with local / remote, YAML / JSON */
$ref: './content/page.schema.yaml',
// $ref: 'https://raw.githubusercontent.com/JulianCataldo/remark-lint-frontmatter-schema/master/demo/content/page.schema.yaml',
},
{
properties: {
baz: {
type: 'string',
},
},
},
],
};
/* ·········································································· */
const mdContent = `---
$schema: './content/creative-work.schema.yaml'
title: 1234
baz: ['wrong']
---
# Hey !`;
/* ·········································································· */
console.log('Demo pipeline starting!…\n');
const output = await remark()
// Your pipeline (basic example)
// …
.use(remarkFrontmatter)
.use(remarkLintFrontmatterSchema, {
/* Bring your own schema */
// embed: mySchema,
//
/* Override default AJV options */
// ajvOptions: {
// },
/* —Or— just (local only) */
// embed: {
// ...mySchema,
// },
})
.process(mdContent);
/* ·········································································· */
output.path = import.meta.url;
// Or if you like, for easier referencing:
// output.path = mySchema.$id ?? '<No file path>';
console.error(reporter([output]));
/**
* Yields:
*
* ```sh
* file:///<...>/content/
* 2:8-2:12 warning Keyword: type frontmatter-schema remark-lint
* Type: string
* Schema path: · ./content/page.schema.yaml/properties/title/type
* 3:6-3:15 warning Keyword: type frontmatter-schema remark-lint
* Type: string
* Schema path: · #/allOf/1/properties/baz/type
*
* ⚠ 2 warnings
* ```
*
*/