Skip to content

Commit 33f4e15

Browse files
committed
fix docs base url
1 parent 4f6756f commit 33f4e15

14 files changed

Lines changed: 40 additions & 15 deletions

File tree

starlight/astro.config.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import mdx from "@astrojs/mdx";
77
import { injectMdxImports } from "./src/remark/inject-mdx-imports.mjs";
88
import { rewriteCodeGroup } from "./src/remark/rewrite-code-group.mjs";
99
import { rewriteAsides } from "./src/remark/rewrite-asides.mjs";
10+
import { prependBaseToLinks } from "./src/remark/prepend-base-to-links.mjs";
1011
import { sidebarV1 } from "./src/sidebars/v1.mjs";
1112
import { sidebarV2 } from "./src/sidebars/v2.mjs";
1213
import { sidebarV3 } from "./src/sidebars/v3.mjs";
@@ -64,11 +65,17 @@ function snippetLoaderPlugin() {
6465

6566
export default defineConfig({
6667
site: "https://inertiajs.com",
68+
base: "/docs",
69+
// Emit build output under dist/docs/ so the on-disk layout mirrors
70+
// the URL layout. The docs worker is mounted at /docs/* via service
71+
// binding — a request for /docs/v3/... resolves to dist/docs/v3/...
72+
// without the worker having to rewrite paths.
73+
outDir: "./dist/docs",
6774
// The root splash page lives in a separate repo; this build only owns
6875
// /docs/*. Redirect the bare /docs entry point to the latest version's
6976
// intro page so wandering links land somewhere useful.
7077
redirects: {
71-
"/docs": "/docs/v3/getting-started/",
78+
"/": "/docs/v3/getting-started/",
7279
},
7380
markdown: {
7481
remarkPlugins: [
@@ -77,6 +84,7 @@ export default defineConfig({
7784
// need to provide bindings for the originals.
7885
rewriteCodeGroup,
7986
rewriteAsides,
87+
prependBaseToLinks,
8088
[
8189
injectMdxImports,
8290
{
@@ -104,7 +112,7 @@ export default defineConfig({
104112
// runs once per navigation.
105113
{
106114
tag: "script",
107-
attrs: { type: "module", src: "/framework-switcher.js" },
115+
attrs: { type: "module", src: "/docs/framework-switcher.js" },
108116
},
109117
],
110118
expressiveCode: {

starlight/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "astro dev",
99
"build": "astro build",
1010
"preview": "astro preview",
11-
"deploy": " npx wrangler deploy",
11+
"deploy": "npx wrangler deploy",
1212
"astro": "astro"
1313
},
1414
"dependencies": {

starlight/src/components/SiteTitleWithVersion.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getCollection } from "astro:content";
88
const allEntries = await getCollection("docs");
99
const slugsByVersion: Record<string, Set<string>> = {};
1010
for (const entry of allEntries) {
11-
const m = entry.id.match(/^docs\/(v\d+)\/(.+)$/);
11+
const m = entry.id.match(/^(v\d+)\/(.+)$/);
1212
if (!m) continue;
1313
const [, version, rest] = m;
1414
(slugsByVersion[version] ??= new Set()).add(rest);

starlight/src/content/docs/docs/v1

Lines changed: 0 additions & 1 deletion
This file was deleted.

starlight/src/content/docs/docs/v2

Lines changed: 0 additions & 1 deletion
This file was deleted.

starlight/src/content/docs/docs/v3

Lines changed: 0 additions & 1 deletion
This file was deleted.

starlight/src/content/docs/v1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../v1

starlight/src/content/docs/v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../v2

starlight/src/content/docs/v3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../v3
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ function cleanMarkdown(content: string): string {
2323
export const getStaticPaths: GetStaticPaths = async () => {
2424
const entries = await getCollection("docs");
2525
return entries
26-
.filter((entry) => /^docs\/v\d+\//.test(entry.id))
26+
.filter((entry) => /^v\d+\//.test(entry.id))
2727
.map((entry) => ({
28-
// Strip the leading `docs/` from the collection id — the file
29-
// sits inside `src/pages/docs/`, so the slug param is the
30-
// remainder of the URL between `/docs/` and `.md`.
31-
params: { slug: entry.id.replace(/^docs\//, "") },
28+
params: { slug: entry.id },
3229
props: { entry },
3330
}));
3431
};

0 commit comments

Comments
 (0)