From 36715edfeb50bfd6f078bb0a16d7a585b62185ad Mon Sep 17 00:00:00 2001
From: HiDeoo <494699+HiDeoo@users.noreply.github.com>
Date: Mon, 15 Apr 2024 10:40:36 +0200
Subject: [PATCH] docs: rewrite `guides/sidebar` examples to be more generic
(#1751)
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
---
docs/src/components/sidebar-preview.astro | 5 +-
docs/src/content/docs/guides/sidebar.mdx | 242 +++++++++++-----------
2 files changed, 121 insertions(+), 126 deletions(-)
diff --git a/docs/src/components/sidebar-preview.astro b/docs/src/components/sidebar-preview.astro
index bd10705d169..f392972a009 100644
--- a/docs/src/components/sidebar-preview.astro
+++ b/docs/src/components/sidebar-preview.astro
@@ -17,7 +17,10 @@ function makeEntries(items: SidebarConfig): SidebarEntry[] {
return {
type: 'link',
label: item.label,
- href: item.link,
+ // Empty hrefs are used to represent internal links that do not exist in the Starlight
+ // docs. Using a non-existing anchor link like `#_` will not trigger a page reload or any
+ // scrolling.
+ href: item.link.length > 0 ? item.link : '#_',
isCurrent: false,
badge: item.badge,
attrs: item.attrs ?? {},
diff --git a/docs/src/content/docs/guides/sidebar.mdx b/docs/src/content/docs/guides/sidebar.mdx
index 726e9f9a276..bf9d3605642 100644
--- a/docs/src/content/docs/guides/sidebar.mdx
+++ b/docs/src/content/docs/guides/sidebar.mdx
@@ -19,11 +19,11 @@ For example, given the following file structure:
- src/
- content/
- docs/
- - guides/
- - components.md
- - i18n.md
- - reference/
- - configuration.md
+ - constellations/
+ - andromeda.md
+ - orion.md
+ - stars/
+ - betelgeuse.md
@@ -32,17 +32,15 @@ The following sidebar will be automatically generated:
@@ -62,10 +60,10 @@ Add a link to an internal or external page using an object with `label` and `lin
```js "label:" "link:"
starlight({
sidebar: [
- // A link to the CSS & Styling guide.
- { label: 'CSS & Styling', link: '/guides/css-and-tailwind/' },
- // An external link to the Astro website.
- { label: 'Astro', link: 'https://astro.build/' },
+ // A link to the Ganymede moon page.
+ { label: 'Ganymede', link: '/moons/ganymede/' },
+ // An external link to the NASA website.
+ { label: 'NASA', link: 'https://www.nasa.gov/' },
],
});
```
@@ -74,8 +72,8 @@ The configuration above generates the following sidebar:
@@ -91,19 +89,19 @@ Add links or subgroups to the `items` array.
```js /^\s*(label:|items:)/
starlight({
sidebar: [
- // A group of links labelled "Guides".
+ // A group of links labelled "Constellations".
{
- label: 'Guides',
+ label: 'Constellations',
items: [
- { label: 'Components', link: '/guides/components/' },
- { label: 'Internationalization (i18n)', link: '/guides/i18n/' },
- // A nested group of links.
+ { label: 'Carina', link: '/constellations/carina/' },
+ { label: 'Centaurus', link: '/constellations/centaurus/' },
+ // A nested group of links for seasonal constellations.
{
- label: 'Styling',
+ label: 'Seasonal',
items: [
- { label: 'CSS', link: '/guides/css-and-tailwind/' },
- { label: 'Tailwind', link: '/guides/css-and-tailwind/' },
- { label: 'Shiki', link: '/guides/css-and-tailwind/' },
+ { label: 'Andromeda', link: '/constellations/andromeda/' },
+ { label: 'Orion', link: '/constellations/orion/' },
+ { label: 'Ursa Minor', link: '/constellations/ursa-minor/' },
],
},
],
@@ -117,16 +115,16 @@ The configuration above generates the following sidebar:
@@ -175,15 +173,13 @@ The following sidebar will be generated: