Skip to content

Commit 8b56766

Browse files
committed
docs: ✏️ update URL handling
1 parent 642fb52 commit 8b56766

4 files changed

Lines changed: 517 additions & 64 deletions

File tree

site/app/layout.jsx

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,6 @@ import { getPageMap } from 'nextra/page-map'
44
import 'nextra-theme-docs/style.css'
55
import './globals.css'
66

7-
const repositoryName = process.env.GITHUB_REPOSITORY?.split('/')[1] || ''
8-
const isUserOrOrgPage = repositoryName.endsWith('.github.io')
9-
const basePath = repositoryName && !isUserOrOrgPage ? `/${repositoryName}` : ''
10-
11-
const withBasePath = (value) => {
12-
if (!basePath || typeof value !== 'string' || !value.startsWith('/') || value.startsWith('//')) {
13-
return value
14-
}
15-
16-
if (value === basePath || value.startsWith(`${basePath}/`)) {
17-
return value
18-
}
19-
20-
return `${basePath}${value}`
21-
}
22-
23-
const normalizePageMap = (node) => {
24-
if (Array.isArray(node)) {
25-
return node.map(normalizePageMap)
26-
}
27-
28-
if (!node || typeof node !== 'object') {
29-
return node
30-
}
31-
32-
const normalized = {}
33-
34-
for (const [key, value] of Object.entries(node)) {
35-
if ((key === 'route' || key === 'href') && typeof value === 'string') {
36-
normalized[key] = withBasePath(value)
37-
} else {
38-
normalized[key] = normalizePageMap(value)
39-
}
40-
}
41-
42-
return normalized
43-
}
44-
457
export const metadata = {
468
title: {
479
default: 'nano-css — Tiny CSS-in-JS Library',
@@ -71,8 +33,6 @@ const footer = (
7133
)
7234

7335
export default async function RootLayout({ children }) {
74-
const pageMap = normalizePageMap(await getPageMap())
75-
7636
return (
7737
<html lang="en" dir="ltr" suppressHydrationWarning>
7838
<Head>
@@ -81,7 +41,7 @@ export default async function RootLayout({ children }) {
8141
<body>
8242
<Layout
8343
navbar={navbar}
84-
pageMap={pageMap}
44+
pageMap={await getPageMap()}
8545
docsRepositoryBase="https://github.com/streamich/nano-css/tree/master/site"
8646
footer={footer}
8747
sidebar={{ defaultMenuCollapseLevel: 1 }}

site/mdx-components.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
import { useMDXComponents as getThemeComponents } from 'nextra-theme-docs'
22

33
const themeComponents = getThemeComponents()
4-
const repositoryName = process.env.GITHUB_REPOSITORY?.split('/')[1] || ''
5-
const isUserOrOrgPage = repositoryName.endsWith('.github.io')
6-
const basePath = repositoryName && !isUserOrOrgPage ? `/${repositoryName}` : ''
7-
8-
const withBasePath = (href) => {
9-
if (!basePath || typeof href !== 'string' || !href.startsWith('/') || href.startsWith('//')) {
10-
return href
11-
}
12-
13-
if (href === basePath || href.startsWith(`${basePath}/`)) {
14-
return href
15-
}
16-
17-
return `${basePath}${href}`
18-
}
194

205
export function useMDXComponents(components) {
216
return {
227
...themeComponents,
238
...components,
24-
a: ({ href, ...props }) => {
25-
const Anchor = components?.a || themeComponents.a || 'a'
26-
return <Anchor href={withBasePath(href)} {...props} />
27-
},
289
}
2910
}

site/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "next dev",
77
"clean": "npx rimraf .next out",
88
"build": "next build",
9-
"start": "next start"
9+
"start": "serve out -l 3000"
1010
},
1111
"dependencies": {
1212
"next": "^15",
@@ -15,5 +15,8 @@
1515
"react": "^19",
1616
"react-dom": "^19",
1717
"typescript": "^5"
18+
},
19+
"devDependencies": {
20+
"serve": "^14.2.5"
1821
}
1922
}

0 commit comments

Comments
 (0)