Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check the shared specification site
on:
pull_request:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Verify the generic Building Block example
uses: ./
with:
source: examples/building-block
output: ${{ runner.temp }}/building-block-site
base: /building-block/
unofficial: 'true'
54 changes: 50 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ Every profile requires an explicit source, either `--source` or the
`DOCS_SOURCE_ROOT` environment variable. There is no default, so a build cannot
silently pick up a different or dirty checkout.

## OpenAPI references

Framework sources can opt into Scalar references with `api-references.yml`:

```yaml
references:
- id: consultation
page: resources/api-reference.md
contract: api/openapi.yaml
role: normative
- id: birth-registration
page: resources/api-examples/birth-registration.md
contract: api/examples/birth-registration.openapi.yaml
role: example
```

Each `page` identifies a Markdown page in the source navigation. On these pages,
the renderer replaces the prose with native Scalar, a short role label, download
links, and closed technical metadata. There is no iframe or repeated introductory
response. Examples stay inside the owning contract. A missing local dependency
fails the build. An optional `operationId` and successful `response` pair can
validate a published response example; `example` selects a named example for
that pair. These selection fields are not needed to render a contract.

`role` is explicit: `normative` labels a draft transport contract, while `example`
labels an illustrative binding that adds no conformance requirements. Both the
navigation and reference page retain that distinction. Response values remain
illustrative even on a normative contract page.

Scalar 1.76.4 and bundled contracts are served locally, including project-subpath
deployments. Contract references must resolve inside the source repository;
remote references and escaping symlinks are rejected. Source contract bytes stay
unchanged and every dependency contributes to the source digest. API execution,
AI chat, and telemetry are disabled; references follow the site's theme.
Sources without this configuration retain their existing pages and navigation.
Operation-level `x-*` metadata is collected for every Building Block, without
requiring Digital Registries extensions. Built-output checks verify the native
host, role label, collapsed metadata, and bundled contract digest.

## Local use

Use Node 24.11 or later. From this directory:
Expand Down Expand Up @@ -86,13 +125,20 @@ skipped, with the reason printed, unless these variables are set:
`GOVSTACK_SITE_RENDERER`.
- Framework-format specifications call the CLI directly with
`--profile framework --source <specification>`.
- The template's `specification-site/` directory is a thin framework wrapper
that can be copied into a Building Block. It checks source-format and native
Scalar compatibility before running the shared renderer.
- [`action.yml`](action.yml) provides a build-only composite GitHub Action.
See [Building Block integration](docs/building-block-integration.md) for local
setup, pinned CI consumption, and activation prerequisites.

## Not yet

The repository is published at
<https://github.com/jeremi/govstack-specification-site>, but there are no tagged
releases and no version pinning yet. Until tags exist, consumers point
`GOVSTACK_SITE_RENDERER` at a local checkout of this repository.
The repository is available at
<https://github.com/jeremi/govstack-specification-site>. Consumers can pin a
published full commit; tagged releases are not required. The native Scalar
integration and composite action must be published before hosted consumers can
select them. A local checkout works through `GOVSTACK_SITE_RENDERER` meanwhile.

## Ownership and generated files

Expand Down
51 changes: 51 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: GovStack specification site
description: Build and verify a specification with the shared renderer and native OpenAPI references.
inputs:
source:
description: Specification source directory, absolute or relative to the caller workspace.
required: true
output:
description: Static output directory, separate from the source and renderer.
required: true
profile:
description: Source adapter, framework or api-guide.
default: framework
base:
description: Site URL prefix, including leading and trailing slashes.
default: /
unofficial:
description: Keep unofficial preview notices unless explicitly set to false.
default: 'true'
source-url:
description: Optional GitHub source URL for the api-guide adapter.
default: ''
runs:
using: composite
steps:
- name: Set up Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
with:
node-version: '24'
- name: Install the shared renderer
shell: bash
working-directory: ${{ github.action_path }}
run: |
#!/usr/bin/env bash
set -euo pipefail
npm ci --ignore-scripts --no-audit --no-fund
- name: Build and verify the specification site
id: build
shell: bash
working-directory: ${{ github.workspace }}
env:
GOVSTACK_RENDERER_ROOT: ${{ github.action_path }}
DOCS_PROFILE: ${{ inputs.profile }}
DOCS_SOURCE_ROOT: ${{ inputs.source }}
DOCS_DIST_DIR: ${{ inputs.output }}
DOCS_BASE: ${{ inputs.base }}
DOCS_UNOFFICIAL: ${{ inputs.unofficial == 'false' && '0' || '1' }}
DOCS_SOURCE_URL: ${{ inputs.source-url }}
run: |
#!/usr/bin/env bash
set -euo pipefail
node "$GOVSTACK_RENDERER_ROOT/scripts/site.mjs" check
53 changes: 38 additions & 15 deletions adapters/framework.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import path from 'node:path';
import { promisify } from 'node:util';

import GithubSlugger from 'github-slugger';
import GithubSlugger, { slug } from 'github-slugger';
import remarkFrontmatter from 'remark-frontmatter';
import remarkGfm from 'remark-gfm';
import remarkParse from 'remark-parse';
Expand All @@ -23,6 +23,7 @@ import YAML from 'yaml';

