Skip to content

Commit

Permalink
feat: excluded pages (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Mar 4, 2025
1 parent 892408a commit 0e5806f
Show file tree
Hide file tree
Showing 28 changed files with 412 additions and 69 deletions.
9 changes: 9 additions & 0 deletions .changeset/light-candles-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'starlight-sidebar-topics': minor
---

Adds a new [`exclude`](https://starlight-sidebar-topics.netlify.app/docs/configuration#exclude) plugin configuration option to exclude pages from any topic.

This options can be useful for custom pages that use a custom site navigation sidebar which do not belong to any topic. Excluded pages will use the built-in Starlight sidebar and not render a list of topics.

See the [“Excluded Pages”](https://starlight-sidebar-topics.netlify.app/docs/guides/excluded-pages) guide to learn more about how to exclude content pages from any topic.
71 changes: 38 additions & 33 deletions docs/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,49 @@ export default defineConfig({
baseUrl: 'https://github.com/HiDeoo/starlight-sidebar-topics/edit/main/docs/',
},
plugins: [
starlightSidebarTopics([
{
label: 'Documentation',
link: '/docs/getting-started/',
icon: 'open-book',
items: [
{ label: 'Start Here', items: ['docs/getting-started', 'docs/configuration'] },
{ label: 'Guides', autogenerate: { directory: 'docs/guides' } },
{ label: 'Resources', items: [{ label: 'Plugins and Tools', slug: 'docs/resources/starlight' }] },
],
},
{
id: 'demo',
label: {
en: 'Demo',
fr: 'Démo',
starlightSidebarTopics(
[
{
label: 'Documentation',
link: '/docs/getting-started/',
icon: 'open-book',
items: [
{ label: 'Start Here', items: ['docs/getting-started', 'docs/configuration'] },
{ label: 'Guides', autogenerate: { directory: 'docs/guides' } },
{ label: 'Resources', items: [{ label: 'Plugins and Tools', slug: 'docs/resources/starlight' }] },
],
},
link: '/demo/',
icon: 'puzzle',
items: [
{ label: 'API', autogenerate: { directory: 'demo/api' } },
{ label: 'Components', autogenerate: { directory: 'demo/components' } },
{ label: 'Commands', autogenerate: { directory: 'demo/commands' }, collapsed: true },
],
badge: {
text: {
en: 'Stub',
fr: 'Ébauche',
{
id: 'demo',
label: {
en: 'Demo',
fr: 'Démo',
},
link: '/demo/',
icon: 'puzzle',
items: [
{ label: 'API', autogenerate: { directory: 'demo/api' } },
{ label: 'Components', autogenerate: { directory: 'demo/components' } },
{ label: 'Commands', autogenerate: { directory: 'demo/commands' }, collapsed: true },
],
badge: {
text: {
en: 'Stub',
fr: 'Ébauche',
},
variant: 'caution',
},
variant: 'caution',
},
},
{
label: 'Starlight Docs',
link: 'https://starlight.astro.build/',
icon: 'starlight',
},
],
{
label: 'Starlight Docs',
link: 'https://starlight.astro.build/',
icon: 'starlight',
exclude: ['/demo/excluded/**/*', '/*/demo/excluded/**/*'],
},
]),
),
],
social: {
blueSky: 'https://bsky.app/profile/hideoo.dev',
Expand Down
13 changes: 13 additions & 0 deletions docs/src/content/docs/demo/excluded/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Excluded with sidebar
pagefind: false
---

This page is not listed in any topic sidebar configuration, is not associated any topic through the `topic` frontmatter field, and is also excluded in the plugin configuration.

See the [“Excluded Pages”](/docs/guides/excluded-pages) guide to learn how to exclude content pages from any topic.

:::note
This page exists solely for demonstration purposes and contains no useful information.
See the Starlight Sidebar Topics plugin [documentation](/docs/getting-started/) for more information.
:::
11 changes: 11 additions & 0 deletions docs/src/content/docs/demo/excluded/splash.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Excluded without sidebar
pagefind: false
---

This page using the `splash` template is not listed in any topic sidebar configuration, is not associated with any topic through the `topic` frontmatter field, and is also excluded in the plugin configuration.

:::note
This page exists solely for demonstration purposes and contains no useful information.
See the Starlight Sidebar Topics plugin [documentation](/docs/getting-started/) for more information.
:::
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Secrets with sidebar
title: Unlisted with sidebar
topic: demo
pagefind: false
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Secrets without sidebar
title: Unlisted without sidebar
template: splash
pagefind: false
---
Expand Down
52 changes: 48 additions & 4 deletions docs/src/content/docs/docs/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: An overview of the configuration options supported by the Starlight

The Starlight Sidebar Topics can be configured inside the `astro.config.mjs` configuration file of your project:

```js {12}
```js {13,16}
// astro.config.mjs
// @ts-check
import starlight from '@astrojs/starlight'
Expand All @@ -16,9 +16,14 @@ export default defineConfig({
integrations: [
starlight({
plugins: [
starlightSidebarTopics([
// Topics configuration goes here.
]),
starlightSidebarTopics(
[
// Topics configuration goes here.
],
{
// Plugin configuration goes here (optional).
},
),
],
title: 'My Docs',
}),
Expand Down Expand Up @@ -180,3 +185,42 @@ starlightSidebarTopics([
},
])
```

## Plugin configuration

The Starlight Sidebar Topics plugin accepts an optional configuration object as the second argument.

The configuration object can be used to customize the plugin global behavior and the following options are available:

### `exclude`

**type:** `string[]`
**default:** `[]`

A list of pages or [glob patterns](https://github.com/micromatch/picomatch#globbing-features) that should be excluded from any topic.

This options can be useful for [custom pages](https://starlight.astro.build/guides/pages/#custom-pages) that use a [custom site navigation sidebar](https://starlight.astro.build/guides/pages/#sidebar) which do not belong to any topic.
Excluded pages will use the built-in Starlight sidebar and not render a list of topics.

The following example excludes all pages under the `/blog` directory from any topic:

```js {10}
starlightSidebarTopics(
[
{
label: 'Guides',
link: '/guides/',
items: ['guides/concepts', 'guides/courses'],
},
],
{
exclude: ['/blog', '/blog/**/*'],
},
)
```

See the [“Excluded Pages”](/docs/guides/excluded-pages) guide to learn how to exclude content pages from any topic.

:::tip
You can use this [webpage](https://www.digitalocean.com/community/tools/glob) to generate and test glob patterns.
:::
2 changes: 1 addition & 1 deletion docs/src/content/docs/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ import { PackageManagers } from '@hideoo/starlight-plugins-docs-components'

</Steps>

The Starlight Sidebar Topics plugin behavior can be tweaked using various [topic configuration options](/docs/configuration/#topic-configuration).
The Starlight Sidebar Topics plugin behavior can be tweaked using various [configuration options](/docs/configuration/).
82 changes: 82 additions & 0 deletions docs/src/content/docs/docs/guides/excluded-pages.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: Excluded Pages
description: Learn how to exclude content pages from any topic.
---

By default, the Starlight Sidebar Topics plugin expect that every pages in your project is associated with a topic.
This is done by including the page in a [topic sidebar configuration](/docs/configuration#items) or using the `topic` frontmatter field for [unlisted pages](/docs/guides/unlisted-pages/).

However, there are cases where you may have [custom pages](https://starlight.astro.build/guides/pages/#custom-pages) that use a [custom site navigation sidebar](https://starlight.astro.build/guides/pages/#sidebar) which do not belong to any topic.
Excluding these pages from any topic will prevent the plugin from rendering a list of topics in the sidebar and use the built-in Starlight sidebar instead.

## Exclude pages

To exclude some pages from any topic, you can use the [`exclude`](/docs/configuration#exclude) plugin configuration option.

```js {20}
// astro.config.mjs
// @ts-check
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightSidebarTopics from 'starlight-sidebar-topics'

export default defineConfig({
integrations: [
starlight({
plugins: [
starlightSidebarTopics(
[
{
label: 'Guides',
link: '/guides/',
items: ['guides/concepts', 'guides/courses'],
},
],
{
exclude: ['/changelog', '/changelog/**/*'],
},
),
],
title: 'My Docs',
}),
],
})
```

For example, given the above configuration and following file structure:

import { FileTree } from '@astrojs/starlight/components'

<FileTree>

- src/
- content/
- docs/
- guides/
- concepts.md
- courses.md
- pages/
- changelog.astro
-

</FileTree>

And the `changelog.astro` page content rendering the following custom page with a custom site navigation sidebar:

```astro title="src/pages/changelog.astro" {3-7}
<StarlightPage
frontmatter={{ title: 'Changelog' }}
sidebar={[
{ label: 'v3.0.0', link: '/changelog/v3-0-0/' },
{ label: 'v2.0.0', link: '/changelog/v2-0-0/' },
{ label: 'v1.0.0', link: '/changelog/v1-0-0/' },
]}
>
</StarlightPage>
```

Visiting the `guides/concepts` and `guides/courses` pages will display the sidebar of the "Guides" topic while the `changelog` page will use the custom site navigation sidebar defined in the `changelog.astro` page using the built-in Starlight sidebar.

- `guides/concepts` and `guides/courses` are explicitly listed in the "Guides" topic sidebar configuration under the [`items`](/docs/configuration#items) key.
- `changelog` is excluded from any topic using the [`exclude`](/docs/configuration#exclude) plugin configuration option.
2 changes: 2 additions & 0 deletions docs/src/content/docs/docs/guides/unlisted-pages.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: Unlisted Pages
description: Learn how to associate content pages that are not listed in any topic sidebar configuration with a specific topic.
sidebar:
order: 1
---

By default, the Starlight Sidebar Topics plugin expect that every [content pages](https://starlight.astro.build/guides/pages/#content-pages) in your project is associated with a topic.
Expand Down
16 changes: 16 additions & 0 deletions docs/src/pages/demo/excluded/custom-no-sidebar.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import { Aside } from '@astrojs/starlight/components'
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'
---

<StarlightPage frontmatter={{ title: 'Custom - Excluded without sidebar' }} sidebar={[]} hasSidebar={false}>
<p>
This custom page with <code>hasSidebar</code> set to <code>false</code> is not listed in any topic sidebar configuration,
is not associated with any topic through the <code>topic</code> frontmatter field, and is also excluded in the plugin
configuration.
</p>
<Aside>
This page exists solely for demonstration purposes and contains no useful information. See the Starlight Sidebar
Topics plugin <a href="/docs/getting-started/">documentation</a> for more information.
</Aside>
</StarlightPage>
29 changes: 29 additions & 0 deletions docs/src/pages/demo/excluded/custom-page.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
import { Aside } from '@astrojs/starlight/components'
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'
---

<StarlightPage
frontmatter={{ title: 'Custom - Excluded without sidebar' }}
sidebar={[
{ label: 'Home', link: '/' },
{
label: 'Start Here',
items: ['docs/getting-started', 'docs/configuration'],
},
{ label: 'Demo', link: '/demo/' },
]}
>
<p>
This custom page with a custom <code>sidebar</code> is not listed in any topic sidebar configuration, is not associated
with any topic through the <code>topic</code> frontmatter field, and is also excluded in the plugin configuration.
</p>
<p>
See the <a href="/docs/guides/excluded-pages/">“Excluded Pages”</a> guide to learn how to exclude content pages from
any topic.
</p>
<Aside>
This page exists solely for demonstration purposes and contains no useful information. See the Starlight Sidebar
Topics plugin <a href="/docs/getting-started/">documentation</a> for more information.
</Aside>
</StarlightPage>
15 changes: 15 additions & 0 deletions docs/src/pages/demo/excluded/custom-splash.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
import { Aside } from '@astrojs/starlight/components'
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'
---

<StarlightPage frontmatter={{ title: 'Custom - Excluded without sidebar', template: 'splash' }}>
<p>
This custom page using the <code>splash</code> template is not listed in any topic sidebar configuration, is not associated
with any topic through the <code>topic</code> frontmatter field, and is also excluded in the plugin configuration.
</p>
<Aside>
This page exists solely for demonstration purposes and contains no useful information. See the Starlight Sidebar
Topics plugin <a href="/docs/getting-started/">documentation</a> for more information.
</Aside>
</StarlightPage>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Aside } from '@astrojs/starlight/components'
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'
---

<StarlightPage frontmatter={{ title: 'Custom - Secrets without sidebar' }} sidebar={[]} hasSidebar={false}>
<StarlightPage frontmatter={{ title: 'Custom - Unlisted without sidebar' }} sidebar={[]} hasSidebar={false}>
<p>
This custom page with <code>hasSidebar</code> set to <code>false</code> is not listed in any topic sidebar configuration
and is not associated with any topic through the <code>topic</code> frontmatter field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Aside } from '@astrojs/starlight/components'
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'
---

<StarlightPage frontmatter={{ title: 'Custom - Secrets without sidebar', topic: 'demo' }}>
<StarlightPage frontmatter={{ title: 'Custom - Unlisted without sidebar', topic: 'demo' }}>
<p>
This custom page is not listed in any topic sidebar configuration but is associated with the "Demo" topic through
the <code>topic: demo</code> frontmatter entry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Aside } from '@astrojs/starlight/components'
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro'
---

<StarlightPage frontmatter={{ title: 'Custom - Secrets without sidebar', template: 'splash' }}>
<StarlightPage frontmatter={{ title: 'Custom - Unlisted without sidebar', template: 'splash' }}>
<p>
This custom page using the <code>splash</code> template is not listed in any topic sidebar configuration and is not associated
with any topic through the <code>topic</code> frontmatter field.
Expand Down
Loading

0 comments on commit 0e5806f

Please sign in to comment.