starlight-versions 0.4.0 → 0.5.1
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 +20 -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 +12 -4
- package/libs/markdown.ts +12 -0
- package/libs/starlight.ts +4 -4
- package/libs/versions.ts +5 -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,25 @@
|
|
|
1
1
|
# starlight-versions
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#21](https://github.com/HiDeoo/starlight-versions/pull/21) [`42be6e3`](https://github.com/HiDeoo/starlight-versions/commit/42be6e30a54fcdd5bec0959b7f354a1bc3954c14) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes a potential link generation issue when using the Astro [`base`](https://docs.astro.build/en/reference/configuration-reference/#base) option.
|
|
8
|
+
|
|
9
|
+
## 0.5.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#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.
|
|
14
|
+
|
|
15
|
+
- [#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`.
|
|
16
|
+
|
|
17
|
+
Please use the `@astrojs/upgrade` command to upgrade your project:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npx @astrojs/upgrade
|
|
21
|
+
```
|
|
22
|
+
|
|
3
23
|
## 0.4.0
|
|
4
24
|
|
|
5
25
|
### 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,11 +21,19 @@ 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 {
|
|
28
|
-
await ensureNewVersion(config, starlightConfig, astroConfig
|
|
36
|
+
await ensureNewVersion(config, starlightConfig, astroConfig, logger)
|
|
29
37
|
} catch (error) {
|
|
30
38
|
throwPluginError(
|
|
31
39
|
error instanceof Error ? error.message : 'An error occurred while creating a new documentation version.',
|
|
@@ -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/markdown.ts
CHANGED
|
@@ -187,9 +187,20 @@ function handleImports(node: MdxjsEsm, file: VFile) {
|
|
|
187
187
|
function addVersionToLink(link: string, file: VFile) {
|
|
188
188
|
assert(file.data.version, 'A version must be provided to add a version to an Astro asset.')
|
|
189
189
|
|
|
190
|
+
const base = file.data.base ?? ''
|
|
191
|
+
const hasBase = file.data.base && link.startsWith(file.data.base)
|
|
192
|
+
|
|
193
|
+
if (hasBase) {
|
|
194
|
+
link = link.replace(base, '')
|
|
195
|
+
}
|
|
196
|
+
|
|
190
197
|
const segments = link.split('/')
|
|
191
198
|
segments.splice(1, 0, file.data.version.slug)
|
|
192
199
|
|
|
200
|
+
if (hasBase) {
|
|
201
|
+
segments.splice(1, 0, stripLeadingSlash(base))
|
|
202
|
+
}
|
|
203
|
+
|
|
193
204
|
return segments.join('/')
|
|
194
205
|
}
|
|
195
206
|
|
|
@@ -235,6 +246,7 @@ function isPublicAsset(asset: string) {
|
|
|
235
246
|
|
|
236
247
|
export interface TransformContext {
|
|
237
248
|
assets: VersionAsset[]
|
|
249
|
+
base: string
|
|
238
250
|
locale: string | undefined
|
|
239
251
|
slug: string
|
|
240
252
|
url: URL
|
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/libs/versions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StarlightConfig } from '@astrojs/starlight/types'
|
|
2
|
-
import type { AstroIntegrationLogger } from 'astro'
|
|
2
|
+
import type { AstroConfig, AstroIntegrationLogger } from 'astro'
|
|
3
3
|
import { z } from 'astro/zod'
|
|
4
4
|
|
|
5
5
|
import type { StarlightVersionsConfig } from '..'
|
|
@@ -55,10 +55,10 @@ export const VersionSchema = z
|
|
|
55
55
|
export async function ensureNewVersion(
|
|
56
56
|
config: StarlightVersionsConfig,
|
|
57
57
|
starlightConfig: StarlightUserConfig,
|
|
58
|
-
|
|
58
|
+
astroConfig: AstroConfig,
|
|
59
59
|
logger: AstroIntegrationLogger,
|
|
60
60
|
) {
|
|
61
|
-
const docsDir = new URL('content/docs/', srcDir)
|
|
61
|
+
const docsDir = new URL('content/docs/', astroConfig.srcDir)
|
|
62
62
|
const newVersion = await checkForNewVersion(config, docsDir)
|
|
63
63
|
const locales = Object.keys(starlightConfig.locales ?? {})
|
|
64
64
|
|
|
@@ -98,6 +98,7 @@ export async function ensureNewVersion(
|
|
|
98
98
|
|
|
99
99
|
const md = await transformMarkdown(entry.content, {
|
|
100
100
|
assets: [],
|
|
101
|
+
base: stripTrailingSlash(astroConfig.base),
|
|
101
102
|
locale: getDocLocale(slug, starlightConfig),
|
|
102
103
|
slug,
|
|
103
104
|
url: entry.url,
|
|
@@ -113,7 +114,7 @@ export async function ensureNewVersion(
|
|
|
113
114
|
await copyFile(asset.source, asset.dest)
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
await makeVersionConfig(newVersion, starlightConfig, srcDir)
|
|
117
|
+
await makeVersionConfig(newVersion, starlightConfig, astroConfig.srcDir)
|
|
117
118
|
|
|
118
119
|
logger.info(`Created new version '${newVersion.slug}'.`)
|
|
119
120
|
}
|
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.1",
|
|
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>
|