Skip to content
Open
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
5 changes: 3 additions & 2 deletions .github/workflows/spdx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ jobs:
- uses: ai-openshell/workflows/spdx-check@0b051efd25c3f7319634fed863d2e03e1bd55d7b # main
with:
include: "*"
# LICENSE is the license text; the CNCF logos are third-party artwork.
exclude: "LICENSE site/static/cncf/*"
# LICENSE is the license text; the CNCF, GitHub, and Slack logos are
# third-party artwork.
exclude: "LICENSE site/static/cncf/* www/icons/*"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ site/src/content/docs/
site/src/generated/
site/public/
site/src/styles/tokens.css
site/src/styles/site-bar.css
54 changes: 49 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ docs of several repositories. Each repository keeps its docs next to its code
and ships them with its releases. This repository holds no page content: it
owns the build, the theme, and the navigation.

| Docset | Repository | Path | Versions |
| --------- | ------------------------------------------------------------------- | ----------- | --------------------------------- |
| OpenShell | [ai-openshell/openshell](https://github.com/ai-openshell/openshell) | `docs/` | dev (`main`), 0.1.9, 0.1.8, 0.1.7 |
| Go SDK | [ai-openshell/sdk-go](https://github.com/ai-openshell/sdk-go) | `docs/src/` | dev (`main`), 0.1.8, 0.1.7 |
| Docset | Repository | Path | Dev branch |
| --------- | ------------------------------------------------------------------- | ----------- | ---------- |
| OpenShell | [ai-openshell/openshell](https://github.com/ai-openshell/openshell) | `docs/` | `main` |
| Go SDK | [ai-openshell/sdk-go](https://github.com/ai-openshell/sdk-go) | `docs/src/` | `main` |

## How it works

Expand All @@ -21,7 +21,7 @@ branch, reads it in its own format (Fern `index.yml`, mdBook `SUMMARY.md`, or
[Starlight](https://starlight.astro.build/). The newest release of each
repository is published without a version in the URL, such as
`/about/overview/` or `/sdks/go/`, so links always show the current docs. Other
versions have their own path, such as `/0.1.8/about/overview/` or
versions have their own path, such as `/<version>/about/overview/` or
`/sdks/go/dev/`.

Broken links in fetched versions are warnings, so one repository can't block
Expand All @@ -36,6 +36,50 @@ The published website serves a small landing page from [`www/`](www/)
at `/` and the docs at `/docs/`. [`scripts/website.mjs`](scripts/website.mjs)
combines the two after the docs build.

## Website pages

The landing page, [`www/index.html`](www/index.html), is hand-written HTML.
Other pages outside the docs, such as `/community/`, are Markdown files in
`www/` with a `title` and `description` in their front matter.
`scripts/website.mjs` renders each `www/<name>.md` into the landing page's
header and footer at `/<name>/`. To add a page, add a Markdown file and its link
to [`theme/nav.json`](theme/nav.json), which the site bar reads. `:name:` in a
page, such as `:github:`, inserts the icon `www/icons/<name>.svg`. `mise run
website` builds the whole website, and `mise run serve-website` serves it.

Every page, docs included, renders the same site bar from
[`theme/site-bar.mjs`](theme/site-bar.mjs): wordmark, site links, search,
GitHub, and theme toggle, with one stylesheet (`theme/site-bar.css`) and
script (`theme/search.js`). Search uses the docs build's
[Pagefind](https://pagefind.app/) index, and `scripts/website.mjs` indexes the
website pages into `/pagefind-www/`; on the full website (`WEBSITE=1`, as
Netlify and `mise run website` set it) search merges the two. A docs-only
build searches the docs only.

## Markdown for agents

Every page has a Markdown copy at its URL plus `.md`, such as
`/docs/about/overview.md` or `/community.md`. The docs list theirs in
`/docs/llms.txt`, and each docs page links to its copy in the page actions menu
(Copy page, View as Markdown, Open in Claude or ChatGPT).

The assembler writes the docs copies from each page's source, so they keep
the source's text rather than the rendered HTML. Source repositories can mark
content for one output only: `<llms-only>` blocks appear only in the Markdown
copy, and `<llms-ignore>` blocks only on the site.

## Hosting

The website is hosted on [Netlify](https://www.netlify.com/) under the CNCF's
account. [`netlify.toml`](netlify.toml) holds the build settings, which
override the Netlify UI: Netlify runs `npm run build && npm run website` with
`BASE_PATH=/docs/` and publishes `build/website`. Netlify also builds a deploy
preview for each pull request.

The [Site workflow](.github/workflows/site.yml) also builds the docs on every
pull request and publishes them to GitHub Pages from `main`, at
`/<repository>/` and without the landing page.

## Run it locally

```shell
Expand Down
6 changes: 4 additions & 2 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ run = "npm run site"

[tasks.website]
description = "Build the site, then add the landing page at / with the docs at /docs/"
depends = ["build"]
run = "npm run website"
depends = ["assemble"]
# WEBSITE=1 makes the docs search include the website pages, as on Netlify.
env = { BASE_PATH = "/docs/", WEBSITE = "1" }
run = ["npm run site", "npm run website"]

[tasks.serve-website]
description = "Serve the website at http://127.0.0.1:4410/"
Expand Down
2 changes: 2 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ publish = "build/website"

[build.environment]
BASE_PATH = "/docs/"
# Docs search also covers the website pages (pagefind-www, see scripts/website.mjs).
WEBSITE = "1"
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
"@astrojs/starlight": "0.42.10",
"astro": "7.4.11",
"github-slugger": "2.0.0",
"pagefind": "1.6.0",
"pele": "1.13.0",
"rehype-stringify": "10.0.1",
"remark-frontmatter": "5.0.0",
"remark-gfm": "4.0.1",
"remark-mdx": "3.1.1",
"remark-parse": "11.0.0",
"remark-rehype": "11.1.2",
"remark-stringify": "11.0.0",
"unified": "11.0.5",
"unist-util-visit": "5.2.0",
Expand Down
93 changes: 88 additions & 5 deletions scripts/website.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#!/usr/bin/env node
// SPDX-License-Identifier: Apache-2.0
// Assemble the website: the files in www/ (the landing page) at / and the
// docs build at /docs/.
// Assemble the website: the files in www/ at / and the docs build at /docs/.
// www/index.html is the landing page. Each other www/<name>.md is rendered
// into the landing page's shell (header, footer, scripts) at /<name>/, with
// its Markdown copy at /<name>.md, like the docs pages.
// The docs build must use BASE_PATH=/docs/ so its links resolve under /docs/.
// Usage: node scripts/website.mjs site/dist build/website
import fs from 'node:fs';
import path from 'node:path';
import * as pagefind from 'pagefind';
import rehypeStringify from 'rehype-stringify';
import remarkGfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import { unified } from 'unified';
import YAML from 'yaml';
import { siteBar } from '../theme/site-bar.mjs';

const MOUNT = 'docs';
const [docs = 'site/dist', out = 'build/website'] = process.argv.slice(2).map((p) => path.resolve(p));
const repo = path.resolve(import.meta.dirname, '..');
const www = path.join(repo, 'www');

const { base } = JSON.parse(fs.readFileSync(path.join(docs, 'versions.json'), 'utf8'));
if (base !== `/${MOUNT}/`) {
Expand All @@ -18,12 +29,84 @@ if (base !== `/${MOUNT}/`) {
}

fs.rmSync(out, { recursive: true, force: true });
fs.cpSync(path.join(repo, 'www'), out, { recursive: true });
fs.copyFileSync(path.join(repo, 'theme/tokens.css'), path.join(out, 'tokens.css'));
fs.cpSync(www, out, {
recursive: true,
filter: (f) => path.extname(f) !== '.md' && !f.startsWith(path.join(www, 'icons')),
});
for (const f of ['tokens.css', 'site-bar.css', 'search.js', 'theme-toggle.js'])
fs.copyFileSync(path.join(repo, 'theme', f), path.join(out, f));
for (const f of ['favicon.svg', 'apple-touch-icon.png', 'cncf'])
fs.cpSync(path.join(repo, 'site/static', f), path.join(out, f), { recursive: true });
fs.cpSync(docs, path.join(out, MOUNT), { recursive: true });
// Hosts serve /404.html for any missing path. The docs one links its assets
// absolutely (/docs/_astro/...), so it works at the root too.
fs.copyFileSync(path.join(docs, '404.html'), path.join(out, '404.html'));
console.log(`website -> ${path.relative(process.cwd(), out)} (landing at /, docs at /${MOUNT}/)`);

const htmlEscape = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
const swap = (html, re, to, what) => {
if (!re.test(html)) throw new Error(`www/index.html has no ${what}`);
return html.replace(re, () => to);
};

// The site bar (theme/site-bar.mjs), the same one the docs header renders.
// Search covers the docs index and the website pages' index written below.
const withNav = (html, current) =>
swap(
html,
/<!-- site-bar -->/,
siteBar({ current, search: { bundlePath: `/${MOUNT}/pagefind/`, baseUrl: `/${MOUNT}/`, merge: '/pagefind-www/' } }),
'<!-- site-bar --> placeholder',
);

// The landing page.
const shell = fs.readFileSync(path.join(www, 'index.html'), 'utf8');
fs.writeFileSync(path.join(out, 'index.html'), withNav(shell, '/'));

// Markdown pages.
const render = unified().use(remarkParse).use(remarkGfm).use(remarkRehype).use(rehypeStringify);
// Icon shortcodes: :name: in a www/*.md page becomes www/icons/<name>.svg in
// the HTML, and is dropped from the Markdown copy.
const ICON = /:([a-z][a-z0-9-]*):/g;
const icon = (name) => {
const f = path.join(www, 'icons', `${name}.svg`);
if (!fs.existsSync(f)) throw new Error(`no icon www/icons/${name}.svg for :${name}:`);
return fs
.readFileSync(f, 'utf8')
.replace(/<!--[\s\S]*?-->\s*/g, '')
.trim();
};
const pages = fs.readdirSync(www).filter((f) => f.endsWith('.md'));
const rendered = [];
for (const file of pages) {
const name = path.basename(file, '.md');
const src = fs.readFileSync(path.join(www, file), 'utf8');
const m = src.match(/^---\n([\s\S]*?)\n---\n/);
const meta = m ? YAML.parse(m[1]) : {};
if (!meta?.title || !meta.description)
throw new Error(`www/${file} needs a title and description in its front matter`);
const body = src.slice(m[0].length).trim();
const main = `<main class="page" data-pagefind-body data-pagefind-meta="section:${htmlEscape(meta.title)}">\n<h1>${htmlEscape(meta.title)}</h1>\n${String(render.processSync(body)).replace(ICON, (_, n) => icon(n))}\n</main>`;
let html = swap(shell, /<title>[^<]*<\/title>/, `<title>${htmlEscape(meta.title)} · OpenShell</title>`, '<title>');
html = swap(
html,
/<meta name="description" content="[^"]*" \/>/,
`<meta name="description" content="${htmlEscape(meta.description)}" />`,
'description meta tag',
);
html = withNav(swap(html, /<main>[\s\S]*<\/main>/, main, '<main>'), `/${name}/`);
fs.mkdirSync(path.join(out, name), { recursive: true });
fs.writeFileSync(path.join(out, name, 'index.html'), html);
rendered.push([`/${name}/`, html]);
fs.writeFileSync(path.join(out, `${name}.md`), `# ${meta.title}\n\n${body.replace(/:[a-z][a-z0-9-]*: /g, '')}\n`);
}

// Search: index the Markdown pages into /pagefind-www/, which the docs search
// merges with its own index (pagefind.mergeIndex in site/astro.config.mjs).
const { index } = await pagefind.createIndex();
for (const [url, content] of rendered) await index.addHTMLFile({ url, content });
await index.writeFiles({ outputPath: path.join(out, 'pagefind-www') });
await pagefind.close();

console.log(
`website -> ${path.relative(process.cwd(), out)} (landing at /, ${pages.length} Markdown pages, docs at /${MOUNT}/)`,
);
15 changes: 13 additions & 2 deletions site/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import starlight from '@astrojs/starlight';
import { defineConfig } from 'astro/config';
import siteNav from '../theme/nav.json' with { type: 'json' };

// BASE_PATH is the path the site is served under (GitHub Pages: /<repo>/).
export default defineConfig({
Expand All @@ -15,9 +16,16 @@ export default defineConfig({
title: 'OpenShell',
description: 'The safe, private runtime for autonomous AI agents.',
favicon: '/favicon.svg',
social: [{ icon: 'github', label: 'GitHub', href: 'https://github.com/ai-openshell/docs' }],
customCss: ['./src/styles/tokens.css', './src/styles/theme.css'],
social: [{ icon: 'github', label: 'GitHub', href: siteNav.github }],
customCss: ['./src/styles/tokens.css', './src/styles/site-bar.css', './src/styles/theme.css'],
head: [
// Mark the stored theme choice before paint so the header's theme toggle
// (theme/site-bar.mjs) shows the right icon; Starlight sets data-theme.
{
tag: 'script',
content:
"try{const t=localStorage.getItem('starlight-theme');document.documentElement.dataset.themeChoice=t==='light'||t==='dark'?t:'auto'}catch{}",
},
{
tag: 'link',
attrs: { rel: 'apple-touch-icon', href: `${process.env.BASE_PATH ?? '/'}apple-touch-icon.png` },
Expand Down Expand Up @@ -60,6 +68,9 @@ export default defineConfig({
// Sidebar, pagination, topic tabs and the version picker all follow the
// version context of the current page; see src/versioning.ts.
routeMiddleware: './src/routeData.ts',
// Starlight builds the Pagefind index; the site bar's search
// (theme/search.js) shows it instead of Starlight's search box.
pagefind: true,
}),
],
});
5 changes: 3 additions & 2 deletions site/scripts/sync.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// build/assembled/content -> site/src/content/docs (MDX pages get one import line for the components)
// build/assembled/{nav,pages}.json -> site/src/generated/ (read by src/versioning.ts)
// site/static + build/assembled/public -> site/public (assets, <slug>.md, llms.txt, versions.json)
// theme/tokens.css -> site/src/styles/tokens.css
// theme/tokens.css, theme/site-bar.css -> site/src/styles/
// Per page it also sets:
// slug explicit, so version segments like "0.1.8" keep their dots
// banner on dev and older versions, linking to the same page in the latest release
Expand Down Expand Up @@ -99,6 +99,7 @@ fs.rmSync(pub, { recursive: true, force: true });
fs.cpSync(path.join(site, 'static'), pub, { recursive: true, filter: (src) => !src.endsWith('.license') });
fs.cpSync(path.join(assembled, 'public'), pub, { recursive: true });

fs.copyFileSync(path.join(themeDir, 'tokens.css'), path.join(site, 'src/styles/tokens.css'));
for (const f of ['tokens.css', 'site-bar.css'])
fs.copyFileSync(path.join(themeDir, f), path.join(site, 'src/styles', f));
for (const f of failed) console.warn(`warning: diagram left as code: ${f}`);
console.log(`synced ${pages.length} pages, ${diagrams} diagrams and ${names.length} components (base ${nav.base})`);
2 changes: 1 addition & 1 deletion site/src/components/VersionPicker.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const isLatest = picker?.options.some((o) => o.current && o.latest);

{picker && (
<div class="os-version-field">
<span class="os-version-field__label" id="os-version-label">Version</span>
<span class="os-version-field__label" id="os-version-label">{picker.title} version</span>
<details class="os-version" aria-labelledby="os-version-label">
<summary>
<span class="os-version__selected">
Expand Down
Loading
Loading