starlight-versions 0.5.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 CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 0.5.0
4
10
 
5
11
  ### 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.srcDir, logger)
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/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,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
- srcDir: URL,
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-versions",
3
- "version": "0.5.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)",