Skip to content

Commit

Permalink
slash
Browse files Browse the repository at this point in the history
  • Loading branch information
rossrobino committed Feb 7, 2025
1 parent 3b27ab0 commit ce63898
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions apps/docs/src/server/+func.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export const prerender: Prerender = new Set([

export const handler: Handler = async (req) => {
const url = new URL(req.url);

// append trailing slash
if (url.pathname.at(-1) !== "/") {
url.pathname += "/";
url.search = "";
return Response.redirect(url.origin, 301);
}

const page = new Injector(html);

if (url.pathname === "/") {
Expand Down Expand Up @@ -95,13 +103,6 @@ export const handler: Handler = async (req) => {

if (!page.empty) return page.toResponse();

// append trailing slash
if (url.pathname.at(-1) !== "/") {
url.pathname += "/";
url.search = "";
return Response.redirect(url.origin, 301);
}

// redirect from old docs
if (url.pathname.startsWith("/docs/")) {
const element = url.pathname.split("/").at(2);
Expand All @@ -110,7 +111,7 @@ export const handler: Handler = async (req) => {
if (element === "details" || element === "popover") {
url.pathname = `/styles/${element}/`;
} else {
url.pathname = `/elements/${element}`;
url.pathname = `/elements/${element}/`;
}

url.search = "";
Expand Down

0 comments on commit ce63898

Please sign in to comment.