Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
db2f072
Add route data to `Astro.locals`
delucis Sep 22, 2024
988c554
Use local instead of props in Starlight’s components
delucis Sep 22, 2024
286e9c8
Refactor route components
delucis Sep 22, 2024
34129ab
Merge branch 'main' into chris/locals-route-data
delucis Oct 19, 2024
9aa7f35
Merge branch 'main' into chris/locals-route-data
delucis Nov 6, 2024
990bc51
Merge branch 'main' into chris/locals-route-data
delucis Dec 14, 2024
28039b4
Fix 404 render
delucis Dec 14, 2024
08c18a7
Make `routeData` a getter to avoid null checks in components
delucis Dec 14, 2024
52a13fe
Move 404 route data logic up out of components
delucis Dec 14, 2024
c1ffade
Fix SSR 404s
delucis Dec 14, 2024
e7ced3d
Rename `routeData` => `starlightRoute`
delucis Dec 14, 2024
8c67752
Merge branch 'main' into chris/locals-route-data
delucis Dec 17, 2024
243786a
Draft docs & schema
delucis Dec 18, 2024
a547e92
Add default and description in middleware config schema
delucis Dec 18, 2024
8f44f89
Tweak proposed middleware API in docs
delucis Dec 18, 2024
2cc0a8f
Move route data docs to dedicated reference page
delucis Dec 18, 2024
c21fba9
Update component overrides guide to match locals usage
delucis Dec 18, 2024
1e79b85
Add reference link to guide
delucis Dec 18, 2024
f150aba
Update config test snapshot
delucis Dec 19, 2024
840fd32
Fix links in English pages
delucis Dec 19, 2024
8db3c72
Merge branch 'main' into chris/locals-route-data
delucis Dec 19, 2024
6d0c68b
Refactor routing utilities to avoid type issues
delucis Dec 19, 2024
67cb8ed
Also move `StarlightRouteData` type
delucis Dec 19, 2024
33e6d53
More type refactoring
delucis Dec 19, 2024
bac78a0
Remove deprecated `labels` prop from route data
delucis Dec 23, 2024
2f19039
Add virtual module that exports route middleware
delucis Dec 23, 2024
f6f9af5
Add new dependency to deep clone route data
delucis Dec 23, 2024
0107e9a
Run user middleware when adding route data to pages
delucis Dec 23, 2024
72a9577
FIx tests
delucis Dec 23, 2024
b362c7a
Remove unused import
delucis Dec 26, 2024
72f3bfb
Merge branch 'main' into chris/locals-route-data
delucis Jan 8, 2025
9aa3461
Add changeset for move of route data to locals
delucis Jan 8, 2025
3a30a0b
Remove props type import in DocSearch component
delucis Jan 9, 2025
503b46d
Step up and Badge on (#2778)
trueberryless Jan 10, 2025
c8e26f8
Create `@astrojs/starlight/route-data` module to export utilities
delucis Jan 10, 2025
4eb3adf
Export `StarlightRouteData` type
delucis Jan 11, 2025
eb0357f
Deprecate the old override props export
delucis Jan 11, 2025
4e1e936
`pnpm format`
delucis Jan 11, 2025
a7eebad
Document `defineRouteMiddleware()` and `StarlightRouteData` type
delucis Jan 11, 2025
7554878
Reorganise `Props` type deprecation to fix JSDoc tooltip
delucis Jan 11, 2025
18faac2
Add a demo route middleware file
delucis Jan 11, 2025
e5df5ec
Merge branch 'main' into chris/locals-route-data
delucis Jan 28, 2025
3c91de4
Use `AstroError` for invalid plugin config mutation
delucis Jan 31, 2025
0ec6e4e
Add support for `next()` callback to middleware system
delucis Jan 31, 2025
bb35c02
Implement `addRouteMiddleware()` plugin API
delucis Jan 31, 2025
b4acdb6
Add tests
delucis Jan 31, 2025
621a59e
Document support for multiple user middleware and use of `next()`
delucis Jan 31, 2025
3cb40cd
Document `addRouteMiddleware()` plugin API
delucis Jan 31, 2025
b87650c
Fix `injectTranslations()` type in plugin quick API docs
delucis Jan 31, 2025
15da794
Fix typo
delucis Jan 31, 2025
650e14c
Update virtual module types to include `next()`
delucis Jan 31, 2025
a743cee
deprecated > not required
delucis Feb 4, 2025
ca6f249
More extensive comment
delucis Feb 4, 2025
47988d4
Move route data generation to route component
delucis Feb 5, 2025
50bec23
Add tests for starlightRoute getter
delucis Feb 5, 2025
765beca
Handle route data for SSR route
delucis Feb 5, 2025
0de3e36
Fix missing `next` type in middleware handler type
delucis Feb 5, 2025
ca58aed
Add `order: default` to `addRouteMiddleware` types in docs and tweak …
delucis Feb 5, 2025
9ad43c1
Merge branch 'main' into chris/locals-route-data
delucis Feb 5, 2025
13d2038
Switch to alternative SSR approach more close to what we already did
delucis Feb 5, 2025
883d4a5
Add doc comments to `locals` types
delucis Feb 12, 2025
56621a6
Merge branch 'main' into chris/locals-route-data
delucis Feb 12, 2025
5471975
Improve `starlightRoute` error message
delucis Feb 13, 2025
102bd61
Fix test snapshot of error message
delucis Feb 13, 2025
43b67a3
`this` > `that`
delucis Feb 13, 2025
6d05cd9
Docs pass
delucis Feb 14, 2025
8a41943
Remove demo middleware from docs
delucis Feb 14, 2025
9f3475a
Fix broken links
delucis Feb 14, 2025
bd785d9
Update Docsearch plugin peer dependency version
delucis Feb 14, 2025
8238a86
Add DocSearch plugin changeset
delucis Feb 14, 2025
1820dec
Merge branch 'main' into chris/locals-route-data
delucis Feb 15, 2025
1ffda84
Fix type that got lost in the merge
delucis Feb 15, 2025
0496d99
Removes DocSearch plugin changeset as one was already added to the sa…
delucis Feb 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move route data docs to dedicated reference page
  • Loading branch information
delucis committed Dec 18, 2024
commit 2cc0a8f908a67206826a59052948adffb2089eb4
143 changes: 0 additions & 143 deletions docs/src/content/docs/reference/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,149 +10,6 @@ This page lists all components available to override and links to their default

Learn more in the [Guide to Overriding Components](/guides/overriding-components/).

## Component props

All components can access a standard `Astro.props` object that contains information about the current page.

To type your custom components, import the `Props` type from Starlight:

```astro
---
// src/components/Custom.astro
import type { Props } from '@astrojs/starlight/props';

const { hasSidebar } = Astro.props;
// ^ type: boolean
---
```

This will give you autocomplete and types when accessing `Astro.props`.

### Props

Starlight will pass the following props to your custom components.

#### `dir`

**Type:** `'ltr' | 'rtl'`

Page writing direction.

#### `lang`

**Type:** `string`

BCP-47 language tag for this page’s locale, e.g. `en`, `zh-CN`, or `pt-BR`.

#### `locale`

**Type:** `string | undefined`

The base path at which a language is served. `undefined` for root locale slugs.

#### `siteTitle`

**Type:** `string`

The site title for this page’s locale.

#### `siteTitleHref`

**Type:** `string`

The value for the site title’s `href` attribute, linking back to the homepage, e.g. `/`.
For multilingual sites this will include the current locale, e.g. `/en/` or `/zh-cn/`.

#### `slug`

**Type:** `string`

The slug for this page generated from the content filename.

This property is deprecated and will be removed in a future version of Starlight.
Migrate to the new Content Layer API by using [Starlight’s `docsLoader`](/manual-setup/#configure-content-collections) and use the [`id`](#id) property instead.

#### `id`

**Type:** `string`

The slug for this page or the unique ID for this page based on the content filename if using the [`legacy.collections`](https://docs.astro.build/en/reference/legacy-flags/#collections) flag.

#### `isFallback`

**Type:** `true | undefined`

`true` if this page is untranslated in the current language and using fallback content from the default locale.
Only used in multilingual sites.

#### `entryMeta`

**Type:** `{ dir: 'ltr' | 'rtl'; lang: string }`

Locale metadata for the page content. Can be different from top-level locale values when a page is using fallback content.

#### `entry`

The Astro content collection entry for the current page.
Includes frontmatter values for the current page at `entry.data`.

```ts
entry: {
data: {
title: string;
description: string | undefined;
// etc.
}
}
```

Learn more about the shape of this object in [Astro’s Collection Entry Type](https://docs.astro.build/en/reference/modules/astro-content/#collectionentry) reference.

#### `sidebar`

**Type:** `SidebarEntry[]`

Site navigation sidebar entries for this page.

#### `hasSidebar`

**Type:** `boolean`

Whether or not the sidebar should be displayed on this page.

#### `pagination`

**Type:** `{ prev?: Link; next?: Link }`

Links to the previous and next page in the sidebar if enabled.

#### `toc`

**Type:** `{ minHeadingLevel: number; maxHeadingLevel: number; items: TocItem[] } | undefined`

Table of contents for this page if enabled.

#### `headings`

**Type:** `{ depth: number; slug: string; text: string }[]`

Array of all Markdown headings extracted from the current page.
Use [`toc`](#toc) instead if you want to build a table of contents component that respects Starlight’s configuration options.

#### `lastUpdated`

**Type:** `Date | undefined`

JavaScript `Date` object representing when this page was last updated if enabled.

#### `editUrl`

**Type:** `URL | undefined`

`URL` object for the address where this page can be edited if enabled.

---

## Components

### Head
Expand Down
151 changes: 151 additions & 0 deletions docs/src/content/docs/reference/route-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
title: Route Data Reference
description: The full reference documentation for Starlight’s route data object.
---

Starlight’s route data object contains information about the current page.
Learn more about how Starlight’s data model works in the [“Route Data” guide](/guides/route-data/).

In Astro components, access route data from `Astro.locals.starlightRoute`:

```astro {4}
---
// src/components/Custom.astro

const { hasSidebar } = Astro.locals.starlightRoute;
---
```

In [route middleware](/guides/route-data/#customizing-route-data), access route data from the context object passed to your middleware function:

```ts {5}
// src/routeData.ts
import { defineRouteMiddleware } from '@astrojs/starlight/route-data';

export const onRequest = defineRouteMiddleware((context) => {
const { hasSidebar } = context.locals.starlightRoute;
});
```

## `starlightRoute`

The `starlightRoute` object has the following properties:

### `dir`

**Type:** `'ltr' | 'rtl'`

Page writing direction.

### `lang`

**Type:** `string`

BCP-47 language tag for this page’s locale, e.g. `en`, `zh-CN`, or `pt-BR`.

### `locale`

**Type:** `string | undefined`

The base path at which a language is served. `undefined` for root locale slugs.

### `siteTitle`

**Type:** `string`

The site title for this page’s locale.

### `siteTitleHref`

**Type:** `string`

The value for the site title’s `href` attribute, linking back to the homepage, e.g. `/`.
For multilingual sites this will include the current locale, e.g. `/en/` or `/zh-cn/`.

### `slug`

**Type:** `string`

The slug for this page generated from the content filename.

This property is deprecated and will be removed in a future version of Starlight.
Migrate to the new Content Layer API by using [Starlight’s `docsLoader`](/manual-setup/#configure-content-collections) and use the [`id`](#id) property instead.

### `id`

**Type:** `string`

The slug for this page or the unique ID for this page based on the content filename if using the [`legacy.collections`](https://docs.astro.build/en/reference/legacy-flags/#collections) flag.

### `isFallback`

**Type:** `true | undefined`

`true` if this page is untranslated in the current language and using fallback content from the default locale.
Only used in multilingual sites.

### `entryMeta`

**Type:** `{ dir: 'ltr' | 'rtl'; lang: string }`

Locale metadata for the page content. Can be different from top-level locale values when a page is using fallback content.

### `entry`

The Astro content collection entry for the current page.
Includes frontmatter values for the current page at `entry.data`.

```ts
entry: {
data: {
title: string;
description: string | undefined;
// etc.
}
}
```

Learn more about the shape of this object in [Astro’s Collection Entry Type](https://docs.astro.build/en/reference/modules/astro-content/#collectionentry) reference.

### `sidebar`

**Type:** `SidebarEntry[]`

Site navigation sidebar entries for this page.

### `hasSidebar`

**Type:** `boolean`

Whether or not the sidebar should be displayed on this page.

### `pagination`

**Type:** `{ prev?: Link; next?: Link }`

Links to the previous and next page in the sidebar if enabled.

### `toc`

**Type:** `{ minHeadingLevel: number; maxHeadingLevel: number; items: TocItem[] } | undefined`

Table of contents for this page if enabled.

### `headings`

**Type:** `{ depth: number; slug: string; text: string }[]`

Array of all Markdown headings extracted from the current page.
Use [`toc`](#toc) instead if you want to build a table of contents component that respects Starlight’s configuration options.

### `lastUpdated`

**Type:** `Date | undefined`

JavaScript `Date` object representing when this page was last updated if enabled.

### `editUrl`

**Type:** `URL | undefined`

`URL` object for the address where this page can be edited if enabled.
Loading