starlight-versions 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/components/VersionBanner.astro +3 -3
- package/components/VersionNotice.astro +1 -2
- package/components/VersionSearch.astro +1 -2
- package/components/VersionSelect.astro +1 -2
- package/index.ts +11 -3
- package/libs/starlight.ts +4 -4
- package/middleware.ts +33 -0
- package/overrides/Banner.astro +2 -3
- package/overrides/PageTitle.astro +2 -3
- package/overrides/Search.astro +1 -3
- package/overrides/ThemeSelect.astro +2 -3
- package/package.json +3 -6
- package/components/VersionPagination.astro +0 -34
- package/components/VersionSidebar.astro +0 -15
- package/overrides/Pagination.astro +0 -7
- package/overrides/Sidebar.astro +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# starlight-versions
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#18](https://github.com/HiDeoo/starlight-versions/pull/18) [`a68d559`](https://github.com/HiDeoo/starlight-versions/commit/a68d55958731e03d6c3b6ddf04eb5775a75a6862) Thanks [@HiDeoo](https://github.com/HiDeoo)! - ⚠️ **BREAKING CHANGE:** The Starlight Versions plugin no longer [overrides](https://starlight.astro.build/guides/overriding-components/) the [`<Sidebar>`](https://starlight.astro.build/reference/overrides/#sidebar) and [`<Pagination>`](https://starlight.astro.build/reference/overrides/#pagination) components. If you were manually rendering `starlight-versions/components/VersionSidebar.astro` or `starlight-versions/components/VersionPagination.astro` in a custom override, you can now remove them.
|
|
8
|
+
|
|
9
|
+
- [#18](https://github.com/HiDeoo/starlight-versions/pull/18) [`a68d559`](https://github.com/HiDeoo/starlight-versions/commit/a68d55958731e03d6c3b6ddf04eb5775a75a6862) Thanks [@HiDeoo](https://github.com/HiDeoo)! - ⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now version `0.32.0`.
|
|
10
|
+
|
|
11
|
+
Please use the `@astrojs/upgrade` command to upgrade your project:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx @astrojs/upgrade
|
|
15
|
+
```
|
|
16
|
+
|
|
3
17
|
## 0.4.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
3
2
|
import starlightConfig from 'virtual:starlight/user-config'
|
|
4
3
|
import starlightVersionsConfig from 'virtual:starlight-versions-config'
|
|
5
4
|
|
|
6
5
|
import { getVersionFromSlug, getVersionURL } from '../libs/versions'
|
|
7
6
|
|
|
8
|
-
const {
|
|
7
|
+
const { entry } = Astro.locals.starlightRoute
|
|
8
|
+
const { template } = Astro.locals.starlightRoute.entry.data
|
|
9
9
|
|
|
10
|
-
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
|
|
10
|
+
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, entry.slug)
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
{
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { Icon } from '@astrojs/starlight/components'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
3
|
import starlightConfig from 'virtual:starlight/user-config'
|
|
5
4
|
import starlightVersionsConfig from 'virtual:starlight-versions-config'
|
|
6
5
|
|
|
7
6
|
import { getVersionFromSlug, getVersionURL } from '../libs/versions'
|
|
8
7
|
|
|
9
|
-
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, Astro.
|
|
8
|
+
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, Astro.locals.starlightRoute.entry.slug)
|
|
10
9
|
---
|
|
11
10
|
|
|
12
11
|
{
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { Icon } from '@astrojs/starlight/components'
|
|
8
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
9
8
|
import '@pagefind/default-ui/css/ui.css'
|
|
10
9
|
import project from 'virtual:starlight/project-context'
|
|
11
10
|
import starlightConfig from 'virtual:starlight/user-config'
|
|
@@ -13,7 +12,7 @@ import starlightVersionsConfig from 'virtual:starlight-versions-config'
|
|
|
13
12
|
|
|
14
13
|
import { getVersionFromSlug, getVersionIdentifier, getVersionURL } from '../libs/versions'
|
|
15
14
|
|
|
16
|
-
const { entry } = Astro.
|
|
15
|
+
const { entry } = Astro.locals.starlightRoute
|
|
17
16
|
|
|
18
17
|
const pagefindTranslations = {
|
|
19
18
|
placeholder: Astro.locals.t('search.label'),
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { Icon } from '@astrojs/starlight/components'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
3
|
import starlightConfig from 'virtual:starlight/user-config'
|
|
5
4
|
import starlightVersionsConfig from 'virtual:starlight-versions-config'
|
|
6
5
|
|
|
7
6
|
import { getVersionFromSlug, getVersionURL } from '../libs/versions'
|
|
8
7
|
|
|
9
|
-
const { id } = Astro.
|
|
8
|
+
const { id } = Astro.locals.starlightRoute
|
|
10
9
|
|
|
11
10
|
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, id)
|
|
12
11
|
---
|
package/index.ts
CHANGED
|
@@ -21,7 +21,15 @@ export default function starlightVersionsPlugin(userConfig: StarlightVersionsUse
|
|
|
21
21
|
return {
|
|
22
22
|
name: 'starlight-versions-plugin',
|
|
23
23
|
hooks: {
|
|
24
|
-
async setup({
|
|
24
|
+
async 'config:setup'({
|
|
25
|
+
addIntegration,
|
|
26
|
+
addRouteMiddleware,
|
|
27
|
+
astroConfig,
|
|
28
|
+
command,
|
|
29
|
+
config: starlightConfig,
|
|
30
|
+
logger,
|
|
31
|
+
updateConfig,
|
|
32
|
+
}) {
|
|
25
33
|
if (command !== 'dev' && command !== 'build') return
|
|
26
34
|
|
|
27
35
|
try {
|
|
@@ -33,6 +41,8 @@ export default function starlightVersionsPlugin(userConfig: StarlightVersionsUse
|
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
try {
|
|
44
|
+
addRouteMiddleware({ entrypoint: 'starlight-versions/middleware' })
|
|
45
|
+
|
|
36
46
|
const versionedSidebar = await getVersionedSidebar(config, starlightConfig.sidebar, astroConfig.srcDir)
|
|
37
47
|
|
|
38
48
|
updateConfig({
|
|
@@ -40,8 +50,6 @@ export default function starlightVersionsPlugin(userConfig: StarlightVersionsUse
|
|
|
40
50
|
starlightConfig,
|
|
41
51
|
[
|
|
42
52
|
{ name: 'ThemeSelect', fallback: 'VersionSelect' },
|
|
43
|
-
{ name: 'Sidebar', fallback: 'VersionSidebar' },
|
|
44
|
-
{ name: 'Pagination', fallback: 'VersionPagination' },
|
|
45
53
|
{ name: 'Search', fallback: 'VersionSearch' },
|
|
46
54
|
{ name: 'PageTitle', fallback: 'VersionNotice' },
|
|
47
55
|
{ name: 'Banner', fallback: 'VersionBanner' },
|
package/libs/starlight.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import url from 'node:url'
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { StarlightRouteData } from '@astrojs/starlight/route-data'
|
|
5
5
|
import type { docsSchema } from '@astrojs/starlight/schema'
|
|
6
|
-
import type {
|
|
6
|
+
import type { HookParameters } from '@astrojs/starlight/types'
|
|
7
7
|
import type { z } from 'astro/zod'
|
|
8
8
|
import yaml from 'yaml'
|
|
9
9
|
|
|
@@ -93,7 +93,7 @@ interface StarlightFrontmatteHero {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
export type StarlightUserConfig =
|
|
96
|
+
export type StarlightUserConfig = HookParameters<'config:setup'>['config']
|
|
97
97
|
export type StarlightSidebarUserConfig = StarlightUserConfig['sidebar']
|
|
98
98
|
|
|
99
|
-
export type StarlightSidebar =
|
|
99
|
+
export type StarlightSidebar = StarlightRouteData['sidebar']
|
package/middleware.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineRouteMiddleware, type StarlightRouteData } from '@astrojs/starlight/route-data'
|
|
2
|
+
import starlightConfig from 'virtual:starlight/user-config'
|
|
3
|
+
import starlightVersionsConfig from 'virtual:starlight-versions-config'
|
|
4
|
+
|
|
5
|
+
import { getVersionFromPaginationLink, getVersionFromSlug, getVersionSidebar, type Version } from './libs/versions'
|
|
6
|
+
|
|
7
|
+
export const onRequest = defineRouteMiddleware((context) => {
|
|
8
|
+
const { starlightRoute } = context.locals
|
|
9
|
+
const { entry, locale, pagination, sidebar } = starlightRoute
|
|
10
|
+
|
|
11
|
+
starlightRoute.sidebar = getVersionSidebar(
|
|
12
|
+
getVersionFromSlug(starlightVersionsConfig, starlightConfig, entry.slug),
|
|
13
|
+
sidebar,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, entry.slug)
|
|
17
|
+
|
|
18
|
+
starlightRoute.pagination.prev = getPaginationLink(locale, pageVersion, pagination.prev)
|
|
19
|
+
starlightRoute.pagination.next = getPaginationLink(locale, pageVersion, pagination.next)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
function getPaginationLink(locale: string | undefined, currentVersion: Version | undefined, link: PaginationLink) {
|
|
23
|
+
if (!link) return undefined
|
|
24
|
+
|
|
25
|
+
const linkVersion = getVersionFromPaginationLink(starlightVersionsConfig, link.href, locale)
|
|
26
|
+
|
|
27
|
+
// If the current version is not the same as the link version, remove the link.
|
|
28
|
+
return (currentVersion === undefined && linkVersion === undefined) || currentVersion?.slug === linkVersion?.slug
|
|
29
|
+
? link
|
|
30
|
+
: undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type PaginationLink = StarlightRouteData['pagination']['next']
|
package/overrides/Banner.astro
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
import Default from '@astrojs/starlight/components/Banner.astro'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
3
|
|
|
5
4
|
import VersionBanner from '../components/VersionBanner.astro'
|
|
6
5
|
---
|
|
7
6
|
|
|
8
|
-
<VersionBanner
|
|
9
|
-
<Default
|
|
7
|
+
<VersionBanner />
|
|
8
|
+
<Default><slot /></Default>
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
import Default from '@astrojs/starlight/components/PageTitle.astro'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
3
|
|
|
5
4
|
import VersionNotice from '../components/VersionNotice.astro'
|
|
6
5
|
---
|
|
7
6
|
|
|
8
|
-
<Default
|
|
9
|
-
<VersionNotice
|
|
7
|
+
<Default><slot /></Default>
|
|
8
|
+
<VersionNotice />
|
package/overrides/Search.astro
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
import Default from '@astrojs/starlight/components/ThemeSelect.astro'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
3
|
|
|
5
4
|
import VersionSelect from '../components/VersionSelect.astro'
|
|
6
5
|
---
|
|
7
6
|
|
|
8
|
-
<VersionSelect
|
|
9
|
-
<Default
|
|
7
|
+
<VersionSelect />
|
|
8
|
+
<Default><slot /></Default>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-versions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Starlight plugin to version documentation pages.",
|
|
6
6
|
"author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",
|
|
@@ -10,15 +10,12 @@
|
|
|
10
10
|
"./loader": "./loader.ts",
|
|
11
11
|
"./components/VersionBanner.astro": "./components/VersionBanner.astro",
|
|
12
12
|
"./components/VersionNotice.astro": "./components/VersionNotice.astro",
|
|
13
|
-
"./components/VersionPagination.astro": "./components/VersionPagination.astro",
|
|
14
13
|
"./components/VersionSearch.astro": "./components/VersionSearch.astro",
|
|
15
14
|
"./components/VersionSelect.astro": "./components/VersionSelect.astro",
|
|
16
|
-
"./
|
|
15
|
+
"./middleware": "./middleware.ts",
|
|
17
16
|
"./overrides/Banner.astro": "./overrides/Banner.astro",
|
|
18
17
|
"./overrides/PageTitle.astro": "./overrides/PageTitle.astro",
|
|
19
|
-
"./overrides/Pagination.astro": "./overrides/Pagination.astro",
|
|
20
18
|
"./overrides/Search.astro": "./overrides/Search.astro",
|
|
21
|
-
"./overrides/Sidebar.astro": "./overrides/Sidebar.astro",
|
|
22
19
|
"./overrides/ThemeSelect.astro": "./overrides/ThemeSelect.astro",
|
|
23
20
|
"./package.json": "./package.json"
|
|
24
21
|
},
|
|
@@ -40,7 +37,7 @@
|
|
|
40
37
|
"vitest": "2.1.6"
|
|
41
38
|
},
|
|
42
39
|
"peerDependencies": {
|
|
43
|
-
"@astrojs/starlight": ">=0.
|
|
40
|
+
"@astrojs/starlight": ">=0.32.0"
|
|
44
41
|
},
|
|
45
42
|
"engines": {
|
|
46
43
|
"node": ">=18"
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import Default from '@astrojs/starlight/components/Pagination.astro'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
|
-
import starlightConfig from 'virtual:starlight/user-config'
|
|
5
|
-
import starlightVersionsConfig from 'virtual:starlight-versions-config'
|
|
6
|
-
|
|
7
|
-
import { getVersionFromPaginationLink, getVersionFromSlug } from '../libs/versions'
|
|
8
|
-
import type { Version } from '../libs/versions'
|
|
9
|
-
|
|
10
|
-
const { entry, locale, pagination } = Astro.props
|
|
11
|
-
|
|
12
|
-
type PaginationLink = typeof Astro.props.pagination.next
|
|
13
|
-
|
|
14
|
-
function getPaginationLink(currentVersion: Version | undefined, link: PaginationLink) {
|
|
15
|
-
if (!link) return undefined
|
|
16
|
-
|
|
17
|
-
const linkVersion = getVersionFromPaginationLink(starlightVersionsConfig, link.href, locale)
|
|
18
|
-
|
|
19
|
-
// If the current version is not the same as the link version, remove the link.
|
|
20
|
-
return (currentVersion === undefined && linkVersion === undefined) || currentVersion?.slug === linkVersion?.slug
|
|
21
|
-
? link
|
|
22
|
-
: undefined
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, entry.slug)
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
<Default
|
|
29
|
-
{...Astro.props}
|
|
30
|
-
pagination={{
|
|
31
|
-
prev: getPaginationLink(pageVersion, pagination.prev),
|
|
32
|
-
next: getPaginationLink(pageVersion, pagination.next),
|
|
33
|
-
}}><slot /></Default
|
|
34
|
-
>
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import Default from '@astrojs/starlight/components/Sidebar.astro'
|
|
3
|
-
import type { Props } from '@astrojs/starlight/props'
|
|
4
|
-
import starlightConfig from 'virtual:starlight/user-config'
|
|
5
|
-
import starlightVersionsConfig from 'virtual:starlight-versions-config'
|
|
6
|
-
|
|
7
|
-
import { getVersionFromSlug, getVersionSidebar } from '../libs/versions'
|
|
8
|
-
|
|
9
|
-
const sidebar = getVersionSidebar(
|
|
10
|
-
getVersionFromSlug(starlightVersionsConfig, starlightConfig, Astro.props.entry.slug),
|
|
11
|
-
Astro.props.sidebar,
|
|
12
|
-
)
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
<Default {...Astro.props} {sidebar}><slot /></Default>
|