diff --git a/.eslintignore b/.eslintignore index 7a5eab56..019650a4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ /browser/ /dist/ +/docs/ /docs-slate/ /lib/ /package-lock.json diff --git a/docs-slate b/docs-slate index 04e15502..a5cd8504 160000 --- a/docs-slate +++ b/docs-slate @@ -1 +1 @@ -Subproject commit 04e155025f60085fddfa6685eeb803e80ef14c2f +Subproject commit a5cd8504c3eb42df98aa9a378bff138468ac87dc diff --git a/docs/prepare-docs.mjs b/docs/prepare-docs.mjs new file mode 100755 index 00000000..bf9ab3f6 --- /dev/null +++ b/docs/prepare-docs.mjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +import { lstat, mkdir, readdir, readFile, symlink, rm } from 'node:fs/promises' +import { resolve } from 'node:path' +import { parseAllDocuments } from '../dist/index.js' + +const source = 'docs' +const target = 'docs-slate/source' + +// Create symlink for index.html.md +const indexSource = resolve(source, 'index.html.md') +const indexTarget = resolve(target, 'index.html.md') +try { + const prevIndex = await lstat(indexTarget) + if (prevIndex.isSymbolicLink()) await rm(indexTarget) +} catch {} +await symlink(indexSource, indexTarget, 'file') + +// Create symlinks for included sections +const includesDir = resolve(target, 'includes') +try { + await mkdir(includesDir) +} catch { + for (const ent of await readdir(includesDir, { withFileTypes: true })) { + if (ent.isSymbolicLink()) await rm(resolve(includesDir, ent.name)) + } +} +const [indexDoc] = parseAllDocuments(await readFile(indexSource, 'utf-8')) +for (const { value } of indexDoc.get('includes').items) { + const name = `${value}.md` + await symlink(resolve(source, name), resolve(includesDir, name), 'file') +} diff --git a/package.json b/package.json index 588c5bb3..d673e8d8 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,9 @@ "test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/index.js", "test:types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json", "docs:install": "cd docs-slate && bundle install", + "predocs:deploy": "node docs/prepare-docs.mjs", "docs:deploy": "cd docs-slate && ./deploy.sh", + "predocs": "node docs/prepare-docs.mjs", "docs": "cd docs-slate && bundle exec middleman server", "preversion": "npm test && npm run build", "prepublishOnly": "npm run clean && npm test && npm run build"