import { robotsContent } from '../scripts/publication.mjs';
import { isPublishableSupportPath } from '../scripts/support-paths.mjs';
import { apiReferenceMarkup, apiReferenceSidebar, prepareApiReferences } from '../scripts/api-references.mjs';

const execFileAsync = promisify(execFile);
const parser = unified().use(remarkParse).use(remarkGfm).use(remarkFrontmatter, ['yaml']);
Expand All @@ -48,7 +49,7 @@ export function routeFor(source) {
: source.slice(0, -'.md'.length);
return route
.split('/')
.map((segment) => segment.replaceAll('.', ''))
.map((segment) => slug(segment))
.join('/');
}

Expand Down Expand Up @@ -621,11 +622,12 @@ ${authorRows}
// Redirect and download index pages keep the bare noindex unless the build is unofficial.
const supportRobots = (unofficial) => (unofficial ? robotsContent(true) : 'noindex');

function generatedFrontmatter({ title, description, pagefind }, unofficial) {
function generatedFrontmatter({ title, description, pagefind, apiReference }, unofficial) {
return `---\n${YAML.stringify({
title,
description,
...(pagefind === false ? { pagefind: false } : {}),
...(apiReference ? { tableOfContents: false, prev: false, next: false } : {}),
head: [{ tag: 'meta', attrs: { name: 'robots', content: robotsContent(unofficial) } }],
})}---\n\n`;
}
Expand Down Expand Up @@ -678,7 +680,7 @@ function transformBody({ page, pageRoutes, pageAnchors, base, metadata, authors,
? frontmatter.description.trim()
: sourceName === 'README.md'
? metadata.abstract
: `${title} in the Digital Registries specification.`;
: `${title} in the ${metadata.name} specification.`;
return `${generatedFrontmatter({ title, description, pagefind: isArchive ? false : undefined }, unofficial)}${body}`;
}

Expand Down Expand Up @@ -906,7 +908,7 @@ async function writeSupportDirectoryIndexes(
await mkdir(path.dirname(output), { recursive: true });
await writeFile(
output,
`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="robots" content="${supportRobots(unofficial)}"><title>${htmlEscape(directory)} downloads</title></head><body data-pagefind-ignore><main><h1>${htmlEscape(directory)} downloads</h1><p>Source support files for the local Digital Registries preview.</p><ul>${links.join('')}</ul></main></body></html>\n`,
`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="robots" content="${supportRobots(unofficial)}"><title>${htmlEscape(directory)} downloads</title></head><body data-pagefind-ignore><main><h1>${htmlEscape(directory)} downloads</h1><p>Source support files for the specification preview.</p><ul>${links.join('')}</ul></main></body></html>\n`,
);
indexes.push(`${directory}/index.html`);
}
Expand Down Expand Up @@ -1016,12 +1018,33 @@ export async function generateSite({ sourceRoot, siteRoot, base = '/', unofficia
const pageAnchors = new Map(loaded.map((page) => [page.sourceName, page.anchors]));
const referencedSupportPaths = collectReferencedSupportPaths(loaded);
assertReferencedSupportPathsAllowed(referencedSupportPaths);
const sidebar = sidebarFromToc(toc, pagesBySource, ordered);
const supportFiles = await copySupportFiles(
absoluteSourceRoot,
absoluteSiteRoot,
pageSources,
snapshots,
referencedSupportPaths,
);
const apiReferences = await prepareApiReferences({
sourceRoot: absoluteSourceRoot,
siteRoot: absoluteSiteRoot,
base: normalizedBase,
unofficial,
snapshots,
reservedPaths: supportFiles,
});
for (const reference of apiReferences.references) {
const page = pagesBySource.get(reference.page);
if (!page) throw new Error(`api-references.yml: page is not in the source navigation: ${reference.page}`);
reference.title = page.title;
reference.route = page.route;
}
const sidebar = apiReferenceSidebar(sidebarFromToc(toc, pagesBySource, ordered), apiReferences.references, pagesBySource);

await pruneFormerGeneratedPages(absoluteSiteRoot, loaded);

for (const page of loaded) {
const output = transformBody({
let output = transformBody({
page,
pageRoutes,
pageAnchors,
Expand All @@ -1030,19 +1053,18 @@ export async function generateSite({ sourceRoot, siteRoot, base = '/', unofficia
authors,
unofficial,
});
const reference = apiReferences.references.find((item) => item.page === page.sourceName);
if (reference) {
output = generatedFrontmatter({ title: page.title, description: page.frontmatter.description, apiReference: true }, unofficial)
+ page.headings.map((heading) => `<a id="${htmlEscape(heading.id)}"></a>`).join('\n')
+ '\n' + apiReferenceMarkup(reference);
}
const relative = page.route ? `${page.route}.md` : 'index.md';
const destination = path.join(absoluteSiteRoot, 'src/content/docs', relative);
await mkdir(path.dirname(destination), { recursive: true });
await writeFile(destination, output);
}

const supportFiles = await copySupportFiles(
absoluteSourceRoot,
absoluteSiteRoot,
pageSources,
snapshots,
referencedSupportPaths,
);
const supportIndexes = await writeSupportDirectoryIndexes(
absoluteSourceRoot,
absoluteSiteRoot,
Expand All @@ -1063,7 +1085,8 @@ export async function generateSite({ sourceRoot, siteRoot, base = '/', unofficia
sourceDigest: sourceDigest(snapshots),
requirementCount,
sidebar,
supportFiles,
supportFiles: [...supportFiles, ...apiReferences.supportFiles],
apiReferences: apiReferences.references,
supportIndexes,
redirects,
warnings: [...new Set(warnings)],
Expand Down
2 changes: 2 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default defineConfig({
ThemeProvider: './src/components/GuideThemeProvider.astro',
Banner: './src/components/PublicationBanner.astro',
Footer: './src/components/PublicationFooter.astro',
MarkdownContent: './src/components/ReferenceContent.astro',
PageTitle: './src/components/ReferenceTitle.astro',
},
head: [
{ tag: 'meta', attrs: { name: 'robots', content: robotsContent(publication.unofficial) } },
Expand Down
88 changes: 88 additions & 0 deletions docs/building-block-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Building Block site integration

The shared renderer owns Scalar, its pinned dependencies, presentation, and
build checks. Each Building Block owns its Markdown, OpenAPI contracts, and
root `api-references.yml`. Existing GitBook publications are separate consumers;
adding this file does not modify their renderer or migrate their source layout.

## Local setup

Use Node 24.11 or later. Install this renderer with `npm ci --ignore-scripts`.
For a framework-format Building Block, run:

```sh
npm run check -- --profile framework --source /absolute/path/to/building-block --base /building-block/ --unofficial --output /absolute/path/to/preview
```

The source needs root `metadata.yml`, `authors.yml`, `toc.yml`, and Markdown.
The template's `specification-site/` wrapper supplies the same commands from a
Building Block repository, using an absolute `GOVSTACK_SITE_RENDERER` checkout.
It deliberately rejects an older renderer when API references are configured.

[`examples/building-block`](../examples/building-block/) is a runnable,
illustrative source fixture. It has no Digital Registries dependency:

```sh
npm run check -- --profile framework --source examples/building-block --base /building-block/ --unofficial --output /absolute/path/to/example-preview
```

## Declare API pages

Create a short Markdown page containing its title and list it in `toc.yml`.
Add an entry to root `api-references.yml` with `id`, `page`, `contract`, and
`role`. Set `role: normative` for the draft contract and `role: example` for an
illustrative binding. Keep those on separate pages. Do not add a requirement
just to make a contract visible.

The page opens on operations, with its role and downloads visible and technical
metadata collapsed. The full source contract remains available to download.
Local `$ref` dependencies are bundled; remote and escaping references fail the
build. Do not copy bundled JSON or Scalar assets into the source repository.

OpenAPI references are optional. AsyncAPI and protocol-standard surfaces keep
their existing documentation; this renderer does not convert them to OpenAPI.

## CI

After publishing a renderer revision containing `action.yml` and native Scalar,
check it out at an immutable full commit and use the local composite action:

```yaml
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: specification
persist-credentials: false
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: jeremi/govstack-specification-site
ref: ${{ vars.GOVSTACK_SITE_RENDERER_REF }}
path: renderer
persist-credentials: false
- uses: ./renderer
with:
source: specification
output: ${{ runner.temp }}/site
base: /building-block/
unofficial: 'true'
```

Set `GOVSTACK_SITE_RENDERER_REF` to the published full commit. Validate that it
is a 40-character hexadecimal commit before checkout, and reject a renderer
without `action.yml`, `scripts/api-references.mjs`, and
`src/components/ReferenceContent.astro`. Digital Registries' preview workflow
includes those checks. A repository or organisation variable lets consumers
share a deliberately selected revision; it must not contain a branch name.

The action installs Node and renderer dependencies, runs tests, checks Astro,
builds, checks output, and tests an isolated HTTP preview. It has no deployment
step or Pages permissions. An existing publication workflow can upload its
checked output and retain its own approval and deployment policy.

## Activation status

Local integration and hosted activation are distinct. Changing source config
does not upgrade a previously pinned renderer. Publish the reviewed renderer
change first, set the consumer's immutable revision, then run its site check.
Only after that succeeds should its existing publication process deploy it.
The template remains `noApi: true`; its config example stays inactive until an
adopting Building Block supplies its own contracts and framework source.
5 changes: 5 additions & 0 deletions examples/building-block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Example Building Block

This small fixture demonstrates a framework-format site with a native
[illustrative API reference](resources/api-example.md). It is not a Building
Block specification or a conformance target.
5 changes: 5 additions & 0 deletions examples/building-block/api-references.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
references:
- id: entries
page: resources/api-example.md
contract: api/openapi.yaml
role: example
10 changes: 10 additions & 0 deletions examples/building-block/api/entry.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"additionalProperties": false,
"required": ["entryId", "label"],
"properties": {
"entryId": { "type": "string" },
"label": { "type": "string" }
}
}
Loading
Loading