diff --git a/app/components/doc-route.tsx b/app/components/doc-route.tsx index 5238904..be64c45 100644 --- a/app/components/doc-route.tsx +++ b/app/components/doc-route.tsx @@ -2,6 +2,7 @@ import type { LoaderFunctionArgs, SerializeFrom, MetaFunction, + HeadersFunction, } from "@remix-run/node"; import * as React from "react"; import { json } from "@remix-run/node"; @@ -27,20 +28,24 @@ export let loader = async ({ params, request }: LoaderFunctionArgs) => { invariant(params.ref, "expected `ref` params"); - let doc = await getRepoDoc(params.ref, params["*"] || "index"); - if (!doc) { + try { + let slug = params["*"]?.endsWith("/changelog") + ? "CHANGELOG" + : `docs/${params["*"] || "index"}`; + let doc = await getRepoDoc(params.ref, slug); + if (!doc) throw null; + return json({ doc }, { headers: { "Cache-Control": CACHE_CONTROL.doc } }); + } catch (_) { throw new Response("", { status: 404 }); } - - return json({ doc }, { headers: { "Cache-Control": CACHE_CONTROL.doc } }); }; -export function headers() { - return { - "Cache-Control": CACHE_CONTROL.doc, - Vary: "Cookie", - }; -} +export const headers: HeadersFunction = ({ loaderHeaders }) => { + // Inherit the caching headers from the loader so we don't cache 404s + let headers = new Headers(loaderHeaders); + headers.set("Vary", "Cookie"); + return headers; +}; export const meta: MetaFunction< typeof loader, diff --git a/app/modules/gh-docs/docs.ts b/app/modules/gh-docs/docs.ts index ba28942..fe0d23f 100644 --- a/app/modules/gh-docs/docs.ts +++ b/app/modules/gh-docs/docs.ts @@ -88,8 +88,7 @@ global.docCache ??= new LRUCache({ async function fetchDoc(key: string): Promise { let [repo, ref, slug] = key.split(":"); - // remove docs/ when we do https://github.com/remix-run/react-router-website/issues/94 - let filename = `docs/${slug}.md`; + let filename = `${slug}.md`; let md = await getRepoContent(repo, ref, filename); if (md === null) { throw Error(`Could not find ${filename} in ${repo}@${ref}`); diff --git a/app/routes/$lang.$ref.$.tsx b/app/routes/$lang.$ref.$.tsx index b0dfc57..edb9754 100644 --- a/app/routes/$lang.$ref.$.tsx +++ b/app/routes/$lang.$ref.$.tsx @@ -5,5 +5,3 @@ export { meta, ErrorBoundary, } from "~/components/doc-route"; - -export let unstable_shouldReload = () => false; diff --git a/app/routes/brand.tsx b/app/routes/brand.tsx index 15077e5..b3d1815 100644 --- a/app/routes/brand.tsx +++ b/app/routes/brand.tsx @@ -12,7 +12,7 @@ export const meta: MetaFunction = () => { export default function Brand() { return ( -
+

React Router Brand