starlight-versions 0.3.1 → 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 +44 -0
- package/components/VersionBanner.astro +3 -3
- package/components/VersionNotice.astro +1 -2
- package/components/VersionSearch.astro +66 -26
- package/components/VersionSelect.astro +3 -4
- package/index.ts +11 -3
- package/libs/starlight.ts +4 -4
- package/loader.ts +18 -0
- 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 +13 -15
- 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
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# starlight-versions
|
|
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
|
+
|
|
17
|
+
## 0.4.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [#15](https://github.com/HiDeoo/starlight-versions/pull/15) [`ecd96ed`](https://github.com/HiDeoo/starlight-versions/commit/ecd96ed4aa4474bb418669e8113bb9e1af0f7536) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for Astro v5, drops support for Astro v4.
|
|
22
|
+
|
|
23
|
+
⚠️ **BREAKING CHANGE:** The minimum supported version of Starlight is now `0.30.0`.
|
|
24
|
+
|
|
25
|
+
Please follow the [upgrade guide](https://github.com/withastro/starlight/releases/tag/%40astrojs/starlight%400.30.0) to update your project.
|
|
26
|
+
|
|
27
|
+
After upgrading, you will also need to update the `versions` collection in your `src/content.config.ts` file to use the new `docsVersionsLoader`:
|
|
28
|
+
|
|
29
|
+
```diff
|
|
30
|
+
// src/content.config.ts
|
|
31
|
+
import { defineCollection } from "astro:content";
|
|
32
|
+
import { docsLoader } from "@astrojs/starlight/loaders";
|
|
33
|
+
import { docsSchema } from "@astrojs/starlight/schema";
|
|
34
|
+
-import { docsVersionsSchema } from 'starlight-versions/schema'
|
|
35
|
+
+import { docsVersionsLoader } from 'starlight-versions/loader'
|
|
36
|
+
|
|
37
|
+
export const collections = {
|
|
38
|
+
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
|
|
39
|
+
- versions: defineCollection({ type: 'data', schema: docsVersionsSchema() }),
|
|
40
|
+
+ versions: defineCollection({ loader: docsVersionsLoader() }),
|
|
41
|
+
};
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Note that the [`legacy.collections` flag](https://docs.astro.build/en/reference/legacy-flags/#collections) is not supported by this plugin and you should update your collections to use Astro's new Content Layer API.
|
|
@@ -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'),
|
|
@@ -26,18 +25,22 @@ const pagefindTranslations = {
|
|
|
26
25
|
|
|
27
26
|
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, entry.slug)
|
|
28
27
|
const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
28
|
+
|
|
29
|
+
const dataAttributes: DOMStringMap = {
|
|
30
|
+
'data-pagefind-filter': `version:${pageVersionIdentifier}`,
|
|
31
|
+
'data-translations': JSON.stringify(pagefindTranslations),
|
|
32
|
+
'data-version': pageVersionIdentifier,
|
|
33
|
+
}
|
|
34
|
+
if (project.trailingSlash === 'never') dataAttributes['data-strip-trailing-slash'] = ''
|
|
29
35
|
---
|
|
30
36
|
|
|
31
|
-
<site-search
|
|
32
|
-
data-translations={JSON.stringify(pagefindTranslations)}
|
|
33
|
-
data-strip-trailing-slash={project.trailingSlash === 'never'}
|
|
34
|
-
data-version={pageVersionIdentifier}
|
|
35
|
-
data-pagefind-filter={`version:${pageVersionIdentifier}`}
|
|
36
|
-
>
|
|
37
|
+
<site-search class={Astro.props['class']} {...dataAttributes}>
|
|
37
38
|
<button data-open-modal disabled>
|
|
38
|
-
<Icon name="magnifier"
|
|
39
|
+
<Icon name="magnifier" />
|
|
39
40
|
<span class="sl-hidden md:sl-block" aria-hidden="true">{Astro.locals.t('search.label')}</span>
|
|
40
|
-
<
|
|
41
|
+
<kbd class="sl-hidden md:sl-flex" style="display: none;">
|
|
42
|
+
<kbd>{Astro.locals.t('search.ctrlKey')}</kbd><kbd>K</kbd>
|
|
43
|
+
</kbd>
|
|
41
44
|
</button>
|
|
42
45
|
|
|
43
46
|
<dialog style="padding:0" aria-label={Astro.locals.t('search.label')}>
|
|
@@ -72,6 +75,27 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
72
75
|
</dialog>
|
|
73
76
|
</site-search>
|
|
74
77
|
|
|
78
|
+
{
|
|
79
|
+
/**
|
|
80
|
+
* This is intentionally inlined to avoid briefly showing an invalid shortcut.
|
|
81
|
+
* Purposely using the deprecated `navigator.platform` property to detect Apple devices, as the
|
|
82
|
+
* user agent is spoofed by some browsers when opening the devtools.
|
|
83
|
+
*/
|
|
84
|
+
}
|
|
85
|
+
<script is:inline>
|
|
86
|
+
;(() => {
|
|
87
|
+
const openBtn = document.querySelector('button[data-open-modal]')
|
|
88
|
+
const shortcut = openBtn?.querySelector('kbd')
|
|
89
|
+
if (!openBtn || !(shortcut instanceof HTMLElement)) return
|
|
90
|
+
const platformKey = shortcut.querySelector('kbd')
|
|
91
|
+
if (platformKey && /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) {
|
|
92
|
+
platformKey.textContent = '⌘'
|
|
93
|
+
openBtn.setAttribute('aria-keyshortcuts', 'Meta+K')
|
|
94
|
+
}
|
|
95
|
+
shortcut.style.display = ''
|
|
96
|
+
})()
|
|
97
|
+
</script>
|
|
98
|
+
|
|
75
99
|
<script>
|
|
76
100
|
class SiteSearch extends HTMLElement {
|
|
77
101
|
constructor() {
|
|
@@ -95,7 +119,7 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
95
119
|
document.body.toggleAttribute('data-search-modal-open', true)
|
|
96
120
|
this.querySelector('input')?.focus()
|
|
97
121
|
event?.stopPropagation()
|
|
98
|
-
|
|
122
|
+
globalThis.addEventListener('click', onClick)
|
|
99
123
|
}
|
|
100
124
|
|
|
101
125
|
const closeModal = () => dialog.close()
|
|
@@ -106,20 +130,17 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
106
130
|
|
|
107
131
|
dialog.addEventListener('close', () => {
|
|
108
132
|
document.body.toggleAttribute('data-search-modal-open', false)
|
|
109
|
-
|
|
133
|
+
globalThis.removeEventListener('click', onClick)
|
|
110
134
|
})
|
|
111
135
|
|
|
112
|
-
// Listen for
|
|
113
|
-
|
|
114
|
-
const isInput =
|
|
115
|
-
document.activeElement instanceof HTMLElement &&
|
|
116
|
-
(['input', 'select', 'textarea'].includes(document.activeElement.tagName.toLowerCase()) ||
|
|
117
|
-
document.activeElement.isContentEditable)
|
|
136
|
+
// Listen for `ctrl + k` and `cmd + k` keyboard shortcuts.
|
|
137
|
+
globalThis.addEventListener('keydown', (e) => {
|
|
118
138
|
if ((e.metaKey === true || e.ctrlKey === true) && e.key === 'k') {
|
|
119
|
-
dialog.open
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
139
|
+
if (dialog.open) {
|
|
140
|
+
closeModal()
|
|
141
|
+
} else {
|
|
142
|
+
openModal()
|
|
143
|
+
}
|
|
123
144
|
e.preventDefault()
|
|
124
145
|
}
|
|
125
146
|
})
|
|
@@ -135,9 +156,9 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
135
156
|
const formatURL = shouldStrip ? this.stripTrailingSlash : (path: string) => path
|
|
136
157
|
const version = this.dataset['version'] ?? 'current'
|
|
137
158
|
|
|
138
|
-
|
|
159
|
+
globalThis.addEventListener('DOMContentLoaded', () => {
|
|
139
160
|
if (import.meta.env.DEV) return
|
|
140
|
-
const onIdle =
|
|
161
|
+
const onIdle = globalThis.requestIdleCallback || ((cb) => setTimeout(cb, 1))
|
|
141
162
|
onIdle(async () => {
|
|
142
163
|
// @ts-expect-error — Missing types for @pagefind/default-ui package.
|
|
143
164
|
const { PagefindUI } = await import('@pagefind/default-ui')
|
|
@@ -189,7 +210,7 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
189
210
|
border: 1px solid var(--sl-color-gray-5);
|
|
190
211
|
border-radius: 0.5rem;
|
|
191
212
|
padding-inline-start: 0.75rem;
|
|
192
|
-
padding-inline-end:
|
|
213
|
+
padding-inline-end: 0.5rem;
|
|
193
214
|
background-color: var(--sl-color-black);
|
|
194
215
|
color: var(--sl-color-gray-2);
|
|
195
216
|
font-size: var(--sl-text-sm);
|
|
@@ -206,6 +227,18 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
206
227
|
}
|
|
207
228
|
}
|
|
208
229
|
|
|
230
|
+
button > kbd {
|
|
231
|
+
border-radius: 0.25rem;
|
|
232
|
+
font-size: var(--sl-text-2xs);
|
|
233
|
+
gap: 0.25em;
|
|
234
|
+
padding-inline: 0.375rem;
|
|
235
|
+
background-color: var(--sl-color-gray-6);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
kbd {
|
|
239
|
+
font-family: var(--__sl-font);
|
|
240
|
+
}
|
|
241
|
+
|
|
209
242
|
dialog {
|
|
210
243
|
margin: 0;
|
|
211
244
|
background-color: var(--sl-color-gray-6);
|
|
@@ -217,7 +250,7 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
217
250
|
box-shadow: var(--sl-shadow-lg);
|
|
218
251
|
}
|
|
219
252
|
dialog[open] {
|
|
220
|
-
display:
|
|
253
|
+
display: flex;
|
|
221
254
|
}
|
|
222
255
|
|
|
223
256
|
dialog::backdrop {
|
|
@@ -227,7 +260,10 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
227
260
|
}
|
|
228
261
|
|
|
229
262
|
.dialog-frame {
|
|
263
|
+
position: relative;
|
|
264
|
+
overflow: auto;
|
|
230
265
|
flex-direction: column;
|
|
266
|
+
flex-grow: 1;
|
|
231
267
|
gap: 1rem;
|
|
232
268
|
padding: 1rem;
|
|
233
269
|
}
|
|
@@ -383,6 +419,10 @@ const pageVersionIdentifier = getVersionIdentifier(pageVersion)
|
|
|
383
419
|
border-radius: 0 0 var(--sl-search-corners) var(--sl-search-corners);
|
|
384
420
|
}
|
|
385
421
|
|
|
422
|
+
#starlight__search .pagefind-ui__result-inner > .pagefind-ui__result-excerpt {
|
|
423
|
+
display: none;
|
|
424
|
+
}
|
|
425
|
+
|
|
386
426
|
#starlight__search .pagefind-ui__result-inner > .pagefind-ui__result-title {
|
|
387
427
|
padding: var(--sl-search-result-pad-block) var(--sl-search-result-pad-inline-end);
|
|
388
428
|
padding-inline-start: var(--sl-search-result-pad-inline-start);
|
|
@@ -1,14 +1,13 @@
|
|
|
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 {
|
|
8
|
+
const { id } = Astro.locals.starlightRoute
|
|
10
9
|
|
|
11
|
-
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
|
|
10
|
+
const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig, id)
|
|
12
11
|
---
|
|
13
12
|
|
|
14
13
|
<starlight-version-select>
|
|
@@ -106,7 +105,7 @@ const pageVersion = getVersionFromSlug(starlightVersionsConfig, starlightConfig,
|
|
|
106
105
|
|
|
107
106
|
select?.addEventListener('change', (event) => {
|
|
108
107
|
if (event.currentTarget instanceof HTMLSelectElement) {
|
|
109
|
-
|
|
108
|
+
globalThis.location.pathname = event.currentTarget.value
|
|
110
109
|
}
|
|
111
110
|
})
|
|
112
111
|
|
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/loader.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { glob, type Loader } from 'astro/loaders'
|
|
2
|
+
|
|
3
|
+
import { docsVersionsSchema } from './schema'
|
|
4
|
+
|
|
5
|
+
const extensions = ['json', 'yml', 'yaml']
|
|
6
|
+
|
|
7
|
+
export function docsVersionsLoader(): Loader {
|
|
8
|
+
return {
|
|
9
|
+
name: 'starlight-versions-loader',
|
|
10
|
+
load: (context) => {
|
|
11
|
+
return glob({
|
|
12
|
+
base: `${context.config.srcDir.pathname.replace(context.config.root.pathname, '')}content/versions`,
|
|
13
|
+
pattern: `**/[^_]*.{${extensions.join(',')}}`,
|
|
14
|
+
}).load(context)
|
|
15
|
+
},
|
|
16
|
+
schema: docsVersionsSchema(),
|
|
17
|
+
}
|
|
18
|
+
}
|
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,52 +1,50 @@
|
|
|
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)",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./index.ts",
|
|
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
|
},
|
|
25
22
|
"dependencies": {
|
|
26
|
-
"@pagefind/default-ui": "^1.0
|
|
23
|
+
"@pagefind/default-ui": "^1.2.0",
|
|
27
24
|
"github-slugger": "^2.0.0",
|
|
28
|
-
"mdast-util-mdx-jsx": "^3.1.
|
|
25
|
+
"mdast-util-mdx-jsx": "^3.1.3",
|
|
29
26
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
30
27
|
"remark": "^15.0.1",
|
|
31
28
|
"remark-frontmatter": "^5.0.0",
|
|
32
|
-
"remark-mdx": "^3.0
|
|
29
|
+
"remark-mdx": "^3.1.0",
|
|
33
30
|
"unist-util-visit": "^5.0.0",
|
|
34
|
-
"vfile": "^6.0.
|
|
35
|
-
"yaml": "^2.
|
|
31
|
+
"vfile": "^6.0.3",
|
|
32
|
+
"yaml": "^2.6.1"
|
|
36
33
|
},
|
|
37
34
|
"devDependencies": {
|
|
38
35
|
"@types/mdast": "^4.0.4",
|
|
39
36
|
"fast-glob": "^3.3.2",
|
|
40
|
-
"vitest": "
|
|
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"
|
|
47
44
|
},
|
|
48
45
|
"publishConfig": {
|
|
49
|
-
"access": "public"
|
|
46
|
+
"access": "public",
|
|
47
|
+
"provenance": true
|
|
50
48
|
},
|
|
51
49
|
"sideEffects": false,
|
|
52
50
|
"keywords": [
|
|
@@ -66,6 +64,6 @@
|
|
|
66
64
|
"bugs": "https://github.com/HiDeoo/starlight-versions/issues",
|
|
67
65
|
"scripts": {
|
|
68
66
|
"test": "vitest",
|
|
69
|
-
"lint": "
|
|
67
|
+
"lint": "eslint . --cache --max-warnings=0"
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -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>
|