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

fix: handle redirect domains & refs #331

Merged
merged 1 commit into from
Oct 25, 2023
Merged
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
18 changes: 14 additions & 4 deletions website-v3/src/pages/[owner]/[repository]/[...path].astro
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,24 @@ Astro.response.status = status;
if (response?.code === 'OK') {
const { frontmatter, config, source, baseBranch, code, headings } = response!.data;

const domain = domains.find(([, repo]) => repo === `${owner}/${repository}`)?.at(0);

// Handle a frontmatter redirect
const redirect = frontmatter.redirect;
if (redirect && isExternalLink(redirect)) {
return Astro.redirect(redirect);
} else if (redirect) {
return Astro.redirect(`/${owner}/${repository}${redirect}`);
} else if (redirect && domain) {
// If there is a domain setup, always redirect to it.
let url = `https://${domain}`;
if (ref) url += `/~${ref}`;
url += redirect;
return Astro.redirect(url);
} else if (redirect && !domain) {
// If no domain, redirect to docs.page.
let url = `https://docs.page/${owner}/${repository}`;
if (ref) url += `~${ref}`;
url += redirect;
return Astro.redirect(url);
}

if (import.meta.env.PROD) {
Expand All @@ -96,8 +108,6 @@ if (response?.code === 'OK') {
try {
tabs = Astro.cookies.get('tabs')?.json() ?? {};
} catch {}

const domain = domains.find(([, repo]) => repo === `${owner}/${repository}`)?.at(0);

let relativePath = ensureLeadingSlash(path || '/');
let locale: string | undefined;
Expand Down
Loading