diff --git a/.github/workflows/spdx.yml b/.github/workflows/spdx.yml index 892bf46..3518b99 100644 --- a/.github/workflows/spdx.yml +++ b/.github/workflows/spdx.yml @@ -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/* website/icons/*" diff --git a/.gitignore b/.gitignore index 9647aa3..44d654c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ site/src/content/docs/ site/src/generated/ site/public/ site/src/styles/tokens.css +site/src/styles/site-bar.css diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 309c2b6..aae7a8f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,9 +2,9 @@ # Contributing to the OpenShell docs site -This repository holds the site build, theme, and navigation. Page content lives -in each source repository; change it there. See the [README](README.md) for -how the build works. +This repository holds the site build, theme, and navigation, and the pages +outside the docs. Docs content lives in each source repository; change it +there. See the [README](README.md) for an overview. ## Setup @@ -16,22 +16,100 @@ mise install mise run install ``` -| Task | What it does | -| ------------------- | -------------------------------------------------------- | -| `mise run build` | Fetch every source and build the site into `site/dist` | -| `mise run serve` | Serve the built site at | -| `mise run website` | Build the site and add the landing page into `build/website` | -| `mise run serve-website` | Serve the website at | -| `mise run assemble` | Fetch and assemble the sources without building the site | -| `mise run test` | Run the assembler's unit tests | -| `mise run lint` | Check formatting and lint with [Biome](https://biomejs.dev/) | -| `mise run format` | Format the code and apply safe lint fixes | -| `mise run typecheck` | Assemble the sources and type-check the site with `astro check` | - -To build against a local checkout instead of a source's `dev` branch, run -`node assembler/assemble.mjs --base /docs/ --local core=../OpenShell` before -`BASE_PATH=/docs/ npm run site`. Broken links in a local checkout fail the -build; in fetched versions they only warn. +| Task | What it does | +| ------------------------ | ------------------------------------------------------------------ | +| `mise run website` | Build the docs and the website pages into `build/website` | +| `mise run serve-website` | Serve the website at | +| `mise run build` | Fetch every source and build only the docs into `site/dist` | +| `mise run serve` | Serve the docs build at | +| `mise run assemble` | Fetch and assemble the sources without building the site | +| `mise run test` | Run the assembler's unit tests | +| `mise run lint` | Check formatting and lint with [Biome](https://biomejs.dev/) | +| `mise run format` | Format the code and apply safe lint fixes | +| `mise run typecheck` | Assemble the sources and type-check the site with `astro check` | + +## How the docs build works + +[`sources.yml`](sources.yml) lists each source repository, where it's mounted, +and which tags to publish; `dev` is a branch built as an extra, unreleased +version. The assembler ([`assembler/`](assembler/)) fetches only the docs +directory at each ref, reads it in its own format (Fern `index.yml`, mdBook +`SUMMARY.md`, or `docset.yml`), and writes the Starlight content, navigation, +and Markdown copies. The commits it used are recorded in +`build/assembled/sources.lock.json`. + +Broken links in fetched versions are warnings, so one repository can't block +the site. To check a change to a repository's docs, build against a local +checkout, where broken links are errors: + +```shell +node assembler/assemble.mjs --base /docs/ --local core=../OpenShell +BASE_PATH=/docs/ npm run site +``` + +Pull request previews for source repositories are tracked in +[#2](https://github.com/ai-openshell/docs/issues/2). + +## Website pages + +[`website/`](website/) holds the website's own pages, the ones outside the docs; +the docs come from the sources and are built in `site/`. +[`scripts/website.mjs`](scripts/website.mjs) puts the files in `website/` at `/` +and the docs build at `/docs/`, into `build/website/`. The landing page, +[`website/index.html`](website/index.html), is hand-written HTML. Other pages, +such as `/community/`, are Markdown files in `website/` with a `title` and +`description` in their front matter; each `website/.md` is rendered into +the landing page's shell at `//`. + +To add a page, add a Markdown file and its link to +[`theme/nav.json`](theme/nav.json). `:name:` in a page, such as `:github:`, +inserts the icon `website/icons/.svg`. + +## Site bar and search + +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. The docs header +([`Header.astro`](site/src/components/overrides/Header.astro)) and +`scripts/website.mjs` both call it, and both use the same styles +(`theme/site-bar.css`) and scripts (`theme/search.js`, +`theme/theme-toggle.js`), so change the bar only in `theme/`. + +Search shows [Pagefind](https://pagefind.app/)'s UI in the site bar's dialog; +Starlight's own search box isn't used. Starlight builds the docs index (the +latest release of each docset only), and `scripts/website.mjs` indexes the +website pages into `/pagefind-website/`. When built with `WEBSITE=1`, as Netlify +and `mise run website` do, search merges the two, with the website pages at +half weight so they don't outrank the docs. Each page records its section +(Core, Go SDK, Community) as Pagefind metadata, which the results show as a +label. + +## 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). On Netlify, an +[edge function](netlify/edge-functions/markdown.js) serves the copy at the +page's own URL to clients that send `Accept: text/markdown`; +`mise run serve-website` does the same locally. + +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: `` blocks appear only in the Markdown +copy, and `` 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 `WEBSITE=1`, and publishes `build/website`. Netlify also +builds a deploy preview for each pull request. + +The [Site workflow](.github/workflows/site.yml) builds the docs on every pull +request and publishes them to GitHub Pages from `main`, at `//` +and without the website pages. ## Commits and pull requests @@ -44,4 +122,5 @@ build; in fetched versions they only warn. a comment in its first 10 lines; the `SPDX` workflow checks it. In `.mdx` and `.astro` files, put it in the front matter. A file that can't hold a comment, such as JSON or an image, gets a `.license` file containing - the line instead. + the line instead. Third-party artwork, such as the CNCF logos and + `website/icons/`, is excluded. diff --git a/README.md b/README.md index 02d0c17..76a7d3a 100644 --- a/README.md +++ b/README.md @@ -2,55 +2,45 @@ # OpenShell docs -Builds the [OpenShell](https://github.com/ai-openshell/openshell) docs site from the -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. +Builds the [OpenShell](https://github.com/ai-openshell/openshell) website and +docs from the docs of several repositories. Each repository keeps its docs next +to its code and ships them with its releases. This repository holds no docs +content: it owns the build, the theme, the navigation, and the few pages outside +the docs, such as the landing page, in [`website/`](website/). -| 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 [`sources.yml`](sources.yml) lists each repository, where it's mounted, and which tags to publish. The build fetches only the docs directory at each tag or -branch, reads it in its own format (Fern `index.yml`, mdBook `SUMMARY.md`, or -`docset.yml`), checks every link, and builds the site with +branch, checks every link, and builds the docs with [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 -`/sdks/go/dev/`. +`/docs/about/overview/`; other versions have their own path, such as +`/docs/0.1.8/about/overview/` or `/docs/sdks/go/dev/`. -Every page also has a Markdown copy at its path plus `.md`, listed in -`/llms.txt`. On Netlify, an [edge function](netlify/edge-functions/markdown.js) -serves that copy at the page's own URL to clients that send -`Accept: text/markdown`. - -Broken links in fetched versions are warnings, so one repository can't block -the site. To check a change to a repository's docs, build with `--local` (see -[CONTRIBUTING.md](CONTRIBUTING.md)), where broken links are errors. Pull request -previews for source repositories are tracked in -[#2](https://github.com/ai-openshell/docs/issues/2). +The website serves the landing page and the community page at `/` and the docs +at `/docs/`, all with one site bar and one search. Every page also has a +Markdown copy for agents at its URL plus `.md`. The site is hosted on Netlify +under the CNCF's account. To publish a new release, add its tag to `sources.yml`. -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. - ## Run it locally ```shell mise install mise run install -mise run build -mise run serve +mise run website +mise run serve-website ``` -See [CONTRIBUTING.md](CONTRIBUTING.md) for more. +See [CONTRIBUTING.md](CONTRIBUTING.md) for the build details, the other tasks, +and how to change the site. ## License diff --git a/mise.toml b/mise.toml index 0551e4a..66de1da 100644 --- a/mise.toml +++ b/mise.toml @@ -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/" diff --git a/netlify.toml b/netlify.toml index fb4ba89..31879f9 100644 --- a/netlify.toml +++ b/netlify.toml @@ -12,6 +12,8 @@ publish = "build/website" [build.environment] BASE_PATH = "/docs/" +# Docs search also covers the website pages (pagefind-website, see scripts/website.mjs). +WEBSITE = "1" # A page's URL serves HTML or Markdown depending on Accept (see # netlify/edge-functions/markdown.js), so tell caches to key on it. The edge diff --git a/package-lock.json b/package-lock.json index 599f807..1ecd91f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,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", @@ -5940,6 +5943,21 @@ "expressive-code": "^0.44.3" } }, + "node_modules/rehype-stringify": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/rehype-stringify/-/rehype-stringify-10.0.1.tgz", + "integrity": "sha512-k9ecfXHmIPuFVI61B9DeLPN0qFHfawM6RsuX48hoqlaKSF61RskNjSm1lI8PhBEM0MRdLxVVm4WmTqJQccH9mA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "hast-util-to-html": "^9.0.0", + "unified": "^11.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/remark-directive": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/remark-directive/-/remark-directive-4.0.0.tgz", @@ -6020,6 +6038,23 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/remark-rehype": { + "version": "11.1.2", + "resolved": "https://registry.npmjs.org/remark-rehype/-/remark-rehype-11.1.2.tgz", + "integrity": "sha512-Dh7l57ianaEoIpzbp0PC9UKAdCSVklD8E5Rpw7ETfbTl3FqcOOgq5q2LVDhgGCkaBv7p24JXikPdvhhmHvKMsw==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "mdast-util-to-hast": "^13.0.0", + "unified": "^11.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/remark-stringify": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/remark-stringify/-/remark-stringify-11.0.0.tgz", diff --git a/package.json b/package.json index fb74659..c10f0ce 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/website.mjs b/scripts/website.mjs index 2e45dbb..3c5584a 100644 --- a/scripts/website.mjs +++ b/scripts/website.mjs @@ -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 website/ at / and the docs build at /docs/. +// website/index.html is the landing page. Each other website/.md is rendered +// into the landing page's shell (header, footer, scripts) at //, with +// its Markdown copy at /.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 pagesDir = path.join(repo, 'website'); const { base } = JSON.parse(fs.readFileSync(path.join(docs, 'versions.json'), 'utf8')); if (base !== `/${MOUNT}/`) { @@ -18,12 +29,93 @@ 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(pagesDir, out, { + recursive: true, + filter: (f) => path.extname(f) !== '.md' && !f.startsWith(path.join(pagesDir, '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, '&').replace(//g, '>').replace(/"/g, '"'); +const swap = (html, re, to, what) => { + if (!re.test(html)) throw new Error(`website/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, + //, + siteBar({ + current, + search: { bundlePath: `/${MOUNT}/pagefind/`, baseUrl: `/${MOUNT}/`, merge: '/pagefind-website/' }, + }), + ' placeholder', + ); + +// The landing page. +const shell = fs.readFileSync(path.join(pagesDir, '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 website/*.md page becomes website/icons/.svg in +// the HTML, and is dropped from the Markdown copy. +const ICON = /:([a-z][a-z0-9-]*):/g; +// Links to other sites, such as GitHub and Slack, open in a new tab. +const EXTERNAL = /( { + const f = path.join(pagesDir, 'icons', `${name}.svg`); + if (!fs.existsSync(f)) throw new Error(`no icon website/icons/${name}.svg for :${name}:`); + return fs + .readFileSync(f, 'utf8') + .replace(/\s*/g, '') + .trim(); +}; +const pages = fs.readdirSync(pagesDir).filter((f) => f.endsWith('.md')); +const rendered = []; +for (const file of pages) { + const name = path.basename(file, '.md'); + const src = fs.readFileSync(path.join(pagesDir, 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(`website/${file} needs a title and description in its front matter`); + const body = src.slice(m[0].length).trim(); + const main = `
\n

${htmlEscape(meta.title)}

\n${String( + render.processSync(body), + ) + .replace(ICON, (_, n) => icon(n)) + .replace(EXTERNAL, '$1 target="_blank" rel="noopener"')}\n
`; + let html = swap(shell, /[^<]*<\/title>/, `<title>${htmlEscape(meta.title)} · OpenShell`, ''); + 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-website/, 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-website') }); +await pagefind.close(); + +console.log( + `website -> ${path.relative(process.cwd(), out)} (landing at /, ${pages.length} Markdown pages, docs at /${MOUNT}/)`, +); diff --git a/site/astro.config.mjs b/site/astro.config.mjs index 233cabb..841f53e 100644 --- a/site/astro.config.mjs +++ b/site/astro.config.mjs @@ -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({ @@ -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` }, @@ -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, }), ], }); diff --git a/site/scripts/sync.mjs b/site/scripts/sync.mjs index 7c83af6..20ee4d6 100644 --- a/site/scripts/sync.mjs +++ b/site/scripts/sync.mjs @@ -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 @@ -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})`); diff --git a/site/src/components/VersionPicker.astro b/site/src/components/VersionPicker.astro index 0fd24c9..c6bc842 100644 --- a/site/src/components/VersionPicker.astro +++ b/site/src/components/VersionPicker.astro @@ -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"> diff --git a/site/src/components/overrides/Header.astro b/site/src/components/overrides/Header.astro index 79fefe4..3d5a9a7 100644 --- a/site/src/components/overrides/Header.astro +++ b/site/src/components/overrides/Header.astro @@ -1,12 +1,24 @@ --- // SPDX-License-Identifier: Apache-2.0 -// Header: wordmark / search / theme, then topic tabs, then (in topics with an -// overview page) sub-tabs for the overview and each docset. +// Header: the site bar, then topic tabs, then (in topics with an overview page) +// sub-tabs for the overview and each docset. The site bar (wordmark, site +// links, search, GitHub, theme) is theme/site-bar.mjs, shared with the website +// pages, so it is the same markup, styles, and scripts everywhere. // Tab and sub-tab links come from src/routeData.ts and follow the current // page's version context. -import Search from '@astrojs/starlight/components/Search.astro'; -import SocialIcons from '@astrojs/starlight/components/SocialIcons.astro'; -import ThemeSelect from '@astrojs/starlight/components/ThemeSelect.astro'; +import { siteBar } from '../../../../theme/site-bar.mjs'; + +const base = import.meta.env.BASE_URL; +// Search this build's Pagefind index; on the full website (WEBSITE=1), merge in +// the website pages' index too. +const bar = siteBar({ + current: base, + search: { + bundlePath: `${base}pagefind/`, + baseUrl: base, + merge: process.env.WEBSITE ? '/pagefind-website/' : undefined, + }, +}); const os = Astro.locals.osVersion; const topics = os?.topics ?? []; @@ -24,18 +36,7 @@ const subtabs = ds --- <div class="os-header"> - <div class="os-header__row"> - <a href={import.meta.env.BASE_URL} class="os-wordmark" translate="no"> - <!-- The OpenShell shield (ai-openshell/openshell docs/brand/assets/openshell-mark.svg), cropped to the shield --> - <svg viewBox="14 7 72 87" aria-hidden="true" class="os-wordmark__mark"><path d="M50 9 L84 23 V51 C84 72 69 86 50 92 C31 86 16 72 16 51 V23 Z" fill="#76B900"/><g fill="none" stroke="#FFFFFF" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><path d="M37 41 L49 50 L37 59"/><path d="M55 59 H67"/></g></svg> - <span>OpenShell</span> - </a> - <div class="os-header__search print:hidden"><Search /></div> - <div class="os-header__end print:hidden"> - <div class="sl-hidden md:sl-flex os-header__social"><SocialIcons /></div> - <div class="sl-hidden md:sl-flex"><ThemeSelect /></div> - </div> - </div> + <Fragment set:html={bar} /> <nav class="os-tabs print:hidden" aria-label="Topics"> {topics.map((t) => ( <a href={t.href} class="os-tab" aria-current={t.isCurrent ? 'true' : undefined}>{t.label}</a> @@ -67,6 +68,9 @@ const subtabs = ds </div> <script> + import '../../../../theme/search.js'; + import '../../../../theme/theme-toggle.js'; + document.addEventListener('click', (e) => { for (const d of document.querySelectorAll<HTMLDetailsElement>('details.os-subtabs__menu[open]')) if (!d.contains(e.target as Node)) d.open = false; diff --git a/site/src/components/overrides/PageTitle.astro b/site/src/components/overrides/PageTitle.astro index af3dd8b..6d5e2c0 100644 --- a/site/src/components/overrides/PageTitle.astro +++ b/site/src/components/overrides/PageTitle.astro @@ -5,8 +5,13 @@ import Default from '@astrojs/starlight/components/PageTitle.astro'; import PageActions from '../PageActions.astro'; const { description } = Astro.locals.starlightRoute.entry.data; +// Where the page sits, for search results: the docset in a topic with several +// (Go SDK), else the topic (Core, SDKs). +const ds = Astro.locals.osVersion?.docsets; +const section = ds && ((ds.topic.landing && ds.items.find((d) => d.current)?.title) || ds.topic.label); --- +{section && <span hidden data-pagefind-meta={`section:${section}`} />} <div class="os-title"> <Default /> <PageActions /> diff --git a/site/src/styles/theme.css b/site/src/styles/theme.css index 8a53b45..00b0fd1 100644 --- a/site/src/styles/theme.css +++ b/site/src/styles/theme.css @@ -86,37 +86,23 @@ body { flex-direction: column; height: 100%; } -.os-header__row { - display: flex; - align-items: center; - gap: 1rem; - height: var(--os-header-h); - padding-inline: var(--sl-nav-pad-x); -} -[data-has-sidebar] .os-header__row { - padding-inline-end: calc(var(--sl-nav-pad-x) + var(--sl-menu-button-size) + 0.5rem); +/* The site bar itself (wordmark, links, search, GitHub, theme) is shared with + the website pages: theme/site-bar.css. Here it only sits in Starlight's + header, above the topic tabs. */ +.os-header .site-bar { + /* Keep the full bar height so the wordmark sits where it does on the website + pages; the tabs row absorbs Starlight's header border. */ + flex-shrink: 0; } -@media (min-width: 50em) { - [data-has-sidebar] .os-header__row { - padding-inline-end: var(--sl-nav-pad-x); +/* Narrow screens: room for Starlight's menu button, which holds GitHub and the + theme select, so the bar's own are hidden */ +@media (width < 50em) { + [data-has-sidebar] .os-header .site-bar { + padding-inline-end: calc(var(--sl-nav-pad-x) + var(--sl-menu-button-size) + 0.5rem); + } + .os-header .site-bar__end { + display: none; } -} - -.os-wordmark { - display: flex; - align-items: center; - gap: 0.55rem; - color: var(--os-fg); - text-decoration: none; - font-weight: 600; - font-size: 1rem; - letter-spacing: -0.01em; - white-space: nowrap; -} -.os-wordmark__mark { - width: auto; - height: 1.625rem; - flex: none; } /* ---------- version picker (top of the sidebar) ---------- */ @@ -221,56 +207,6 @@ body { color: var(--os-muted); } -.os-header__search { - flex: 1; - display: flex; - justify-content: flex-end; -} -@media (min-width: 50em) { - .os-header__search { - justify-content: center; - } - .os-header__search button[data-open-modal] { - max-width: 24rem; - height: 2.25rem; - border-radius: var(--os-radius); - background: var(--os-surface); - border-color: var(--os-border); - color: var(--os-muted); - } - .os-header__search button[data-open-modal]:hover { - border-color: var(--sl-color-gray-4); - color: var(--os-fg); - } - .os-header__search button[data-open-modal] > kbd { - background: var(--os-bg); - border: 1px solid var(--os-border); - } - .os-header__search button[data-open-modal] > kbd kbd { - background: none; - border: 0; - padding: 0; - } -} -.os-header__end { - display: flex; - align-items: center; - gap: 0.75rem; -} -.os-header__social { - align-items: center; - gap: 0.75rem; -} -.os-header__social a { - color: var(--os-muted); -} -.os-header__social a:hover { - color: var(--os-fg); -} -.os-header__end starlight-theme-select select { - font-size: 0.8125rem; -} - .os-tabs { display: flex; gap: 1.5rem; diff --git a/theme/nav.json b/theme/nav.json new file mode 100644 index 0000000..19f0920 --- /dev/null +++ b/theme/nav.json @@ -0,0 +1,4 @@ +{ + "links": [{ "label": "Docs", "href": "/docs/" }, { "label": "Community", "href": "/community/" }], + "github": "https://github.com/ai-openshell" +} diff --git a/theme/nav.json.license b/theme/nav.json.license new file mode 100644 index 0000000..1abba28 --- /dev/null +++ b/theme/nav.json.license @@ -0,0 +1 @@ +SPDX-License-Identifier: Apache-2.0 diff --git a/theme/search.js b/theme/search.js new file mode 100644 index 0000000..5dd7424 --- /dev/null +++ b/theme/search.js @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: Apache-2.0 +// Search for the site bar (site-bar.mjs), on every page. The dialog's data +// attributes say which Pagefind index to search (data-bundle, data-base-url) +// and, on the full website, which index to merge (data-merge: the website +// pages in /pagefind-website/). The Pagefind UI loads on first open. +const dialog = document.querySelector('.search-dialog'); +const container = dialog?.querySelector('#site-search'); +const kbd = document.querySelector('.search-button__kbd'); +if (kbd && /Mac|iPhone|iPad/.test(navigator.platform)) kbd.textContent = '⌘ K'; + +// Starlight's default ranking, so results rank as they did with its search. +const ranking = { pageLength: 0.1, termFrequency: 0.1, termSaturation: 2, termSimilarity: 9, diacriticSimilarity: 0.8 }; + +let ready; +const load = () => + (ready ??= new Promise((resolve, reject) => { + const { bundle, baseUrl, merge } = dialog.dataset; + const css = document.createElement('link'); + css.rel = 'stylesheet'; + css.href = `${bundle}pagefind-ui.css`; + document.head.append(css); + const js = document.createElement('script'); + js.src = `${bundle}pagefind-ui.js`; + js.onload = () => { + new window.PagefindUI({ + element: '#site-search', + bundlePath: bundle, + baseUrl, + // Website pages count half, so a short page doesn't outrank the docs. + mergeIndex: merge ? [{ bundlePath: merge, baseUrl: '/', indexWeight: 0.5, ranking }] : [], + showSubResults: true, + showImages: false, + ranking, + }); + resolve(); + }; + js.onerror = reject; + document.head.append(js); + })); + +// Pagefind lists extra metadata as "Section: Go SDK" tags; show just the value, +// as a label next to the result title. +if (container) + new MutationObserver(() => { + for (const tag of container.querySelectorAll('.pagefind-ui__result-tag[data-pagefind-ui-meta="section"]')) { + const value = tag.textContent.replace(/^Section:\s*/, ''); + if (tag.textContent !== value) tag.textContent = value; + } + }).observe(container, { childList: true, subtree: true, characterData: true }); + +async function open() { + if (dialog.open) return; + dialog.showModal(); + await load(); + dialog.querySelector('.pagefind-ui__search-input')?.focus(); +} + +if (dialog) { + // Arrow keys move between the search field and the results (pages, their + // sections, and the "Load more" button); Enter opens the focused result. + dialog.addEventListener('keydown', (e) => { + if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return; + const input = dialog.querySelector('.pagefind-ui__search-input'); + const items = [...dialog.querySelectorAll('.pagefind-ui__result-link, .pagefind-ui__button')]; + if (!items.length) return; + const i = items.indexOf(document.activeElement); + const next = e.key === 'ArrowDown' ? items[Math.min(i + 1, items.length - 1)] : i <= 0 ? input : items[i - 1]; + e.preventDefault(); + next.focus(); + next + .closest('.pagefind-ui__result-nested, .pagefind-ui__result-inner, .pagefind-ui__button') + ?.scrollIntoView({ block: 'nearest' }); + }); + for (const b of document.querySelectorAll('[data-search-open]')) b.addEventListener('click', open); + dialog.querySelector('[data-search-close]')?.addEventListener('click', () => dialog.close()); + // A click on the backdrop closes the dialog; Esc closes it natively. + dialog.addEventListener('click', (e) => e.target === dialog && dialog.close()); + addEventListener('keydown', (e) => { + if ((e.metaKey || e.ctrlKey) && e.key === 'k') { + e.preventDefault(); + dialog.open ? dialog.close() : open(); + } + }); +} diff --git a/theme/site-bar.css b/theme/site-bar.css new file mode 100644 index 0000000..2ea980a --- /dev/null +++ b/theme/site-bar.css @@ -0,0 +1,363 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +/* The site bar (site-bar.mjs) and its search dialog (search.js), shared by the + docs and the website pages. Colors and fonts come from tokens.css (--os-*). + The page around the bar only places it: the docs header stacks the topic + tabs below it, and the website pages make it sticky. */ +:root { + --site-text: color-mix(in srgb, var(--os-fg) 88%, var(--os-bg)); +} + +.site-bar { + display: flex; + align-items: center; + gap: 1rem; + height: var(--os-header-h); + padding-inline: 1.25rem; + border-bottom: 1px solid var(--os-border); + font-family: var(--os-font-sans); + line-height: 1.5; +} +@media (min-width: 50rem) { + .site-bar { + padding-inline: 1.5rem; + } +} +@media print { + .site-bar { + display: none; + } +} +.site-bar .sr-only { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; +} + +.site-bar__wordmark { + display: flex; + flex: none; + align-items: center; + gap: 0.55rem; + color: var(--os-fg); + font-size: 1rem; + font-weight: 600; + letter-spacing: -0.01em; + text-decoration: none; + white-space: nowrap; +} +.site-bar__wordmark svg { + width: auto; + height: 1.625rem; +} + +/* Site links, set off from the wordmark by a divider */ +.site-bar__links { + display: flex; + align-items: center; + gap: 0.5rem; + margin-inline-start: 0.75rem; + margin-inline-end: auto; + padding-inline-start: 1rem; + border-inline-start: 1px solid var(--os-border); +} +.site-bar__link { + padding: 0.25rem 0.5rem; + color: var(--os-fg); + font-size: 0.9375rem; + font-weight: 500; + text-decoration: none; + white-space: nowrap; +} +/* Hover only changes the color; the current section is also underlined */ +.site-bar__link:hover, +.site-bar__link[aria-current="page"] { + color: var(--os-accent-text); +} +.site-bar__link[aria-current="page"] { + text-decoration: underline 2px var(--os-accent); + text-underline-offset: 0.45em; +} +@media (width < 50rem) { + .site-bar { + gap: 0.5rem; + } + .site-bar__links { + gap: 0; + margin-inline-start: 0.25rem; + padding-inline-start: 0.5rem; + } + .site-bar__link { + padding-inline: 0.375rem; + } +} + +.site-bar__end { + display: flex; + align-items: center; + gap: 0.25rem; +} +/* GitHub link and theme toggle */ +.icon-button { + display: grid; + place-items: center; + width: 2rem; + height: 2rem; + padding: 0; + border: 0; + border-radius: var(--os-radius); + background: none; + color: var(--os-muted); + cursor: pointer; +} +.icon-button:hover { + color: var(--os-fg); + background: var(--os-surface); +} +.icon-button svg { + width: 1.125rem; + height: 1.125rem; +} +/* theme-toggle.js sets data-theme-choice: auto, light, or dark */ +:root:not([data-theme-choice="light"]) .theme-toggle__light, +:root:not([data-theme-choice="dark"]) .theme-toggle__dark, +:root[data-theme-choice="light"] .theme-toggle__auto, +:root[data-theme-choice="dark"] .theme-toggle__auto { + display: none; +} + +/* ---------- search ---------- */ +.search-button { + display: flex; + flex: none; + align-items: center; + gap: 0.5rem; + width: 16rem; + height: 2.25rem; + padding: 0 0.5rem 0 0.75rem; + border: 1px solid var(--os-border); + border-radius: var(--os-radius); + background: var(--os-surface); + color: var(--os-muted); + font: inherit; + font-size: 0.875rem; + cursor: pointer; +} +.search-button:hover { + color: var(--os-fg); +} +.search-button svg { + width: 1rem; + height: 1rem; + flex: none; +} +.search-button__label { + margin-inline-end: auto; +} +.search-button__kbd { + padding: 0.05rem 0.35rem; + border: 1px solid var(--os-border); + border-radius: 4px; + background: var(--os-bg); + font-family: var(--os-font-sans); + font-size: 0.75rem; +} +.search-dialog { + width: min(100% - 2rem, 45rem); + max-height: calc(100% - 8rem); + margin: 4rem auto auto; + padding: 0; + border: 1px solid var(--os-border); + border-radius: var(--os-radius); + background: var(--os-bg); + color: var(--site-text); + box-shadow: 0 16px 48px rgb(0 0 0 / 0.25); +} +.search-dialog::backdrop { + background: rgb(0 0 0 / 0.45); + backdrop-filter: blur(2px); +} +.search-dialog__frame { + position: relative; + padding: 1rem; +} +/* The close button sits at the end of the search field's row */ +.search-dialog__close { + position: absolute; + top: calc(1rem + (64px * 0.8 - 2rem) / 2); + right: 1rem; + /* Above the search form, which spans the full width */ + z-index: 10; + display: grid; + place-items: center; + width: 2rem; + height: 2rem; + padding: 0; + border: 0; + border-radius: var(--os-radius); + background: none; + color: var(--os-muted); + cursor: pointer; +} +.search-dialog__close:hover { + color: var(--os-fg); + background: var(--os-surface); +} +.search-dialog__close svg { + width: 1.25rem; + height: 1.25rem; +} +/* Room for the close button next to the field (the results stay full width) */ +#site-search .pagefind-ui__search-input { + width: calc(100% - 2.5rem); +} +/* Clear reads as a link */ +#site-search .pagefind-ui__search-clear { + right: calc(2.5rem + 1px); + padding: 0 0.75rem; + color: var(--os-accent-text); + font-size: 0.875rem; + font-weight: 500; +} +#site-search .pagefind-ui__search-clear:hover { + text-decoration: underline; + text-underline-offset: 0.2em; +} +#site-search { + --pagefind-ui-scale: 0.8; + --pagefind-ui-primary: var(--os-fg); + --pagefind-ui-text: var(--site-text); + --pagefind-ui-background: var(--os-bg); + --pagefind-ui-border: var(--os-border); + --pagefind-ui-tag: var(--os-surface); + --pagefind-ui-border-radius: var(--os-radius); + --pagefind-ui-font: var(--os-font-sans); +} +/* Whole result rows are clickable: each result title link stretches over its + row (the page row, or one section row nested under it). */ +#site-search .pagefind-ui__result-inner, +#site-search .pagefind-ui__result-nested { + position: relative; + border-radius: var(--os-radius); +} +/* Tighter results; each page gets a page icon before its title */ +#site-search .pagefind-ui__result { + padding: 0.35rem 0; +} +#site-search .pagefind-ui__result-inner { + padding: 0.5rem 0.75rem; +} +#site-search .pagefind-ui__result-inner > .pagefind-ui__result-title { + display: flex; + align-items: center; + gap: 0.5rem; +} +#site-search .pagefind-ui__result-inner > .pagefind-ui__result-title::before { + content: ""; + flex: none; + width: 1.125rem; + height: 1.125rem; + background: var(--os-muted); + mask: + url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linejoin='round'%3E%3Cpath d='M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 3v5h5M9 13h6M9 17h6'/%3E%3C/svg%3E") + center / contain no-repeat; +} +/* Excerpts and sections line up with the title text, after the icon */ +#site-search .pagefind-ui__result-inner > .pagefind-ui__result-excerpt { + margin-inline-start: 1.625rem; +} +#site-search .pagefind-ui__result-nested { + /* Full row width, not the width of the text (Pagefind lays rows out with + align-items: flex-start) */ + align-self: stretch; + z-index: 1; + /* Cancel the page row's side padding so both highlights are equally wide */ + margin-inline: -0.75rem; + padding: 0.35rem 0.75rem 0.35rem calc(0.75rem + 1.625rem); +} +/* Pagefind positions section links (for the arrow), which would limit their + overlay to the link text; keep the arrow inline instead. */ +#site-search .pagefind-ui__result-nested .pagefind-ui__result-link, +#site-search .pagefind-ui__result-nested .pagefind-ui__result-link::before { + position: static; +} +#site-search .pagefind-ui__result-link::after { + content: ""; + position: absolute; + inset: 0; + border-radius: inherit; +} +#site-search .pagefind-ui__result-inner:hover:not(:has(.pagefind-ui__result-nested:hover)), +#site-search .pagefind-ui__result-nested:hover, +#site-search .pagefind-ui__result-inner:has(> .pagefind-ui__result-title .pagefind-ui__result-link:focus-visible), +#site-search .pagefind-ui__result-nested:has(.pagefind-ui__result-link:focus-visible) { + background: var(--os-surface); +} +#site-search .pagefind-ui__result-link:focus-visible { + outline: none; +} +/* Keyboard focus: the row's highlight plus an accent bar on its left edge */ +#site-search .pagefind-ui__result-link:focus-visible::after { + box-shadow: inset 3px 0 0 var(--os-accent); +} +/* Where a result comes from (Core, Go SDK, Community), top right of its row */ +#site-search .pagefind-ui__result-tags { + position: absolute; + top: 0.6rem; + right: 0.75rem; + margin: 0; +} +#site-search .pagefind-ui__result-tag { + padding: 0.05rem 0.5rem; + border-radius: 999px; + background: color-mix(in srgb, var(--os-accent) 14%, transparent); + color: var(--os-accent-text); + font-size: 0.75rem; + font-weight: 500; +} +#site-search .pagefind-ui__result-title { + padding-inline-end: 6rem; +} +/* Type scale of the rest of the site: semibold titles, a regular-weight query, + and excerpts at the docs' small-text size (Pagefind defaults to bold and + 12.8px at this scale) */ +#site-search .pagefind-ui__search-input { + font-weight: 400; +} +#site-search .pagefind-ui__result-title { + font-weight: 600; +} +#site-search .pagefind-ui__result-excerpt { + font-size: 0.875rem; + line-height: 1.5; +} +#site-search .pagefind-ui__message, +#site-search .pagefind-ui__button { + font-weight: 600; +} +#site-search mark { + background: none; + color: var(--os-accent-text); + font-weight: 600; +} +@media (width < 50rem) { + .search-button { + width: 2rem; + height: 2rem; + padding: 0; + justify-content: center; + border: 0; + background: none; + } + .search-button svg { + width: 1.125rem; + height: 1.125rem; + } + .search-button__label, + .search-button__kbd { + display: none; + } +} diff --git a/theme/site-bar.mjs b/theme/site-bar.mjs new file mode 100644 index 0000000..a0eb5d8 --- /dev/null +++ b/theme/site-bar.mjs @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: Apache-2.0 +// The site bar shared by every page: wordmark, site links, search, GitHub, and +// the theme toggle, plus the search dialog. The docs header +// (site/src/components/overrides/Header.astro) and the website pages +// (scripts/website.mjs) both render it from here, with the same styles +// (site-bar.css) and scripts (search.js, theme-toggle.js), so the bar can't +// differ between them. +import nav from './nav.json' with { type: 'json' }; + +const esc = (s) => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); + +const WORDMARK = `<svg viewBox="14 7 72 87" aria-hidden="true"><path d="M50 9 L84 23 V51 C84 72 69 86 50 92 C31 86 16 72 16 51 V23 Z" fill="#76B900"/><g fill="none" stroke="#FFFFFF" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"><path d="M37 41 L49 50 L37 59"/><path d="M55 59 H67"/></g></svg>`; +const SEARCH = `<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="6.5" fill="none" stroke="currentColor" stroke-width="1.75"/><path d="m16 16 4 4" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"/></svg>`; +const GITHUB = `<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.07 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.6-2.67-.3-5.47-1.33-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3"/></svg>`; +// Cycled by theme-toggle.js: auto (system), light, dark. +const THEME = `<button type="button" class="icon-button theme-toggle" aria-label="Theme: auto. Switch theme" title="Theme: auto"><svg viewBox="0 0 24 24" aria-hidden="true" class="theme-toggle__auto"><rect x="3" y="4.5" width="18" height="12" rx="1.5" fill="none" stroke="currentColor" stroke-width="1.75"/><path d="M8 20h8M12 16.5V20" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"/></svg><svg viewBox="0 0 24 24" aria-hidden="true" class="theme-toggle__light"><circle cx="12" cy="12" r="4" fill="none" stroke="currentColor" stroke-width="1.75"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"/></svg><svg viewBox="0 0 24 24" aria-hidden="true" class="theme-toggle__dark"><path d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5Z" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round"/></svg></button>`; +const CLOSE = `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"/></svg>`; + +/** + * @param {object} opts + * @param {string} [opts.current] href of the current site link (e.g. '/docs/'), marked as the current page + * @param {{ bundlePath: string, baseUrl: string, merge?: string }} opts.search + * the Pagefind index to search, and optionally a second index to merge + * (the website pages' /pagefind-website/) + */ +export function siteBar({ current, search }) { + const links = nav.links + .map( + (l) => + `<a href="${esc(l.href)}" class="site-bar__link"${l.href === current ? ' aria-current="page"' : ''}>${esc(l.label)}</a>`, + ) + .join(''); + const data = [ + ['bundle', search.bundlePath], + ['base-url', search.baseUrl], + ['merge', search.merge], + ] + .filter(([, v]) => v) + .map(([k, v]) => ` data-${k}="${esc(v)}"`) + .join(''); + return `<div class="site-bar"> +<a href="/" class="site-bar__wordmark" translate="no">${WORDMARK}<span>OpenShell</span></a> +<nav class="site-bar__links" aria-label="Site">${links}</nav> +<button type="button" class="search-button" data-search-open>${SEARCH}<span class="search-button__label">Search</span><kbd class="search-button__kbd">Ctrl K</kbd></button> +<div class="site-bar__end"> +<a href="${esc(nav.github)}" class="icon-button"><span class="sr-only">GitHub</span>${GITHUB}</a> +${THEME} +</div> +</div> +<dialog class="search-dialog" aria-label="Search"${data}> +<div class="search-dialog__frame"> +<button type="button" class="search-dialog__close" data-search-close aria-label="Close search">${CLOSE}</button> +<div id="site-search"></div> +</div> +</dialog>`; +} diff --git a/theme/theme-toggle.js b/theme/theme-toggle.js new file mode 100644 index 0000000..05cd6a0 --- /dev/null +++ b/theme/theme-toggle.js @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Apache-2.0 +// Theme toggle in the site bar (markup in site-bar.mjs). Each click cycles +// auto -> light -> dark. The choice is stored where Starlight keeps it +// (localStorage starlight-theme, '' for auto), so it carries between the landing page and the docs, and Starlight's own +// theme select in the docs mobile menu stays in sync. +const KEY = 'starlight-theme'; +const ORDER = ['auto', 'light', 'dark']; +const light = matchMedia('(prefers-color-scheme: light)'); + +const stored = () => { + try { + const v = localStorage.getItem(KEY); + return v === 'light' || v === 'dark' ? v : 'auto'; + } catch { + return undefined; + } +}; +let choice = stored() ?? 'auto'; + +function apply() { + const root = document.documentElement; + root.dataset.themeChoice = choice; + root.dataset.theme = choice === 'auto' ? (light.matches ? 'light' : 'dark') : choice; + for (const b of document.querySelectorAll('.theme-toggle')) { + b.title = `Theme: ${choice}`; + b.setAttribute('aria-label', `Theme: ${choice}. Switch theme`); + } + window.StarlightThemeProvider?.updatePickers(choice); +} + +document.addEventListener('click', (e) => { + if (!(e.target instanceof Element) || !e.target.closest('.theme-toggle')) return; + choice = ORDER[(ORDER.indexOf(stored() ?? choice) + 1) % ORDER.length]; + try { + localStorage.setItem(KEY, choice === 'auto' ? '' : choice); + } catch {} + apply(); +}); +light.addEventListener('change', () => choice === 'auto' && apply()); +// Follow Starlight's select in the docs mobile menu, and other tabs. +const sync = () => { + choice = stored() ?? choice; + apply(); +}; +document.addEventListener( + 'change', + (e) => e.target instanceof Element && e.target.closest('starlight-theme-select') && sync(), +); +addEventListener('storage', (e) => e.key === KEY && sync()); +apply(); diff --git a/website/community.md b/website/community.md new file mode 100644 index 0000000..71591c6 --- /dev/null +++ b/website/community.md @@ -0,0 +1,21 @@ +--- +# SPDX-License-Identifier: Apache-2.0 +title: Community +description: Where to find the OpenShell community and how to contribute. +--- + +OpenShell is a [Cloud Native Computing Foundation](https://www.cncf.io/) +sandbox project, built in the open. Everyone is welcome to ask questions, share +what they're building, and contribute. + +## Develop and contribute + +To learn how to contribute to OpenShell, see the +[contributing guide](https://github.com/ai-openshell/openshell/blob/main/CONTRIBUTING.md). +Other useful links: + +- :github: [GitHub](https://github.com/ai-openshell): Find us on GitHub. +- :slack: [Slack #openshell-dev](https://cloud-native.slack.com/archives/C0B6Y8WQHU1): + Follow project-wide developments. To chat about a specific subproject, check + out the other channels starting with `#openshell-`. Sign up via + [slack.cncf.io](https://slack.cncf.io/). diff --git a/website/icons/github.svg b/website/icons/github.svg new file mode 100644 index 0000000..b7f353d --- /dev/null +++ b/website/icons/github.svg @@ -0,0 +1,2 @@ +<!-- GitHub logo from Starlight's icon set (@astrojs/starlight, MIT). Used by :github: in website/*.md. --> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" class="icon"><path d="M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.08 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.61-2.67-.3-5.47-1.33-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3Z"/></svg> diff --git a/website/icons/slack.svg b/website/icons/slack.svg new file mode 100644 index 0000000..32d9081 --- /dev/null +++ b/website/icons/slack.svg @@ -0,0 +1,2 @@ +<!-- Slack logo from Starlight's icon set (@astrojs/starlight, MIT). Used by :slack: in website/*.md. --> +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" class="icon"><path d="M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52Zm1.271 0a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313ZM8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834Zm0 1.271a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312Zm10.122 2.521a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834Zm-1.268 0a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312Zm-2.523 10.122a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52Zm0-1.268a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313Z"/></svg> diff --git a/www/index.html b/website/index.html similarity index 73% rename from www/index.html rename to website/index.html index 087caef..00408fc 100644 --- a/www/index.html +++ b/website/index.html @@ -1,6 +1,6 @@ <!doctype html> <!-- SPDX-License-Identifier: Apache-2.0 --> -<!-- The landing page at /. Everything in www/ is served at the site root; scripts/website.mjs publishes it next to the docs build at /docs/. --> +<!-- The landing page at /. Everything in website/ is served at the site root; scripts/website.mjs publishes it next to the docs build at /docs/. The website/*.md pages reuse this file as their shell: everything except the title, the description, and the main element. --> <html lang="en"> <head> <meta charset="utf-8" /> @@ -16,64 +16,26 @@ href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" /> <link rel="stylesheet" href="/tokens.css" /> + <link rel="stylesheet" href="/site-bar.css" /> <link rel="stylesheet" href="/style.css" /> <script> - // Share the theme choice with the docs: Starlight stores it as starlight-theme. + // Apply the theme before the page paints. Starlight stores the choice as + // starlight-theme ('' for auto); theme-toggle.js handles changes. (() => { let t = ''; try { t = localStorage.getItem('starlight-theme') ?? ''; } catch {} - if (t !== 'light' && t !== 'dark') t = matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; - document.documentElement.dataset.theme = t; + const choice = t === 'light' || t === 'dark' ? t : 'auto'; + document.documentElement.dataset.themeChoice = choice; + document.documentElement.dataset.theme = + choice === 'auto' ? (matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark') : choice; })(); </script> </head> <body> - <header class="top"> - <a href="/" class="wordmark" translate="no"> - <svg viewBox="14 7 72 87" aria-hidden="true"> - <path d="M50 9 L84 23 V51 C84 72 69 86 50 92 C31 86 16 72 16 51 V23 Z" fill="#76B900" /> - <g fill="none" stroke="#FFFFFF" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"> - <path d="M37 41 L49 50 L37 59" /> - <path d="M55 59 H67" /> - </g> - </svg> - <span>OpenShell</span> - </a> - <nav aria-label="Site"> - <a href="/docs/" class="nav-link">Docs</a> - <a href="https://github.com/ai-openshell/openshell" class="icon-link"> - <span class="sr-only">GitHub</span> - <svg viewBox="0 0 24 24" aria-hidden="true"> - <path - fill="currentColor" - d="M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.07 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.6-2.67-.3-5.47-1.33-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3" - /> - </svg> - </a> - <button type="button" class="icon-link theme-toggle" aria-label="Toggle dark mode"> - <svg viewBox="0 0 24 24" aria-hidden="true" class="sun"> - <circle cx="12" cy="12" r="4" fill="none" stroke="currentColor" stroke-width="1.75" /> - <path - d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" - stroke="currentColor" - stroke-width="1.75" - stroke-linecap="round" - /> - </svg> - <svg viewBox="0 0 24 24" aria-hidden="true" class="moon"> - <path - d="M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5Z" - fill="none" - stroke="currentColor" - stroke-width="1.75" - stroke-linejoin="round" - /> - </svg> - </button> - </nav> - </header> + <!-- The site bar (theme/site-bar.mjs), shared with the docs; scripts/website.mjs fills it in. --> + <header class="top"><!-- site-bar --></header> <main> <!-- Copy comes from the ai-openshell/openshell README (intro, How It Works, @@ -87,7 +49,7 @@ <h1>The safe, private runtime for <span class="accent">autonomous AI agents</spa declare what each agent can touch in a policy, and OpenShell enforces it. </p> <div class="actions"> - <a class="button primary" href="/docs/">Documentation <span aria-hidden="true">→</span></a> + <a class="button primary" href="/docs/">Documentation</a> <a class="button" href="https://github.com/ai-openshell/openshell">GitHub</a> </div> </section> @@ -222,13 +184,8 @@ <h2 id="explore-title">Explore Further</h2> setTimeout(() => delete b.dataset.copied, 1500); }); } - document.querySelector('.theme-toggle').addEventListener('click', () => { - const t = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'; - document.documentElement.dataset.theme = t; - try { - localStorage.setItem('starlight-theme', t); - } catch {} - }); </script> + <script type="module" src="/theme-toggle.js"></script> + <script type="module" src="/search.js"></script> </body> </html> diff --git a/www/style.css b/website/style.css similarity index 86% rename from www/style.css rename to website/style.css index a4033aa..82155bd 100644 --- a/www/style.css +++ b/website/style.css @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: Apache-2.0 */ -/* Landing page styles (www/index.html). Colors and fonts come from theme/tokens.css (--os-*); - text, card, and code colors follow site/src/styles/theme.css so the page - matches the docs. */ +/* Styles for the pages in website/: the landing page and the Markdown pages. + Colors and fonts come from theme/tokens.css (--os-*); text, card, and code + colors follow site/src/styles/theme.css so the pages match the docs. */ :root { --text: #d3d8cc; --strong: var(--os-fg); @@ -66,75 +66,15 @@ a:hover { } /* ---------- header ---------- */ +/* The bar itself is theme/site-bar.css; here it only sticks to the top. */ .top { position: sticky; top: 0; z-index: 10; - display: flex; - align-items: center; - justify-content: space-between; - height: var(--os-header-h); - padding: 0 1.5rem; - border-bottom: 1px solid var(--os-border); background: color-mix(in srgb, var(--os-bg) 85%, transparent); backdrop-filter: blur(8px); } -.wordmark { - display: flex; - align-items: center; - gap: 0.55rem; - color: var(--strong); - font-weight: 600; - font-size: 1rem; - letter-spacing: -0.01em; - text-decoration: none; -} -.wordmark svg { - height: 1.625rem; - width: auto; -} - -.top nav { - display: flex; - align-items: center; - gap: 0.25rem; -} -.nav-link { - padding: 0.25rem 0.625rem; - color: var(--os-muted); - font-size: 0.875rem; - font-weight: 500; - text-decoration: none; -} -.nav-link:hover { - color: var(--strong); -} -.icon-link { - display: grid; - place-items: center; - width: 2rem; - height: 2rem; - padding: 0; - border: 0; - border-radius: var(--os-radius); - background: none; - color: var(--os-muted); - cursor: pointer; -} -.icon-link:hover { - color: var(--strong); - background: var(--os-surface); -} -.icon-link svg { - width: 1.125rem; - height: 1.125rem; -} -:root[data-theme="dark"] .theme-toggle .moon, -:root[data-theme="light"] .theme-toggle .sun { - display: none; -} - /* ---------- layout ---------- */ main { max-width: 64rem; @@ -160,6 +100,44 @@ h2 { color: var(--os-muted); } +/* ---------- Markdown pages (website/*.md) ---------- */ +.page { + max-width: 48rem; + padding-top: 3.5rem; + padding-bottom: 3rem; +} +.page h1 { + /* Same as a docs page title (Starlight's --sl-text-h1 in site/src/styles/theme.css) */ + margin: 0 0 1rem; + font-size: 2rem; + line-height: 1.2; + letter-spacing: -0.025em; +} +@media (min-width: 50rem) { + .page h1 { + font-size: 2.125rem; + } +} +.page h2 { + margin: 2.5rem 0 0.5rem; +} +.page code { + font-family: var(--os-font-mono); + font-size: 0.875em; + color: var(--strong); +} +.page li + li { + margin-top: 0.5rem; +} +/* Icons from :name: shortcodes (website/icons/) */ +.page .icon { + width: 1em; + height: 1em; + margin-inline-end: 0.15em; + vertical-align: -0.125em; + color: var(--strong); +} + /* ---------- hero ---------- */ .hero { padding: 5.5rem 0 3rem; @@ -426,9 +404,6 @@ a.card:hover .arrow { } @media (max-width: 40rem) { - .top { - padding: 0 1rem; - } main { padding: 0 1rem; }