diff options
author | Chris Swithinbank | 2023-10-24 20:32:51 +0200 |
---|---|---|
committer | GitHub | 2023-10-24 20:32:51 +0200 |
commit | 92b3b575404d0dc34f720c0ba29d8ed50be98f58 (patch) | |
tree | 2575ad0a3a8011126c114751a17e9b313c38fe7d | |
parent | 1e517d92a4cf146d2dcae58f7c4299d6f25ea73e (diff) | |
download | IT.starlight-92b3b575404d0dc34f720c0ba29d8ed50be98f58.tar.gz IT.starlight-92b3b575404d0dc34f720c0ba29d8ed50be98f58.tar.bz2 IT.starlight-92b3b575404d0dc34f720c0ba29d8ed50be98f58.zip |
Point edit link to default locale file for fallback content (#985)
-rw-r--r-- | .changeset/poor-vans-reflect.md | 5 | ||||
-rw-r--r-- | packages/starlight/utils/route-data.ts | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/.changeset/poor-vans-reflect.md b/.changeset/poor-vans-reflect.md new file mode 100644 index 00000000..9c167dd7 --- /dev/null +++ b/.changeset/poor-vans-reflect.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Fix edit URLs for pages displaying fallback content diff --git a/packages/starlight/utils/route-data.ts b/packages/starlight/utils/route-data.ts index ae204f80..503e4233 100644 --- a/packages/starlight/utils/route-data.ts +++ b/packages/starlight/utils/route-data.ts @@ -5,9 +5,10 @@ import config from 'virtual:starlight/user-config'; import { generateToC, type TocItem } from './generateToC'; import { getFileCommitDate } from './git'; import { getPrevNextLinks, getSidebar, type SidebarEntry } from './navigation'; +import { ensureTrailingSlash } from './path'; import type { Route } from './routing'; +import { localizedId } from './slugs'; import { useTranslations } from './translations'; -import { ensureTrailingSlash } from './path'; interface PageProps extends Route { headings: MarkdownHeading[]; @@ -79,7 +80,7 @@ function getLastUpdated({ entry, id }: PageProps): Date | undefined { return; } -function getEditUrl({ entry, id }: PageProps): URL | undefined { +function getEditUrl({ entry, id, isFallback }: PageProps): URL | undefined { const { editUrl } = entry.data; // If frontmatter value is false, editing is disabled for this page. if (editUrl === false) return; @@ -90,8 +91,9 @@ function getEditUrl({ entry, id }: PageProps): URL | undefined { url = editUrl; } else if (config.editLink.baseUrl) { const srcPath = project.srcDir.replace(project.root, ''); + const filePath = isFallback ? localizedId(id, config.defaultLocale.locale) : id; // If a base URL was added in Starlight config, synthesize the edit URL from it. - url = ensureTrailingSlash(config.editLink.baseUrl) + srcPath + 'content/docs/' + id; + url = ensureTrailingSlash(config.editLink.baseUrl) + srcPath + 'content/docs/' + filePath; } return url ? new URL(url) : undefined; } |