Skip to content

Commit

Permalink
Docs version selector
Browse files Browse the repository at this point in the history
  • Loading branch information
pantonante committed Feb 19, 2024
1 parent dda9ca0 commit affe539
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 50 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/deploy_docs.yml

This file was deleted.

6 changes: 6 additions & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import rehypeMathjax from 'rehype-mathjax';

// https://astro.build/config
export default defineConfig({
base: '/v0.3',
outDir: './dist/v0.3',
markdown: {
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeMathjax],
},
integrations: [
starlight({
title: 'Continuous Eval',
components: {
// Override the default `SocialIcons` component.
ThemeSelect: './src/components/ThemeSelect.astro',
},
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 4, },
customCss: [
// Relative path to your custom CSS file
Expand Down
29 changes: 29 additions & 0 deletions docs/src/components/ThemeSelect.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
import type { Props } from '@astrojs/starlight/props';
import Default from '@astrojs/starlight/components/ThemeSelect.astro';
import Select from '@astrojs/starlight/components/Select.astro';
import { defaultVersion, versions } from '../content/config.ts';
const url = new URL(Astro.url);
const currentVersion = /^\/v\d+/.test(url.pathname)
? url.pathname.split('/')[1]
: defaultVersion;
const options = versions.map(([version, label]) => ({
label,
selected: currentVersion === version,
value: `/${version}`,
}));
---

<script>
const select = document.querySelector('select');
select?.addEventListener('change', () => {
const url = new URL(window.location.href);
const pathname = select.value + url.pathname.replace(/^\/v\d/, '');
url.pathname = pathname.replace(/\/$/, '');
window.location.href = url.href;
});
</script>

<Select label="version" value="auto" options={options} width="auto" />
<Default {...Astro.props}><slot /></Default>
9 changes: 9 additions & 0 deletions docs/src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ export const collections = {
docs: defineCollection({ schema: docsSchema() }),
i18n: defineCollection({ type: 'data', schema: i18nSchema() }),
};

export const base = '/';

export const versions = [
['v0.3', 'v0.3 (canary)'],
['v0.2', 'v0.2 (latest)'],
];

export const defaultVersion = 'v0.3';

0 comments on commit affe539

Please sign in to comment.