Skip to content

Commit 5c60759

Browse files
authored
fix: Handle vanity domain redirects (#363)
1 parent 5f585b4 commit 5c60759

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

website/app/components/Tabs.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export function Tabs(props: Props) {
3131
<li key={href}>
3232
<NavLink
3333
to={href}
34-
target={isExternalLink(href) ? "_blank" : undefined}
3534
className={cn(
3635
"relative top-px flex items-center h-12 border-b-[1.5px] border-transparent",
3736
{

website/app/routes/$/route.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const loader = async (args: LoaderFunctionArgs) => {
3333
}).catch((response) => {
3434
throw response;
3535
});
36-
36+
3737
// Check whether the repository has a domain assigned.
3838
const domain = domains
3939
.find(([, repo]) => repo === `${owner}/${repository}`)
@@ -52,7 +52,11 @@ export const loader = async (args: LoaderFunctionArgs) => {
5252
}
5353

5454
let url = "";
55-
if (domain && environment === "production") {
55+
if (vanity) {
56+
url = `https://${owner}.docs.page/${repository}`;
57+
if (ref) url += `~${ref}`;
58+
url += redirectTo;
59+
} else if (domain && environment === "production") {
5660
// If there is a domain setup, always redirect to it.
5761
url = `https://${domain}`;
5862
if (ref) url += `/~${ref}`;
@@ -64,6 +68,8 @@ export const loader = async (args: LoaderFunctionArgs) => {
6468
url += redirectTo;
6569
}
6670

71+
console.log('Handling redirect', redirectTo, { owner, repository, ref, vanity, domain, environment }, url);
72+
6773
throw redirect(url);
6874
}
6975

@@ -151,7 +157,7 @@ export const meta: MetaFunction<typeof loader> = ({ data: ctx }) => {
151157
ctx.bundle.config.logo.light || ctx.bundle.config.logo.dark
152158
? getAssetSrc(
153159
ctx,
154-
ctx.bundle.config.logo.light || ctx.bundle.config.logo.dark || "",
160+
ctx.bundle.config.logo.light || ctx.bundle.config.logo.dark || ""
155161
)
156162
: undefined,
157163
});

website/app/routes/schema[.]json.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const loader = async () => {
2+
const response = await fetch("https://staging-api.docs.page/schema.json");
3+
return response.json();
4+
}

website/app/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ export function getHref(ctx: Context, path: string) {
203203
// Define the base href for the current request.
204204
let href = "";
205205

206+
// If it's a vanity domain, we need to prefix the path with the owner and repository.
207+
if (ctx.vanity) {
208+
href += `/${ctx.repository}`;
209+
}
206210
// Ensure all links start with the custom domain if it's set.
207-
if (ctx.domain) {
211+
else if (ctx.domain) {
208212
href += `https://${ctx.domain}`;
209213
}
210-
// If it's a vanity domain, we need to prefix the path with the owner and repository.
211-
else if (ctx.vanity) {
212-
href += `https://${ctx.owner}.docs.page/${ctx.repository}`;
213-
}
214214
// Prefix the path with the owner and repository, e.g. `/invertase/docs.page`.
215215
else {
216216
href = `/${ctx.owner}/${ctx.repository}`;

0 commit comments

Comments
 (0)