Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point edit link to default locale file for fallback content #985

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading