-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
noticed while updating the enabler content JSON files that the feedback was too late if i wait to run astro to see if the JSON is valid. we can show linting marks with vscode and JSON schema definitions this sets up that linting config and adds a script to generate the schema JSON files off the Zod source of truth that's used by astro
- Loading branch information
1 parent
4a4dec3
commit 29b2954
Showing
10 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"json.schemas": [ | ||
{ | ||
"fileMatch": ["/site/src/content/enabler/*.json"], | ||
"url": "./site/src/schemas/enabler.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import fs from "fs"; | ||
// @ts-expect-error bun types not up to date on alpha api (?) | ||
import { $ } from "bun"; | ||
import { zodToJsonSchema } from "zod-to-json-schema"; | ||
|
||
const zodFiles = await $`ls site/src/schemas`; | ||
const modules = zodFiles.stdout | ||
.toString() | ||
.split("\n") | ||
.map((line: string) => line.trim()); | ||
|
||
modules.forEach((fileName: string) => { | ||
if (fileName) { | ||
const { schema, name } = require(`../site/src/schemas/${fileName}`); | ||
const jsonSchema = zodToJsonSchema(schema, name); | ||
fs.writeFileSync( | ||
`site/src/schemas/${name}.json`, | ||
JSON.stringify(jsonSchema, null, 2) | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { defineCollection } from "astro:content"; | ||
import { enablerSchema } from "../schemas/enabler"; | ||
import { schema } from "../schemas/enabler"; | ||
|
||
export const collections = { | ||
enabler: defineCollection({ | ||
type: "data", | ||
schema: enablerSchema, | ||
schema, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# zod schemas | ||
|
||
Astro uses Zod to enforce content JSON schema. We use JSON schemas to make editing easier, and you can generate the json schemas in this folder with `bun run gen-schemas` from the root of the repo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"$ref": "#/definitions/enabler", | ||
"definitions": { | ||
"enabler": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"bio": { | ||
"type": "string" | ||
}, | ||
"image": { | ||
"type": "string" | ||
}, | ||
"posts": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"type": { | ||
"type": "string", | ||
"enum": [ | ||
"twitter" | ||
] | ||
}, | ||
"href": { | ||
"type": "string" | ||
}, | ||
"text": { | ||
"type": "string" | ||
}, | ||
"date": { | ||
"type": "string" | ||
}, | ||
"image": { | ||
"type": "string" | ||
}, | ||
"imageCaption": { | ||
"type": "string" | ||
}, | ||
"commentary": { | ||
"type": "string" | ||
}, | ||
"skip": { | ||
"type": "boolean" | ||
}, | ||
"quote": { | ||
"type": "object", | ||
"properties": { | ||
"text": { | ||
"type": "string" | ||
}, | ||
"author": { | ||
"type": "string" | ||
}, | ||
"image": { | ||
"type": "string" | ||
}, | ||
"imageCaption": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"text", | ||
"author" | ||
], | ||
"additionalProperties": false | ||
} | ||
}, | ||
"required": [ | ||
"type", | ||
"href", | ||
"date" | ||
], | ||
"additionalProperties": false | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"bio", | ||
"posts" | ||
], | ||
"additionalProperties": false | ||
} | ||
}, | ||
"$schema": "http://json-schema.org/draft-07/schema#" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters