Skip to content

Commit

Permalink
conform trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Sep 11, 2024
1 parent 1083393 commit 2248ff7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
import urljoin from "url-join";
import { loadWithUrl } from "../../../../utils/loadWithUrl";
import { toValidPathname } from "../../../../utils/toValidPathname";
import { isTrailingSlashEnabled } from "../../../../utils/trailingSlash";
import { conformTrailingSlash } from "../../../../utils/trailingSlash";
import { cleanHost, getXFernHostNode } from "../../../../utils/xFernHost";

export const config = {
Expand Down Expand Up @@ -66,9 +66,7 @@ const handler: NextApiHandler = async (

const node = FernNavigation.utils.convertLoadDocsForUrlResponse(docs);
const slugCollector = NodeCollector.collect(node);
const urls = slugCollector
.getSlugs()
.map((slug) => urljoin(xFernHost, slug, isTrailingSlashEnabled() ? "/" : ""));
const urls = slugCollector.getSlugs().map((slug) => conformTrailingSlash(urljoin(xFernHost, slug)));

// when we call res.revalidate() nextjs uses
// req.headers.host to make the network request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
import urljoin from "url-join";
import { loadWithUrl } from "../../../../utils/loadWithUrl";
import { toValidPathname } from "../../../../utils/toValidPathname";
import { isTrailingSlashEnabled } from "../../../../utils/trailingSlash";
import { conformTrailingSlash } from "../../../../utils/trailingSlash";
import { getXFernHostNode } from "../../../../utils/xFernHost";

export const config = {
Expand Down Expand Up @@ -76,9 +76,7 @@ const handler: NextApiHandler = async (

const node = FernNavigation.utils.convertLoadDocsForUrlResponse(docs);
const slugCollector = NodeCollector.collect(node);
const urls = slugCollector
.getSlugs()
.map((slug) => urljoin(xFernHost, slug, isTrailingSlashEnabled() ? "/" : ""));
const urls = slugCollector.getSlugs().map((slug) => conformTrailingSlash(urljoin(xFernHost, slug)));

// when we call res.revalidate() nextjs uses
// req.headers.host to make the network request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { loadWithUrl } from "../../../utils/loadWithUrl";
import { getXFernHostEdge } from "../../../utils/xFernHost";
// eslint-disable-next-line import/no-internal-modules
import { checkViewerAllowedEdge } from "@fern-ui/ui/auth";
import { isTrailingSlashEnabled } from "../../../utils/trailingSlash";
import { conformTrailingSlash } from "../../../utils/trailingSlash";

export const runtime = "edge";
export const revalidate = 60 * 60 * 24;
Expand Down Expand Up @@ -37,7 +37,7 @@ export default async function GET(req: NextRequest): Promise<NextResponse> {
const slugCollector = NodeCollector.collect(node);
const urls = slugCollector.getIndexablePageSlugs().map((slug) => urljoin(xFernHost, slug));

const sitemap = getSitemapXml(urls.map((url) => (isTrailingSlashEnabled() ? `https://${url}/` : `https://${url}`)));
const sitemap = getSitemapXml(urls.map((url) => conformTrailingSlash(`https://${url}`)));

headers.set("Content-Type", "text/xml");

Expand Down

0 comments on commit 2248ff7

Please sign in to comment.