Skip to content

Commit 63ca28b

Browse files
author
Dimitri POSTOLOV
authoredSep 21, 2023
[v3] Remove support of "_meta.json", use "_meta.{js,jsx,ts,tsx}" instead. (#2321)

File tree

29 files changed

+122
-172
lines changed

29 files changed

+122
-172
lines changed
 

‎.changeset/long-wombats-train.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'nextra-theme-docs': major
3+
'nextra': major
4+
---
5+
6+
Remove support of "_meta.json", use "_meta.{js,jsx,ts,tsx}" instead.

‎.changeset/rich-bananas-burn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextra-theme-docs': major
3+
---
4+
5+
remove `config.serverSideError`

‎docs/pages/docs/docs-theme/api/use-config.mdx

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ context.
4545
- `project`: data about
4646
[Project Link](/docs/docs-theme/theme-configuration#project-link)
4747
- `search`: data about [Search](/docs/docs-theme/theme-configuration#search)
48-
- `serverSideError`: data to display when a server-side error happens (requires
49-
`500.mdx` page too)
5048
- `sidebar`: data about [Sidebar](/docs/docs-theme/theme-configuration#sidebar)
5149
- `toc`: data about
5250
[Table of Contents Sidebar](/docs/docs-theme/theme-configuration#toc-sidebar)

‎docs/pages/docs/docs-theme/theme-configuration.mdx

+1-3
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,7 @@ export default {
743743

744744
### 404 - Not Found
745745

746-
### 500 - Internal Server Error
747-
748-
## Favicon Glyph (Experimental)
746+
## Favicon Glyph
749747

750748
This isn’t supported by all browsers, but it’s a nice way to customize the
751749
favicon of the website simply by using an emoji or character.

‎docs/pages/index.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ export function I18n() {
3838
a={
3939
<div style={{ display: 'flex', flexDirection: 'column', gap: '.5rem' }}>
4040
<File
41-
name="/hello.en-US.mdx"
41+
name="/en/hello.mdx"
4242
className={active === 'en' && styles.active}
4343
onPointerOver={() => setActive('en')}
4444
/>
4545
<File
46-
name="/hello.de-DE.mdx"
46+
name="/de/hello.mdx"
4747
className={active === 'de' && styles.active}
4848
onPointerOver={() => setActive('de')}
4949
/>
5050
<File
51-
name="/hello.ja-JP.mdx"
51+
name="/ja/hello.mdx"
5252
className={active === 'ja' && styles.active}
5353
onPointerOver={() => setActive('ja')}
5454
/>

‎examples/docs/src/pages/_meta.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
index: 'Introduction',
3+
'get-started': 'Get Started',
4+
features: 'Features',
5+
themes: 'Themes',
6+
advanced: 'Advanced'
7+
}

‎examples/docs/src/pages/_meta.json

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
'code-highlighting': 'Code Highlighting'
3+
}

‎examples/docs/src/pages/advanced/_meta.json

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
mdx: 'MDX',
3+
ssg: 'Next.js SSG',
4+
i18n: 'Next.js i18n',
5+
image: 'Next.js Image',
6+
themes: 'Themes',
7+
latex: 'LaTeX'
8+
}

‎examples/docs/src/pages/features/_meta.json

-8
This file was deleted.
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
docs: 'Docs Theme',
3+
blog: 'Blog Theme'
4+
}

‎examples/docs/src/pages/themes/_meta.json

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
index: 'Installation'
3+
}

‎examples/docs/src/pages/themes/blog/_meta.json

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
index: 'Installation',
3+
configuration: 'Configuration',
4+
callout: 'Callout',
5+
bleed: 'Bleed'
6+
}

‎examples/docs/src/pages/themes/docs/_meta.json

-6
This file was deleted.

‎examples/swr-site/pages/en/_meta.json

-62
This file was deleted.

‎examples/swr-site/pages/en/_meta.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
export default {
2+
index: {
3+
title: 'Introduction',
4+
type: 'page',
5+
display: 'hidden'
6+
},
7+
docs: {
8+
type: 'page',
9+
title: 'Docs'
10+
},
11+
remote: {
12+
type: 'page',
13+
title: 'Remote',
14+
href: '/remote/4423220'
15+
},
16+
about: {
17+
type: 'menu',
18+
title: 'About',
19+
items: {
20+
contributors: {
21+
title: 'Contributors',
22+
href: 'https://github.com/vercel/swr/graphs/contributors',
23+
newWindow: true
24+
},
25+
team: {
26+
title: 'Team'
27+
},
28+
acknowledgement: {
29+
title: 'Acknowledgement'
30+
},
31+
'a-page': {
32+
title: 'A Page'
33+
},
34+
changelog: {
35+
title: 'Changelog'
36+
}
37+
}
38+
},
39+
examples: {
40+
type: 'page',
41+
title: 'Examples',
42+
theme: {
43+
layout: 'full'
44+
}
45+
},
46+
blog: {
47+
type: 'page',
48+
title: 'Blog',
49+
theme: {
50+
sidebar: false,
51+
toc: true,
52+
breadcrumb: false,
53+
typesetting: 'article'
54+
}
55+
},
56+
nextra_link: {
57+
type: 'page',
58+
title: 'Nextra ↗',
59+
href: 'https://github.com/shuding/nextra',
60+
newWindow: true
61+
}
62+
}

‎examples/swr-site/pages/en/docs/404-500.mdx

-16
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ import { NotFoundPage } from 'nextra-theme-docs'
1616

1717
[Click to try `/404` page.](/this-page-not-exist-trust-me)
1818

19-
## 500
20-
21-
To add `/500` page import `ServerSideErrorPage`:
22-
23-
```mdx filename="pages/500.mdx"
24-
import { ServerSideErrorPage } from 'nextra-theme-docs'
25-
26-
# 500 - Internal Server Error
27-
28-
<ServerSideErrorPage />
29-
```
30-
31-
[Click to try `/500` page.](/500)
32-
3319
## Customize Theme Config Options
3420

3521
Also, you can customize following options:
@@ -38,8 +24,6 @@ Also, you can customize following options:
3824
// ...
3925
notFoundLink?: ReactNode | FC
4026
notFoundLabels?: string
41-
serverSideErrorLink?: ReactNode | FC
42-
serverSideErrorLabels?: string
4327
```
4428

4529
## Customize Layout

‎examples/swr-site/pages/es/_meta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import meta from '../en/_meta.json'
1+
import meta from '../en/_meta'
22

33
export default {
44
index: {

‎packages/nextra-theme-docs/src/components/500.tsx

-34
This file was deleted.

‎packages/nextra-theme-docs/src/components/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export { Navbar } from './navbar'
1313
export { NotFoundPage } from './404'
1414
export { Search } from './search'
1515
export { Select } from './select'
16-
export { ServerSideErrorPage } from './500'
1716
export { Sidebar } from './sidebar'
1817
export { SkipNavContent, SkipNavLink } from './skip-nav'
1918
export { ThemeSwitch } from './theme-switch'

‎packages/nextra-theme-docs/src/constants.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ export const DEFAULT_THEME: DocsThemeConfig = {
154154
return `${text}…`
155155
}
156156
},
157-
serverSideError: {
158-
content: 'Submit an issue about error in url →',
159-
labels: 'bug'
160-
},
161157
sidebar: {
162158
defaultMenuCollapseLevel: 2,
163159
toggleButton: true

‎packages/nextra-theme-docs/src/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ export {
241241
Bleed,
242242
Collapse,
243243
NotFoundPage,
244-
ServerSideErrorPage,
245244
Navbar,
246245
SkipNavContent,
247246
SkipNavLink,

‎packages/nextra-theme-docs/src/schemas.ts

-4
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ export const themeSchema = /* @__PURE__ */ (() =>
118118
// Can't be React component
119119
placeholder: z.string().or(z.function().returns(z.string()))
120120
}),
121-
serverSideError: z.strictObject({
122-
content: z.custom<ReactNode | FC>(...reactNode),
123-
labels: z.string()
124-
}),
125121
sidebar: z.strictObject({
126122
autoCollapse: z.boolean().optional(),
127123
defaultMenuCollapseLevel: z.number().min(1).int(),

‎packages/nextra/__test__/page-map.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('collectPageMap', () => {
2424
const rawJs = await collectPageMap({ dir, route: '/en', locale: 'en' })
2525

2626
expect(clean(rawJs)).toMatchInlineSnapshot(`
27-
"import examples_swr_site_pages_en_meta from \\"../../examples/swr-site/pages/en/_meta.json\\";
27+
"import examples_swr_site_pages_en_meta from \\"../../examples/swr-site/pages/en/_meta.ts\\";
2828
import examples_swr_site_pages_en_about_meta from \\"../../examples/swr-site/pages/en/about/_meta.ts\\";
2929
import examples_swr_site_pages_en_blog_meta from \\"../../examples/swr-site/pages/en/blog/_meta.ts\\";
3030
import examples_swr_site_pages_en_docs_meta from \\"../../examples/swr-site/pages/en/docs/_meta.tsx\\";

‎packages/nextra/src/server/constants.ts

-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ export const DEFAULT_CONFIG = {
3232

3333
export const OFFICIAL_THEMES = ['nextra-theme-docs', 'nextra-theme-blog']
3434

35-
export const META_FILENAME = '_meta.json'
36-
3735
export const META_REGEX = /_meta\.[jt]sx?$/
3836

3937
export const MARKDOWN_EXTENSIONS = ['md', 'mdx'] as const

‎packages/nextra/src/server/page-map.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import gracefulFs from 'graceful-fs'
66
import grayMatter from 'gray-matter'
77
import pLimit from 'p-limit'
88
import {
9+
CWD,
910
DEFAULT_PROPERTY_PROPS,
1011
IMPORT_FRONTMATTER,
1112
MARKDOWN_EXTENSION_REGEX,
12-
META_FILENAME,
1313
META_REGEX
1414
} from './constants.js'
1515
import { PAGES_DIR } from './file-system.js'
@@ -140,15 +140,20 @@ async function collectFiles({
140140
const fileName = name + ext
141141
const isMetaJs = META_REGEX.test(fileName)
142142

143-
if (fileName === META_FILENAME || isMetaJs) {
143+
if (fileName === '_meta.json') {
144+
throw new Error(
145+
'Support of "_meta.json" was removed, use "_meta.{js,jsx,ts,tsx}" instead. ' +
146+
`Refactor following file "${path.relative(CWD, filePath)}".`
147+
)
148+
}
149+
150+
if (isMetaJs) {
144151
const importName = cleanFileName(filePath)
145152
imports.push({ importName, filePath })
146153

147-
if (isMetaJs) {
148-
if (hasDynamicPage) {
149-
dynamicMetaImports.push({ importName, route })
150-
return
151-
}
154+
if (hasDynamicPage) {
155+
dynamicMetaImports.push({ importName, route })
156+
return
152157
}
153158
return createAstObject({
154159
data: { type: 'Identifier', name: importName }

0 commit comments

Comments
 (0)
Please sign in to comment.