Skip to content

Commit f95cb3c

Browse files
committed
Add version selector
1 parent 31176e3 commit f95cb3c

File tree

4 files changed

+114
-32
lines changed

4 files changed

+114
-32
lines changed

astro.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export default defineConfig({
2121
integrations: [
2222
starlight({
2323
title: "VSCode Elements",
24+
components: {
25+
SiteTitle: "./src/components/SiteTitle.astro",
26+
},
2427
social: [
2528
{
2629
icon: "github",

src/components/SiteTitle.astro

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
import { logos } from "virtual:starlight/user-images";
3+
import config from "virtual:starlight/user-config";
4+
import VersionInfo from "./VersionInfo.astro";
5+
const { siteTitle, siteTitleHref } = Astro.locals.starlightRoute;
6+
---
7+
8+
<a href={siteTitleHref} class="site-title sl-flex">
9+
{
10+
config.logo && logos.dark && (
11+
<>
12+
<img
13+
class:list={{
14+
"light:sl-hidden print:hidden": !("src" in config.logo),
15+
}}
16+
alt={config.logo.alt}
17+
src={logos.dark.src}
18+
width={logos.dark.width}
19+
height={logos.dark.height}
20+
/>
21+
{/* Show light alternate if a user configure both light and dark logos. */}
22+
{!("src" in config.logo) && (
23+
<img
24+
class="dark:sl-hidden print:block"
25+
alt={config.logo.alt}
26+
src={logos.light?.src}
27+
width={logos.light?.width}
28+
height={logos.light?.height}
29+
/>
30+
)}
31+
</>
32+
)
33+
}
34+
<span class:list={{ "sr-only": config.logo?.replacesTitle }} translate="no">
35+
{siteTitle}
36+
</span>
37+
</a>
38+
<select id="version-selector">
39+
<option value="https://vscode-elements.github.io/docs-archive/v1">v1.x</option
40+
>
41+
<option selected value="https://vscode-elements.github.io"
42+
>v<VersionInfo /></option
43+
>
44+
</select>
45+
46+
<style>
47+
@layer starlight.core {
48+
.site-title {
49+
align-items: center;
50+
gap: var(--sl-nav-gap);
51+
font-size: var(--sl-text-h4);
52+
font-weight: 600;
53+
color: var(--sl-color-text-accent);
54+
text-decoration: none;
55+
white-space: nowrap;
56+
min-width: 0;
57+
}
58+
span {
59+
overflow: hidden;
60+
}
61+
img {
62+
height: calc(var(--sl-nav-height) - 2 * var(--sl-nav-pad-y));
63+
width: auto;
64+
max-width: 100%;
65+
object-fit: contain;
66+
object-position: 0 50%;
67+
}
68+
select {
69+
background-color: transparent;
70+
border: 0;
71+
margin-left: 10px;
72+
padding-left: 10px;
73+
padding-right: 10px;
74+
}
75+
}
76+
</style>
77+
78+
<script>
79+
const sl = document.querySelector<HTMLSelectElement>("#version-selector");
80+
sl?.addEventListener("input", () => {
81+
window.location.href = sl.value;
82+
});
83+
</script>

src/components/VersionInfo.astro

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
---
2-
import * as fs from "node:fs/promises";
3-
4-
const fc = await fs.readFile(
5-
"node_modules/@vscode-elements/elements/package.json",
6-
"utf-8"
7-
);
8-
const pkg = JSON.parse(fc);
9-
---
10-
11-
<p>Current version: {pkg.version}</p>
1+
---
2+
import * as fs from "node:fs/promises";
3+
4+
const fc = await fs.readFile(
5+
"node_modules/@vscode-elements/elements/package.json",
6+
"utf-8"
7+
);
8+
const pkg = JSON.parse(fc);
9+
---
10+
11+
{pkg.version}

src/content/docs/index.mdx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
---
2-
title: VSCode Elements
3-
description: Web component library for developing Visual Studio Code extensions
4-
template: splash
5-
hero:
6-
tagline: Web component library for developing Visual Studio Code extensions
7-
image:
8-
file: ../../assets/logo.svg
9-
actions:
10-
- text: Getting started
11-
link: /guides/getting-started/
12-
icon: right-arrow
13-
- text: Source code
14-
link: https://github.com/vscode-elements/elements
15-
icon: external
16-
variant: minimal
17-
---
18-
19-
import VersionInfo from "@components/VersionInfo.astro";
20-
21-
<VersionInfo />
1+
---
2+
title: VSCode Elements
3+
description: Web component library for developing Visual Studio Code extensions
4+
template: splash
5+
hero:
6+
tagline: Web component library for developing Visual Studio Code extensions
7+
image:
8+
file: ../../assets/logo.svg
9+
actions:
10+
- text: Getting started
11+
link: /guides/getting-started/
12+
icon: right-arrow
13+
- text: Source code
14+
link: https://github.com/vscode-elements/elements
15+
icon: external
16+
variant: minimal
17+
---

0 commit comments

Comments
 (0)