starlight-versions 0.10.0 → 0.10.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 +6 -0
- package/libs/fs.ts +16 -8
- package/libs/markdown.ts +3 -0
- package/libs/versions.ts +14 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# starlight-versions
|
|
2
2
|
|
|
3
|
+
## 0.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#80](https://github.com/HiDeoo/starlight-versions/pull/80) [`dd385c8`](https://github.com/HiDeoo/starlight-versions/commit/dd385c88940cc36e5733d0f082a04907f44bb2f0) Thanks [@kozmagabor](https://github.com/kozmagabor)! - Fixes versioning of assets stored alongside documentation pages.
|
|
8
|
+
|
|
3
9
|
## 0.10.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/libs/fs.ts
CHANGED
|
@@ -32,13 +32,17 @@ export async function copyDirectory(sourceDir: URL, destDir: URL, callback: Copy
|
|
|
32
32
|
await copyDirectory(source, dest, callback, false)
|
|
33
33
|
} else if (entry.isFile()) {
|
|
34
34
|
const source = new URL(entry.name, sourceDir)
|
|
35
|
-
const content = await fs.readFile(source, 'utf8')
|
|
36
35
|
|
|
37
|
-
const updatedContent = await callback({ type: 'file',
|
|
36
|
+
const updatedContent = await callback({ type: 'file', url: source })
|
|
37
|
+
if (updatedContent === true) continue
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const dest = new URL(entry.name, destDir)
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
if (updatedContent === undefined) {
|
|
42
|
+
await copyFile(source, dest)
|
|
43
|
+
} else if (typeof updatedContent === 'string') {
|
|
44
|
+
await fs.writeFile(dest, updatedContent)
|
|
45
|
+
}
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
}
|
|
@@ -72,8 +76,12 @@ export async function isDirectoryEntry(entry: Dirent) {
|
|
|
72
76
|
return stats.isDirectory()
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Defines how entries are handled when copying a directory with `copyDirectory()`.
|
|
81
|
+
*
|
|
82
|
+
* - For files, return `undefined` to copy as-is, a string to write transformed content, or `true` to skip.
|
|
83
|
+
* - For directories, return `undefined` to use the default destination, a `URL` to override it, or `true` to skip.
|
|
84
|
+
*/
|
|
75
85
|
export type CopyDirectoryCallback = (
|
|
76
|
-
entry:
|
|
77
|
-
|
|
78
|
-
| { type: 'directory'; name: string; isRoot: boolean; source: URL; dest: URL },
|
|
79
|
-
) => Promise<string | boolean | URL>
|
|
86
|
+
entry: { type: 'file'; url: URL } | { type: 'directory'; name: string; isRoot: boolean; source: URL; dest: URL },
|
|
87
|
+
) => Promise<string | true | URL | undefined>
|
package/libs/markdown.ts
CHANGED
|
@@ -246,8 +246,10 @@ function addVersionToLink(link: string, file: VFile) {
|
|
|
246
246
|
|
|
247
247
|
function addVersionToAstroAsset(asset: string, file: VFile) {
|
|
248
248
|
assert.ok(file.data.version, 'A version must be provided to add a version to an Astro asset.')
|
|
249
|
+
assert.ok(file.data.docsDir, 'A docs directory must be provided to add a version to an Astro asset.')
|
|
249
250
|
|
|
250
251
|
const source = new URL(asset, file.data.url)
|
|
252
|
+
if (source.href.startsWith(file.data.docsDir.href)) return asset
|
|
251
253
|
|
|
252
254
|
const segments = asset.split('/')
|
|
253
255
|
segments.splice(-1, 0, file.data.version.slug)
|
|
@@ -287,6 +289,7 @@ function isPublicAsset(asset: string) {
|
|
|
287
289
|
export interface TransformContext {
|
|
288
290
|
assets: VersionAsset[]
|
|
289
291
|
base: string
|
|
292
|
+
docsDir: URL
|
|
290
293
|
excludedSlugs: string[]
|
|
291
294
|
locale: string | undefined
|
|
292
295
|
publicDir: URL
|
package/libs/versions.ts
CHANGED
|
@@ -40,6 +40,9 @@ import {
|
|
|
40
40
|
|
|
41
41
|
const currentVersionSidebarGroupLabel = Symbol('StarlightVersionsCurrentVersionSidebarGroupLabel')
|
|
42
42
|
|
|
43
|
+
// https://github.com/withastro/starlight/blob/23207221169b31e0cc210451a39a19c80fa1f69e/packages/starlight/loaders.ts#L6
|
|
44
|
+
const docsExtensions = new Set(['.markdown', '.mdown', '.mkdn', '.mkd', '.mdwn', '.md', '.mdx'])
|
|
45
|
+
|
|
43
46
|
export const VersionBaseSchema = z.object({
|
|
44
47
|
/**
|
|
45
48
|
* The version redirect strategy used when navigating to this version:
|
|
@@ -105,7 +108,7 @@ export async function ensureNewVersion(
|
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
// Do not skip other non-root directories.
|
|
108
|
-
return
|
|
111
|
+
return
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
// Skip root version directories.
|
|
@@ -114,19 +117,21 @@ export async function ensureNewVersion(
|
|
|
114
117
|
const localeDir = locales.find((locale) => locale === entry.name)
|
|
115
118
|
|
|
116
119
|
// Copy root directories not matching any locale.
|
|
117
|
-
if (!localeDir) return
|
|
120
|
+
if (!localeDir) return
|
|
118
121
|
|
|
119
122
|
// Otherwise, swap the locale and version directories.
|
|
120
123
|
return new URL(`../../${localeDir}/${newVersion.slug}/`, entry.dest)
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
if (
|
|
126
|
+
if (!docsExtensions.has(getExtension(entry.url.pathname))) return
|
|
127
|
+
if (excludedDocs.has(getDocPath(docsDir, entry.url))) return true
|
|
124
128
|
|
|
125
129
|
const slug = getDocSlug(docsDir, entry.url)
|
|
126
130
|
|
|
127
|
-
const md = await transformMarkdown(entry.
|
|
131
|
+
const md = await transformMarkdown(await fs.readFile(entry.url, 'utf8'), {
|
|
128
132
|
assets: [],
|
|
129
133
|
base: stripTrailingSlash(astroConfig.base),
|
|
134
|
+
docsDir,
|
|
130
135
|
excludedSlugs,
|
|
131
136
|
locale: getDocLocale(slug, starlightConfig),
|
|
132
137
|
publicDir: astroConfig.publicDir,
|
|
@@ -497,7 +502,11 @@ async function getExcludedDocs(config: StarlightVersionsConfig, locales: string[
|
|
|
497
502
|
continue
|
|
498
503
|
}
|
|
499
504
|
|
|
500
|
-
if (
|
|
505
|
+
if (
|
|
506
|
+
!entry.isFile() ||
|
|
507
|
+
!docsExtensions.has(getExtension(docPath)) ||
|
|
508
|
+
!config.exclude.some((excludeGlob) => path.posix.matchesGlob(docPath, excludeGlob))
|
|
509
|
+
) {
|
|
501
510
|
continue
|
|
502
511
|
}
|
|
503
512
|
|