Skip to content

🎥 Make videos programmatically with React

Elements: Simplify Markdown routes in library template

Igor Samokhovets8f0eadd479b7
diff --git a/packages/template-element-library/README.md b/packages/template-element-library/README.md
index 8a89221b34..0f68f2dbaa 100644
--- a/packages/template-element-library/README.md
+++ b/packages/template-element-library/README.md
@@ -70,9 +70,11 @@ Publish `build/client` to a static host. All Element pages are prerendered from
## Markdown and agent discovery
-Each page declares its Markdown URL with a `<link rel="alternate" type="text/markdown">` tag. Agents can follow `/index.md` from the homepage to find every Element without guessing URLs or running JavaScript.
+Pages with Markdown declare its URL with a `<link rel="alternate" type="text/markdown">` tag. Agents can follow `/index.md` from the homepage to find every Element without guessing URLs or running JavaScript.
-Markdown uses the website's registry, installation payloads, and source files. New registry entries appear in the catalog and build automatically. Resource routes serve Markdown during development; builds write `.md` files to `build/client`. You don't need a production server or host integration.
+Markdown is served by resource routes registered in `app/routes.ts`. HTML-only pages need no Markdown route.
+
+Markdown uses the website's Element registry, installation payloads, and source files. New Elements get both formats automatically. Builds write `.md` files to `build/client`; you don't need a production server or host integration.
Serve `.md` files directly, preferably with `Content-Type: text/markdown; charset=utf-8`. The routes set development headers; your host sets production headers.
diff --git a/packages/template-element-library/app/routes.ts b/packages/template-element-library/app/routes.ts
index c58e75833b..26d9d2058c 100644
--- a/packages/template-element-library/app/routes.ts
+++ b/packages/template-element-library/app/routes.ts
@@ -6,9 +6,9 @@ import {
} from "@react-router/dev/routes";
export default [
- route("index.md", "routes/library-markdown.ts"),
- route("captions.md", "routes/captions-markdown.ts"),
- route("elements/:slug.md", "routes/element-markdown.ts"),
+ route("index.md", "routes/elements.md.ts"),
+ route("captions.md", "routes/captions.md.ts"),
+ route("elements/:slug.md", "routes/element.md.ts"),
layout("routes/layout.tsx", [
index("routes/library.tsx"),
route("captions", "routes/captions.tsx"),
diff --git a/packages/template-element-library/app/routes/captions-markdown.ts b/packages/template-element-library/app/routes/captions.md.ts
similarity index 100%
rename from packages/template-element-library/app/routes/captions-markdown.ts
rename to packages/template-element-library/app/routes/captions.md.ts
diff --git a/packages/template-element-library/app/routes/element-markdown.ts b/packages/template-element-library/app/routes/element.md.ts
similarity index 77%
rename from packages/template-element-library/app/routes/element-markdown.ts
rename to packages/template-element-library/app/routes/element.md.ts
index 11dbcfc039..794bacb2b7 100644
--- a/packages/template-element-library/app/routes/element-markdown.ts
+++ b/packages/template-element-library/app/routes/element.md.ts
@@ -1,8 +1,8 @@
-import type { LoaderFunctionArgs } from "react-router";
import { catalog } from "../../lib/element-payload";
import { getElementMarkdown } from "../../lib/markdown";
+import type { Route } from "./+types/element.md";
-export const loader = ({ params }: LoaderFunctionArgs) => {
+export const loader = ({ params }: Route.LoaderArgs) => {
const entry = catalog.find(
({ definition }) => definition.slug === params.slug,
);
diff --git a/packages/template-element-library/app/routes/library-markdown.ts b/packages/template-element-library/app/routes/elements.md.ts
similarity index 100%
rename from packages/template-element-library/app/routes/library-markdown.ts
rename to packages/template-element-library/app/routes/elements.md.ts
diff --git a/packages/template-element-library/react-router.config.ts b/packages/template-element-library/react-router.config.ts
index d8abf7b849..f86327c714 100644
--- a/packages/template-element-library/react-router.config.ts
+++ b/packages/template-element-library/react-router.config.ts
@@ -3,11 +3,8 @@ import { elements } from "./elements/registry";
export default {
ssr: false,
- prerender: [
- "/",
- "/index.md",
- "/captions",
- "/captions.md",
+ prerender: ({ getStaticPaths }) => [
+ ...getStaticPaths(),
...elements.flatMap(({ slug }) => [
`/elements/${slug}`,
`/elements/${slug}.md`,