Skip to content

Commit

Permalink
fix: align demo with new feats
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianCataldo committed Nov 1, 2022
1 parent c815371 commit 3cbc16a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 48 deletions.
1 change: 0 additions & 1 deletion demo/content/creative-work.schema.yaml
Expand Up @@ -24,7 +24,6 @@ allOf:
type: string

required:
- title
- category
- complex
# #
Expand Down
@@ -1,7 +1,7 @@
---
'$schema': content/creative-work.schema.yaml
'$schema': ../creative-work.schema.yaml

title: Behind the Gare St. Lazare, Paris, 1932
# title: Behind the Gare St. Lazare, Paris, 1932
category: Video game
---

Expand Down
2 changes: 1 addition & 1 deletion demo/content/creative-work/guten-nachte__local-correct.md
@@ -1,5 +1,5 @@
---
'$schema': content/creative-work.schema.yaml
'$schema': ../creative-work.schema.yaml

title: Guten Nachte
category: Musical piece
Expand Down
10 changes: 5 additions & 5 deletions demo/package.json
Expand Up @@ -12,13 +12,13 @@
"author": "",
"license": "ISC",
"devDependencies": {
"remark": "14.0.2",
"remark-cli": "11.0.0",
"remark-frontmatter": "4.0.1",
"remark-lint-frontmatter-schema": "latest",
"tsx": "^3.11.0"
"tsx": "^3.11.0",
"remark-cli": "11.0.0"
},
"dependencies": {
"remark": "14.0.2",
"remark-frontmatter": "4.0.1",
"remark-lint-frontmatter-schema": "link:..",
"vfile-reporter": "^7.0.4"
}
}
50 changes: 11 additions & 39 deletions demo/pipeline.ts
Expand Up @@ -5,22 +5,15 @@ import remarkFrontmatter from 'remark-frontmatter';
import remarkLintFrontmatterSchema from 'remark-lint-frontmatter-schema';
import type { JSONSchema7 } from 'json-schema';
import { reporter } from 'vfile-reporter';
/* ·········································································· */
import yaml from 'yaml';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
/* —————————————————————————————————————————————————————————————————————————— */

const mySchema: JSONSchema7 = {
/* Set current schema absolute `file:///` URI,
so AJV can resolve relative `$ref`. */

/* (Optional) For easier referencing, put the embedded schema name */
/* \————————————v */
$id: new URL('content/<optional>', import.meta.url).toString(),

allOf: [
{ $ref: './page.schema.yaml' },
{
/* 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: {
Expand All @@ -34,6 +27,7 @@ const mySchema: JSONSchema7 = {
/* ·········································································· */

const mdContent = `---
$schema: './content/creative-work.schema.yaml'
title: 1234
baz: ['wrong']
---
Expand All @@ -51,35 +45,13 @@ const output = await remark()

.use(remarkLintFrontmatterSchema, {
/* Bring your own schema */
embed: mySchema,

/* Override default options so we can resolve `$ref`, etc. */
ajvOptions: {
loadSchema(uri) {
/* Load external referenced schema relatively from schema path */
return new Promise((resolve, reject) => {
/* We use local file here, but you could use anything (fetch…) */
readFile(fileURLToPath(uri), 'utf8')
.then((data) => {
try {
const parsedSchema = yaml.parse(data) as unknown;
if (parsedSchema && typeof parsedSchema === 'object') {
resolve(parsedSchema);
}
} catch (_) {
reject(new Error(`Could not parse ${uri}`));
}
})
.catch((_) => {
reject(new Error(`Could not locate ${uri}`));
});
});
},
},

// embed: mySchema,
//
/* Override default AJV options */
// ajvOptions: {
// },
/* —Or— just (local only) */
// embed: {
// $id: pathToFileURL(mySchemaPath).toString(),
// ...mySchema,
// },
})
Expand Down

0 comments on commit 3cbc16a

Please sign in to comment.