Skip to content

Commit b9f88e3

Browse files
author
Dimitri POSTOLOV
authoredSep 7, 2023
[v3] remove use-internals.ts, remove layout.tsx, move directly to setup-page.tsx (#2268)

25 files changed

+132
-813
lines changed
 

‎.changeset/popular-pianos-smoke.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'nextra': major
3+
---
4+
5+
- remove `use-internals.ts`
6+
7+
- remove `layout.tsx`, move directly to `setup-page.tsx`
8+
9+
- remove `kind: 'Meta' | 'Folder' | 'MdxPage'` to keep page map smaller

‎packages/nextra-theme-blog/__test__/__fixture__/pageMap.ts

-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const indexOpts: BlogPageOpts = {
99
},
1010
pageMap: [
1111
{
12-
kind: 'MdxPage',
1312
name: 'index',
1413
route: '/',
1514
frontMatter: {
@@ -19,11 +18,9 @@ export const indexOpts: BlogPageOpts = {
1918
}
2019
},
2120
{
22-
kind: 'Folder',
2321
name: 'posts',
2422
children: [
2523
{
26-
kind: 'MdxPage',
2724
name: 'aaron-swartz-a-programmable-web',
2825
route: '/posts/aaron-swartz-a-programmable-web',
2926
frontMatter: {
@@ -36,7 +33,6 @@ export const indexOpts: BlogPageOpts = {
3633
}
3734
},
3835
{
39-
kind: 'MdxPage',
4036
name: 'index',
4137
route: '/posts',
4238
frontMatter: {
@@ -49,11 +45,9 @@ export const indexOpts: BlogPageOpts = {
4945
route: '/posts'
5046
},
5147
{
52-
kind: 'Folder',
5348
name: 'tags',
5449
children: [
5550
{
56-
kind: 'MdxPage',
5751
name: '[tag]',
5852
route: '/tags/[tag]',
5953
frontMatter: {
@@ -83,7 +77,6 @@ export const postsOpts: BlogPageOpts = {
8377
},
8478
pageMap: [
8579
{
86-
kind: 'MdxPage',
8780
name: 'index',
8881
route: '/',
8982
frontMatter: {
@@ -93,11 +86,9 @@ export const postsOpts: BlogPageOpts = {
9386
}
9487
},
9588
{
96-
kind: 'Folder',
9789
name: 'posts',
9890
children: [
9991
{
100-
kind: 'MdxPage',
10192
name: 'aaron-swartz-a-programmable-web',
10293
route: '/posts/aaron-swartz-a-programmable-web',
10394
frontMatter: {
@@ -110,7 +101,6 @@ export const postsOpts: BlogPageOpts = {
110101
}
111102
},
112103
{
113-
kind: 'MdxPage',
114104
name: 'index',
115105
route: '/posts',
116106
frontMatter: {
@@ -123,11 +113,9 @@ export const postsOpts: BlogPageOpts = {
123113
route: '/posts'
124114
},
125115
{
126-
kind: 'Folder',
127116
name: 'tags',
128117
children: [
129118
{
130-
kind: 'MdxPage',
131119
name: '[tag]',
132120
route: '/tags/[tag]',
133121
frontMatter: {
@@ -160,7 +148,6 @@ export const articleOpts: BlogPageOpts = {
160148
},
161149
pageMap: [
162150
{
163-
kind: 'MdxPage',
164151
name: 'index',
165152
route: '/',
166153
frontMatter: {
@@ -170,11 +157,9 @@ export const articleOpts: BlogPageOpts = {
170157
}
171158
},
172159
{
173-
kind: 'Folder',
174160
name: 'posts',
175161
children: [
176162
{
177-
kind: 'MdxPage',
178163
name: 'aaron-swartz-a-programmable-web',
179164
route: '/posts/aaron-swartz-a-programmable-web',
180165
frontMatter: {
@@ -187,7 +172,6 @@ export const articleOpts: BlogPageOpts = {
187172
}
188173
},
189174
{
190-
kind: 'MdxPage',
191175
name: 'index',
192176
route: '/posts',
193177
frontMatter: {
@@ -200,11 +184,9 @@ export const articleOpts: BlogPageOpts = {
200184
route: '/posts'
201185
},
202186
{
203-
kind: 'Folder',
204187
name: 'tags',
205188
children: [
206189
{
207-
kind: 'MdxPage',
208190
name: '[tag]',
209191
route: '/tags/[tag]',
210192
frontMatter: {

‎packages/nextra-theme-blog/__test__/collect.spec.ts

-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ describe('collect', () => {
2626
"title": "Random Thoughts",
2727
"type": "posts",
2828
},
29-
"kind": "MdxPage",
3029
"name": "index",
3130
"route": "/posts",
3231
},
@@ -37,7 +36,6 @@ describe('collect', () => {
3736
"title": "About",
3837
"type": "page",
3938
},
40-
"kind": "MdxPage",
4139
"name": "index",
4240
"route": "/",
4341
},
@@ -51,7 +49,6 @@ describe('collect', () => {
5149
"tag": "web development",
5250
"title": "Notes on A Programmable Web by Aaron Swartz",
5351
},
54-
"kind": "MdxPage",
5552
"name": "aaron-swartz-a-programmable-web",
5653
"route": "/posts/aaron-swartz-a-programmable-web",
5754
},
@@ -72,7 +69,6 @@ describe('collect', () => {
7269
"title": "Random Thoughts",
7370
"type": "posts",
7471
},
75-
"kind": "MdxPage",
7672
"name": "index",
7773
"route": "/posts",
7874
},
@@ -83,7 +79,6 @@ describe('collect', () => {
8379
"title": "About",
8480
"type": "page",
8581
},
86-
"kind": "MdxPage",
8782
"name": "index",
8883
"route": "/",
8984
},
@@ -97,7 +92,6 @@ describe('collect', () => {
9792
"tag": "web development",
9893
"title": "Notes on A Programmable Web by Aaron Swartz",
9994
},
100-
"kind": "MdxPage",
10195
"name": "aaron-swartz-a-programmable-web",
10296
"route": "/posts/aaron-swartz-a-programmable-web",
10397
},
@@ -120,7 +114,6 @@ describe('collect', () => {
120114
"title": "Random Thoughts",
121115
"type": "posts",
122116
},
123-
"kind": "MdxPage",
124117
"name": "index",
125118
"route": "/posts",
126119
},
@@ -131,7 +124,6 @@ describe('collect', () => {
131124
"title": "About",
132125
"type": "page",
133126
},
134-
"kind": "MdxPage",
135127
"name": "index",
136128
"route": "/",
137129
},
@@ -145,7 +137,6 @@ describe('collect', () => {
145137
"tag": "web development",
146138
"title": "Notes on A Programmable Web by Aaron Swartz",
147139
},
148-
"kind": "MdxPage",
149140
"name": "aaron-swartz-a-programmable-web",
150141
"route": "/posts/aaron-swartz-a-programmable-web",
151142
},

‎packages/nextra-theme-blog/__test__/parent.spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ describe('parent', () => {
2121
"title": "Random Thoughts",
2222
"type": "posts",
2323
},
24-
"kind": "MdxPage",
2524
"name": "index",
2625
"route": "/posts",
2726
},

‎packages/nextra-theme-blog/src/utils/collect.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ const isNav = (page: PageMapItem): page is MdxFile => {
99
return type && ['page', 'posts'].includes(type)
1010
}
1111
const isPost = (page: PageMapItem): page is MdxFile => {
12-
if (
13-
page.kind === 'Folder' ||
14-
page.kind === 'Meta' ||
15-
page.name.startsWith('_')
16-
)
12+
if ('children' in page || 'data' in page || page.name.startsWith('_'))
1713
return false
1814
const { draft, type } = page.frontMatter || {}
1915
return !draft && (!type || type === 'post')

‎packages/nextra-theme-blog/src/utils/traverse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function traverse(
1212
}
1313

1414
for (const item of pageMap) {
15-
if (item.kind === 'Folder') {
15+
if ('children' in item) {
1616
const matched = traverse(item.children, matcher)
1717
if (matched) {
1818
return matched

‎packages/nextra-theme-docs/src/contexts/config.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function normalizeZodMessage(error: unknown): string {
4444

4545
function validateMeta(pageMap: PageMapItem[]) {
4646
for (const pageMapItem of pageMap) {
47-
if (pageMapItem.kind === 'Meta') {
47+
if ('data' in pageMapItem) {
4848
for (const [key, data] of Object.entries(pageMapItem.data)) {
4949
try {
5050
metaSchema.parse(data)
@@ -56,7 +56,7 @@ function validateMeta(pageMap: PageMapItem[]) {
5656
)
5757
}
5858
}
59-
} else if (pageMapItem.kind === 'Folder') {
59+
} else if ('children' in pageMapItem) {
6060
validateMeta(pageMapItem.children)
6161
}
6262
}

0 commit comments

Comments
 (0)
Please sign in to comment.