starlight-versions 0.5.0 → 0.5.2
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 +12 -0
- package/index.ts +1 -1
- package/libs/fs.ts +13 -1
- package/libs/markdown.ts +12 -0
- package/libs/versions.ts +21 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# starlight-versions
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#24](https://github.com/HiDeoo/starlight-versions/pull/24) [`113cb97`](https://github.com/HiDeoo/starlight-versions/commit/113cb975b6acc3dc3dc6d1c252048e62248dc9ed) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Fixes an issue with symlinked version directories.
|
|
8
|
+
|
|
9
|
+
## 0.5.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#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.
|
|
14
|
+
|
|
3
15
|
## 0.5.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/index.ts
CHANGED
|
@@ -33,7 +33,7 @@ export default function starlightVersionsPlugin(userConfig: StarlightVersionsUse
|
|
|
33
33
|
if (command !== 'dev' && command !== 'build') return
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
-
await ensureNewVersion(config, starlightConfig, astroConfig
|
|
36
|
+
await ensureNewVersion(config, starlightConfig, astroConfig, logger)
|
|
37
37
|
} catch (error) {
|
|
38
38
|
throwPluginError(
|
|
39
39
|
error instanceof Error ? error.message : 'An error occurred while creating a new documentation version.',
|
package/libs/fs.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { PathLike } from 'node:fs'
|
|
1
|
+
import type { Dirent, PathLike } from 'node:fs'
|
|
2
2
|
import fs from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
3
4
|
|
|
4
5
|
import { ensureTrailingSlash } from './path'
|
|
5
6
|
|
|
@@ -60,6 +61,17 @@ export function ensureDirectory(directory: PathLike) {
|
|
|
60
61
|
return fs.mkdir(directory, { recursive: true })
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
// Checks if the entry is a directory or a symbolic link to a directory.
|
|
65
|
+
export async function isDirectoryEntry(entry: Dirent) {
|
|
66
|
+
if (entry.isDirectory()) return true
|
|
67
|
+
if (!entry.isSymbolicLink()) return false
|
|
68
|
+
|
|
69
|
+
const entryPath = path.join(entry.parentPath, entry.name)
|
|
70
|
+
const stats = await fs.stat(entryPath)
|
|
71
|
+
|
|
72
|
+
return stats.isDirectory()
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
export type CopyDirectoryCallback = (
|
|
64
76
|
entry:
|
|
65
77
|
| { type: 'file'; content: string; url: URL }
|
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/versions.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
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 '..'
|
|
6
6
|
import type { DocsVersionsConfig } from '../schema'
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
copyDirectory,
|
|
10
|
+
copyFile,
|
|
11
|
+
ensureDirectory,
|
|
12
|
+
isDirectoryEntry,
|
|
13
|
+
listDirectory,
|
|
14
|
+
readJSONFile,
|
|
15
|
+
writeJSONFile,
|
|
16
|
+
} from './fs'
|
|
9
17
|
import { transformMarkdown } from './markdown'
|
|
10
18
|
import { ensureTrailingSlash, getExtension, stripExtension, stripLeadingSlash, stripTrailingSlash } from './path'
|
|
11
19
|
import { throwPluginError } from './plugin'
|
|
@@ -55,10 +63,10 @@ export const VersionSchema = z
|
|
|
55
63
|
export async function ensureNewVersion(
|
|
56
64
|
config: StarlightVersionsConfig,
|
|
57
65
|
starlightConfig: StarlightUserConfig,
|
|
58
|
-
|
|
66
|
+
astroConfig: AstroConfig,
|
|
59
67
|
logger: AstroIntegrationLogger,
|
|
60
68
|
) {
|
|
61
|
-
const docsDir = new URL('content/docs/', srcDir)
|
|
69
|
+
const docsDir = new URL('content/docs/', astroConfig.srcDir)
|
|
62
70
|
const newVersion = await checkForNewVersion(config, docsDir)
|
|
63
71
|
const locales = Object.keys(starlightConfig.locales ?? {})
|
|
64
72
|
|
|
@@ -98,6 +106,7 @@ export async function ensureNewVersion(
|
|
|
98
106
|
|
|
99
107
|
const md = await transformMarkdown(entry.content, {
|
|
100
108
|
assets: [],
|
|
109
|
+
base: stripTrailingSlash(astroConfig.base),
|
|
101
110
|
locale: getDocLocale(slug, starlightConfig),
|
|
102
111
|
slug,
|
|
103
112
|
url: entry.url,
|
|
@@ -113,7 +122,7 @@ export async function ensureNewVersion(
|
|
|
113
122
|
await copyFile(asset.source, asset.dest)
|
|
114
123
|
}
|
|
115
124
|
|
|
116
|
-
await makeVersionConfig(newVersion, starlightConfig, srcDir)
|
|
125
|
+
await makeVersionConfig(newVersion, starlightConfig, astroConfig.srcDir)
|
|
117
126
|
|
|
118
127
|
logger.info(`Created new version '${newVersion.slug}'.`)
|
|
119
128
|
}
|
|
@@ -316,7 +325,13 @@ async function checkForNewVersion(config: StarlightVersionsConfig, docsDir: URL)
|
|
|
316
325
|
let newVersion: Version | undefined
|
|
317
326
|
|
|
318
327
|
const docsDirEntries = await listDirectory(docsDir)
|
|
319
|
-
const docsDirDirectories = new Set(
|
|
328
|
+
const docsDirDirectories = new Set<string>()
|
|
329
|
+
|
|
330
|
+
for (const entry of docsDirEntries) {
|
|
331
|
+
if (await isDirectoryEntry(entry)) {
|
|
332
|
+
docsDirDirectories.add(entry.name)
|
|
333
|
+
}
|
|
334
|
+
}
|
|
320
335
|
|
|
321
336
|
for (const version of config.versions) {
|
|
322
337
|
if (!docsDirDirectories.has(version.slug)) {
|