@fkrzski/docs-schema
v0.6.0
Published
Shared frontmatter schema + validator for project docs (Astro content collection + CI validator)
Maintainers
Readme
@fkrzski/docs-schema
Shared frontmatter contract + validator for the open-source project docs published at
docs.fkrzski.dev. One source of truth, consumed by the docs site,
which builds its Astro content collection on it, and by a standalone CLI that project repos run
against their own docs/ folder in CI.
What it checks
Frontmatter — every page matches the schema: required
title+ SEO-boundeddescription(50–160 chars), optionalrepository/packagist(vendor/package) /crates(a crates.io crate name) /status(stable | experimental | deprecated).Markdown —
.mdfiles pass a shared markdownlint config (co-located in the validator).Links — relative internal links resolve to a real file the docs site publishes.
Components —
.mdxpages use onlyAside,Badge,FileTree,Steps,TabsandTabItem, which the docs site provides to every page, so a page imports nothing. Any other component tag is an error, and so is any import,@astrojs/starlight/componentsincluded.Changelog — the
CHANGELOG.mdbeside the docs folder, when there is one, passes the same markdownlint config and follows Keep a Changelog 1.1.0:- it opens with
# Changelog, and any text may follow before the first release; - every
##is## [Unreleased]or## [X.Y.Z] - YYYY-MM-DD, optionally ending in[YANKED], with a SemVer 2.0.0 version and a real date; [Unreleased]comes first and once, releases go newest first by SemVer precedence, each once, and dates never increase down the file;- every
###isAdded,Changed,Deprecated,Removed,FixedorSecurity, once per release, and no other heading levels appear; - every section lists at least one item and every release has a section, though an empty
[Unreleased]is fine; - every bracketed version has a link definition such as
[0.9.0]: https://….
The docs site builds the project's changelog page from it, so a
changelog.mdorchangelog.mdxpage in the docs root is an error.- it opens with
Sidebar and versions — the
_meta.jsonin the docs folder, when there is one, matches Order pages and publish versions. The paths itsignorelists are no pages, so none of the checks above reads them.
Site-absolute and cross-project links are left to the docs site's link check at build time;
the CLI only catches problems an author can fix inside their own docs/ folder.
Validate a docs folder in CI
Add one step to a project repo's workflow — no other dependency, and no reference to any private tooling repo:
- uses: actions/checkout@v4
- uses: actions/setup-node@v6
with:
node-version: 24
- name: Validate docs
run: npx --yes @fkrzski/docs-schema docsdocs is the folder to validate (relative to the repo root). Exit codes: 0 pass, 1
validation problems, 2 usage error — so it gates the job like any other check.
The CHANGELOG.md next to that folder is validated with it, when there is one. If the workflow
filters on paths, add CHANGELOG.md there so a changelog edit runs the check too.
Prefer a pinned dependency? Add @fkrzski/docs-schema to devDependencies and run
docs-validate docs from a script instead of npx.
Order pages and publish versions
The sidebar lists the overview, then every other page by its path. A _meta.json in the docs
folder sets another order, publishes older versions beside the latest one and keeps Markdown that
is no page out of the docs site:
{
"pages": ["guide", "configuration", "rate-limiting", "testing"],
"versions": [{ "id": "v1", "label": "1.x", "ref": "1.4.0" }],
"ignore": ["adr", "agents"]
}Every key is optional, and no other key is allowed.
pageslists every page by its path without the extension (guide,guides/install), once each and in kebab-case. The overview (index) always comes first and the<name>-referencepages sit apart, so neither goes in the list.versionspins each older version to a branch, tag or commit and publishes it at/<project>/<id>. Theidis kebab-case without dots, unique, and neitherlatest,changelognor the name of a page.labelnames it in the version switcher (idby default).ignorelists paths relative to the docs folder: a folder covers everything below it, a file takes its extension, and there are no globs. Each entry is listed once, without a leading/,.or.., and must match a file or folder. The validator and the docs site skip those paths, sopagesleaves them out and a relative link into them is an error.- Only the file on the default branch publishes versions. Each version's own
_meta.json, if its ref has one, orders that version's pages and lists what it ignores; without one its pages go by path.
Trigger a docs deploy from a project repo
Docs go live from the central docs site, whose build pulls every project's docs/ afresh; a
project repo signals "my docs changed" by POSTing to the site's Cloudflare Pages deploy hook. The
hook URL is a secret, so nothing about the docs infrastructure appears in the public workflow:
- name: Trigger docs deploy
env:
DOCS_DEPLOY_HOOK: ${{ secrets.DOCS_DEPLOY_HOOK }}
run: curl -fsS -X POST "$DOCS_DEPLOY_HOOK"Run it after the validate step, on pushes to the default branch that touch docs/ or
CHANGELOG.md, so every build has something new to ship. Each project gets a hook of its own,
named after it, so a deployment shows which repo started it and a leaked hook is revoked alone.
Programmatic use
import { docsFrontmatterSchema, parseChangelog, packagistApiUrl } from '@fkrzski/docs-schema';docsFrontmatterSchema— the Zod schema, a plainz.object, so.extend()adds site-only fields.projectStatuses— the allowedstatusvalues.contentComponents/ContentComponent— the components an.mdxpage may use.packagistPageUrl(pkg)/packagistApiUrl(pkg)—vendor/package→ Packagist page / JSON API.cratesPageUrl(name)/cratesApiUrl(name)— crate name → crates.io page / JSON API.parseChangelog(markdown)— a Keep a Changelog file →{ releases, issues }, with what parsed returned next to the issues; each release has itsversion,date,yanked,url,lineandsections.changelogSections/ChangelogSection— the six###sections a release may have.
License
MIT © Filip Krzyżanowski
