Skip to content

Commit 936cf2d

Browse files
committed
Build spec files to the "web" folder
1 parent 999f73b commit 936cf2d

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

Diff for: .gitignore

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
jsonschema-*.html
2-
jsonschema-*.pdf
3-
jsonschema-*.txt
1+
# Markdown builds
2+
web/
3+
4+
# IETF builds
5+
json-schema-use-cases.html
6+
json-schema-use-cases.pdf
7+
json-schema-use-cases.txt
48
relative-json-pointer.html
59
relative-json-pointer.pdf
610
relative-json-pointer.txt
7-
proposals/*.html
811

912
# For the Python enviornment
1013
.venv

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ To build the spec files to HTML from the Markdown sources, run `npm run
2929
build-all`.
3030
You can also build each individually with `npm run build -- filename.md`
3131
(Example: `npm run build -- jsonschema-core.md`). You can also use wildcards to
32-
build multiple specs at the same time: `npm run build -- jsonschema-*.md`.
32+
build multiple specs at the same time: `npm run build -- jsonschema-*.md`. The
33+
HTML files will be available in the `web` folder.
3334

3435
The spec is built using [Remark](https://remark.js.org/), a markdown engine with
3536
good support for plugins and lots of existing plugins we can use.

Diff for: build/build.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-console */
22
import dotenv from "dotenv";
3-
import { readFileSync, writeFileSync } from "node:fs";
4-
import { dirname, basename } from "node:path";
5-
import { argv } from "node:process";
3+
import { mkdir, readFile, writeFile } from "node:fs/promises";
4+
import { dirname, resolve, relative } from "node:path";
5+
import { argv, cwd } from "node:process";
66
import { reporter } from "vfile-reporter";
77
import { remark } from "remark";
88
import remarkCodeTitles from "./remark-code-titles.js";
@@ -22,8 +22,8 @@ import rehypeStringify from "rehype-stringify";
2222

2323
dotenv.config();
2424

25-
const build = async (filename) => {
26-
const md = readFileSync(filename, "utf-8");
25+
const build = async (filePath) => {
26+
const md = await readFile(filePath, "utf-8");
2727
const file = await remark()
2828
.use(remarkPresetLintMarkdownStyleGuide)
2929
.use(remarkLintMaximumHeadingLength, false)
@@ -62,8 +62,12 @@ const build = async (filename) => {
6262
.use(rehypeStringify)
6363
.process(md);
6464

65-
const outfile = `${dirname(filename)}/${basename(filename, ".md")}.html`;
66-
writeFileSync(outfile, `<!DOCTYPE html>
65+
const rootPath = resolve(import.meta.dirname, "..");
66+
const outPath = resolve(rootPath, "web");
67+
const sourceRelativePath = relative(rootPath, filePath);
68+
const outfile = resolve(outPath, sourceRelativePath).replace(/\.md$/, ".html");
69+
await mkdir(dirname(outfile), { recursive: true });
70+
await writeFile(outfile, `<!DOCTYPE html>
6771
<html>
6872
<head>
6973
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
@@ -184,7 +188,8 @@ const build = async (filename) => {
184188
let messageCount = 0;
185189
for (const filename of files) {
186190
console.log(`Building: ${filename} ...`);
187-
messageCount += await build(filename);
191+
const filePath = resolve(cwd(), filename);
192+
messageCount += await build(filePath);
188193
console.log("");
189194
}
190195

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"lint": "eslint build/",
9-
"build-all": "node build/build.js jsonschema-*.md proposals/*.md",
9+
"build-all": "node build/build.js jsonschema-*.md proposals/*.md output/*.md",
1010
"build": "node build/build.js"
1111
},
1212
"license": "MIT",

0 commit comments

Comments
 (0)