Skip to content

Commit

Permalink
Point edit link to default locale file for fallback content (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis committed Oct 24, 2023
1 parent 1e517d9 commit 92b3b57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-vans-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fix edit URLs for pages displaying fallback content
8 changes: 5 additions & 3 deletions packages/starlight/utils/route-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

0 comments on commit 92b3b57

Please sign in to comment.