Skip to content

Commit eb943d0

Browse files
author
Dimitri POSTOLOV
authoredJan 9, 2024
[v3] hardcode flexsearch version to 0.7.31, because package is broken on 0.7.41 (#2615)
* a * add `theme.topContent` and `theme.bottomContent` * prettier * update snapshot * remove warnings * fix tests * prettier
1 parent c2ad837 commit eb943d0

File tree

21 files changed

+189
-101
lines changed

21 files changed

+189
-101
lines changed
 

‎.changeset/big-otters-breathe.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextra-theme-docs': minor
3+
---
4+
5+
add `theme.topContent` and `theme.bottomContent`

‎.changeset/ten-cougars-tell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nextra-theme-docs': patch
3+
---
4+
5+
hardcode flexsearch version to 0.7.31, because package is broken on 0.7.41

‎examples/swr-site/components/authors.tsx

-23
This file was deleted.

‎examples/swr-site/components/blog.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@ export function Blog() {
1111
href={page.route}
1212
className="text-2xl text-black hover:!no-underline dark:text-gray-100"
1313
>
14-
{page.meta.title || page.frontMatter?.title || page.name}
14+
{page.meta?.title || page.frontMatter.title || page.name}
1515
</Link>
1616
<p className="opacity-80 mt-6 leading-7">
17-
{page.frontMatter?.description}
17+
{page.frontMatter.description}
1818
<Link
1919
href={page.route}
2020
className="block _text-primary-600 underline underline-offset-2 decoration-from-font"
2121
>
2222
Read more →
2323
</Link>
2424
</p>
25-
<p>{page.date}</p>
25+
<time dateTime={page.frontMatter.date.toISOString()} className="text-sm">
26+
{page.frontMatter.date.toLocaleDateString(locale, {
27+
month: 'long',
28+
day: 'numeric',
29+
year: 'numeric'
30+
})}
31+
</time>
2632
</div>
2733
))
2834
}

‎examples/swr-site/components/diagrams/use-draw.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { useRouter } from 'nextra/hooks'
22

33
export function useDraw(paths = {}, name = '') {
4-
const { locale, defaultLocale } = useRouter()
4+
const { locale, defaultLocale } = useRouter() as {
5+
locale: string
6+
defaultLocale: string
7+
}
58

69
if (!Object.hasOwn(paths, defaultLocale)) {
710
throw new Error(

‎examples/swr-site/components/features.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ const FEATURES_WITH_TRANSLATIONS = {
4141

4242
export default function Features() {
4343
const { locale, defaultLocale } = useRouter()
44+
4445
const featureText = key =>
45-
FEATURES_WITH_TRANSLATIONS[locale]?.[key] ??
46-
FEATURES_WITH_TRANSLATIONS[defaultLocale][key] // Fallback for missing translations
46+
FEATURES_WITH_TRANSLATIONS[locale!]?.[key] ??
47+
FEATURES_WITH_TRANSLATIONS[defaultLocale!][key] // Fallback for missing translations
4748

4849
return (
4950
<div className="mx-auto mb-10 w-[880px] max-w-full px-4 text-center">
5051
<p className="mb-2 text-lg text-gray-600 md:!text-2xl">
51-
{TITLE_WITH_TRANSLATIONS[locale]}
52+
{TITLE_WITH_TRANSLATIONS[locale!]}
5253
</p>
5354
<div className={styles.features}>
5455
<Feature

‎examples/swr-site/next-env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/basic-features/typescript for more information.

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

-8
This file was deleted.
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { useConfig } from 'nextra-theme-docs'
2+
import { useRouter } from 'nextra/hooks'
3+
4+
const text = {
5+
en: 'by',
6+
ru: 'от',
7+
es: 'por'
8+
}
9+
10+
export function Authors({ date, children }) {
11+
date = new Date(date)
12+
const { locale } = useRouter()
13+
return (
14+
<div className="mb-16 mt-8 text-sm text-gray-400">
15+
<time dateTime={date.toISOString()}>
16+
{date.toLocaleDateString(locale, {
17+
month: 'long',
18+
day: 'numeric',
19+
year: 'numeric'
20+
})}
21+
</time>{' '}
22+
{text[locale!]} {children}
23+
</div>
24+
)
25+
}
26+
27+
export function Author({ name, link }) {
28+
return (
29+
<span className="[&:not(:last-child)]:after:content-[',_']">
30+
<a
31+
href={link}
32+
target="_blank"
33+
rel="noreferrer"
34+
className="text-gray-800 dark:text-gray-100"
35+
>
36+
{name}
37+
</a>
38+
</span>
39+
)
40+
}
41+
42+
function TopContent() {
43+
const config = useConfig()
44+
return (
45+
<>
46+
<h1>{config.frontMatter.title}</h1>
47+
<Authors date={config.frontMatter.date}>
48+
{config.frontMatter.authors.map(author => (
49+
<Author key={author.name} name={author.name} link={author.link} />
50+
))}
51+
</Authors>
52+
</>
53+
)
54+
}
55+
56+
export default {
57+
'*': {
58+
theme: {
59+
breadcrumb: true,
60+
topContent: TopContent
61+
}
62+
}
63+
}

‎examples/swr-site/pages/en/blog/swr-v1.mdx

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
---
2+
title: Announcing SWR 1.0
23
image: https://assets.vercel.com/image/upload/v1630059453/swr/v1.png
34
description:
45
'Almost 2 years ago we open sourced SWR, the tiny data-fetching React library
56
that people love. Today we are reaching another milestone: the 1.0 version of
6-
SWR.'
7+
SWR'
8+
date: 2021-08-27
9+
authors:
10+
- name: Shu Ding
11+
link: https://twitter.com/shuding_
12+
- name: Jiachi Liu
13+
link: https://twitter.com/huozhi
714
---
815

9-
import Authors, { Author } from '@components/authors'
10-
11-
# Announcing SWR 1.0
12-
13-
<Authors date="August 27th, 2021">
14-
<Author name="Shu Ding" link="https://twitter.com/shuding_" />
15-
<Author name="Jiachi Liu" link="https://twitter.com/huozhi" />
16-
</Authors>
17-
1816
Almost 2 years ago we
1917
[open sourced](https://twitter.com/vercel/status/1188911002626097157) SWR, the
2018
tiny data-fetching React library that people love. Today we are reaching another
+1-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
export default {
2-
'swr-v1': {
3-
title: 'Представляем SWR 1.0',
4-
theme: {
5-
breadcrumb: true
6-
}
7-
}
8-
}
1+
export { default } from '../../en/blog/_meta'

‎examples/swr-site/pages/ru/blog/swr-v1.mdx

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
---
2+
title: Представляем SWR 1.0
23
image: https://assets.vercel.com/image/upload/v1630059453/swr/v1.png
34
description:
45
'Почти 2 года назад мы сделали SWR — крошечную React библиотеку с открытым
56
исходным кодом для выборки данных, которую люди полюбили. Сегодня мы
67
приближаемся к еще одной вехе: версии 1.0 SWR!'
8+
date: 2021-08-27
9+
authors:
10+
- name: Shu Ding
11+
link: https://twitter.com/shuding_
12+
- name: Jiachi Liu
13+
link: https://twitter.com/huozhi
714
---
815

9-
import Authors, { Author } from '@components/authors'
10-
11-
# Представляем SWR 1.0
12-
13-
<Authors date="27 августа 2021">
14-
<Author name="Shu Ding" link="https://twitter.com/shuding_" />
15-
<Author name="Jiachi Liu" link="https://twitter.com/huozhi" />
16-
</Authors>
17-
1816
Почти 2 года назад мы сделали SWR — крошечную React библиотеку с
1917
[открытым исходным кодом](https://twitter.com/vercel/status/1188911002626097157)
2018
для выборки данных, которую люди полюбили. Сегодня мы приближаемся к еще одной

‎examples/swr-site/theme.config.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const config: DocsThemeConfig = {
7575
editLink: {
7676
content: function useText() {
7777
const { locale } = useRouter()
78-
return EDIT_TEXT[locale]
78+
return EDIT_TEXT[locale!]
7979
}
8080
},
8181
feedback: {
@@ -96,9 +96,9 @@ const config: DocsThemeConfig = {
9696
rel="noreferrer"
9797
target="_blank"
9898
className="flex items-center gap-2 font-semibold"
99-
href={FOOTER_LINK[locale]}
99+
href={FOOTER_LINK[locale!]}
100100
>
101-
{FOOTER_LINK_TEXT[locale]}
101+
{FOOTER_LINK_TEXT[locale!]}
102102
</a>
103103
)
104104
}
@@ -164,7 +164,7 @@ const config: DocsThemeConfig = {
164164
<SWRLogo className="h-3" />
165165
<span
166166
className="max-md:hidden select-none font-extrabold ltr:ml-2 rtl:mr-2"
167-
title={`SWR: ${TITLE[locale] || ''}`}
167+
title={`SWR: ${TITLE[locale!] || ''}`}
168168
>
169169
SWR
170170
</span>

‎examples/swr-site/tsconfig.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
"baseUrl": "./",
1818
"paths": {
1919
"@components/*": ["./components/*"]
20-
}
20+
},
21+
"plugins": [
22+
{
23+
"name": "next"
24+
}
25+
],
26+
"strictNullChecks": true
2127
},
22-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
28+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "./.next/types/**/*.ts"],
2329
"exclude": ["node_modules"]
2430
}

‎packages/nextra-theme-docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@popperjs/core": "^2.11.8",
4141
"clsx": "^2.0.0",
4242
"escape-string-regexp": "^5.0.0",
43-
"flexsearch": "^0.7.31",
43+
"flexsearch": "0.7.31",
4444
"focus-visible": "^5.2.0",
4545
"intersection-observer": "^0.12.2",
4646
"next-themes": "^0.2.1",

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

+2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ function Body({ children }: { children: ReactNode }): ReactElement {
225225

226226
const content = (
227227
<>
228+
{renderComponent(themeContext.topContent)}
228229
{children}
229230
{gitTimestampEl}
231+
{renderComponent(themeContext.bottomContent)}
230232
{activeType !== 'page' && themeContext.pagination && (
231233
<NavLinks
232234
flatDirectories={flatDocsDirectories}

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

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1+
import { fc, reactNode } from 'nextra/schemas'
12
import type { FC, ReactNode } from 'react'
2-
import { isValidElement } from 'react'
33
import { z } from 'zod'
44
import type { NavBarProps } from './components/navbar'
55
import type { TOCProps } from './components/toc'
66

7-
function isReactNode(value: unknown): boolean {
8-
return (
9-
value == null ||
10-
typeof value === 'string' ||
11-
isFunction(value) ||
12-
isValidElement(value as any)
13-
)
14-
}
15-
16-
function isFunction(value: unknown): boolean {
17-
return typeof value === 'function'
18-
}
19-
207
const i18nSchema = /* @__PURE__ */ (() =>
218
z.array(
229
z.strictObject({
@@ -26,12 +13,6 @@ const i18nSchema = /* @__PURE__ */ (() =>
2613
})
2714
))()
2815

29-
const reactNode = [
30-
isReactNode,
31-
{ message: 'Must be React.ReactNode or React.FC' }
32-
] as const
33-
const fc = [isFunction, { message: 'Must be React.FC' }] as const
34-
3516
export const themeOptionsSchema = /* @__PURE__ */ (() =>
3617
z.strictObject({
3718
light: z.string(),

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

+29-5
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,31 @@ exports[`Page Process > should match i18n site page maps 1`] = `
118118
"children": [
119119
{
120120
"data": {
121-
"swr-v1": {
121+
"*": {
122122
"theme": {
123123
"breadcrumb": true,
124+
"topContent": [Function],
124125
},
125-
"title": "Announcing SWR 1.0",
126126
},
127127
},
128128
},
129129
{
130130
"frontMatter": {
131-
"description": "Almost 2 years ago we open sourced SWR, the tiny data-fetching React library that people love. Today we are reaching another milestone: the 1.0 version of SWR.",
131+
"authors": [
132+
{
133+
"link": "https://twitter.com/shuding_",
134+
"name": "Shu Ding",
135+
},
136+
{
137+
"link": "https://twitter.com/huozhi",
138+
"name": "Jiachi Liu",
139+
},
140+
],
141+
"date": 2021-08-27T00:00:00.000Z,
142+
"description": "Almost 2 years ago we open sourced SWR, the tiny data-fetching React library that people love. Today we are reaching another milestone: the 1.0 version of SWR",
132143
"image": "https://assets.vercel.com/image/upload/v1630059453/swr/v1.png",
133144
"sidebar_label": "SWR V1",
145+
"title": "Announcing SWR 1.0",
134146
},
135147
"name": "swr-v1",
136148
"route": "/en/blog/swr-v1",
@@ -923,19 +935,31 @@ exports[`Page Process > should match i18n site page maps 1`] = `
923935
"children": [
924936
{
925937
"data": {
926-
"swr-v1": {
938+
"*": {
927939
"theme": {
928940
"breadcrumb": true,
941+
"topContent": [Function],
929942
},
930-
"title": "Представляем SWR 1.0",
931943
},
932944
},
933945
},
934946
{
935947
"frontMatter": {
948+
"authors": [
949+
{
950+
"link": "https://twitter.com/shuding_",
951+
"name": "Shu Ding",
952+
},
953+
{
954+
"link": "https://twitter.com/huozhi",
955+
"name": "Jiachi Liu",
956+
},
957+
],
958+
"date": 2021-08-27T00:00:00.000Z,
936959
"description": "Почти 2 года назад мы сделали SWR — крошечную React библиотеку с открытым исходным кодом для выборки данных, которую люди полюбили. Сегодня мы приближаемся к еще одной вехе: версии 1.0 SWR!",
937960
"image": "https://assets.vercel.com/image/upload/v1630059453/swr/v1.png",
938961
"sidebar_label": "SWR V1",
962+
"title": "Представляем SWR 1.0",
939963
},
940964
"name": "swr-v1",
941965
"route": "/ru/blog/swr-v1",

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('collectPageMap', () => {
2424
expect(rawJs).toMatchInlineSnapshot(`
2525
"import examples_swr_site_pages_en_meta from \\"../../../../../examples/swr-site/pages/en/_meta.ts\\";
2626
import examples_swr_site_pages_en_about_meta from \\"../../../../../examples/swr-site/pages/en/about/_meta.ts\\";
27-
import examples_swr_site_pages_en_blog_meta from \\"../../../../../examples/swr-site/pages/en/blog/_meta.ts\\";
27+
import examples_swr_site_pages_en_blog_meta from \\"../../../../../examples/swr-site/pages/en/blog/_meta.tsx\\";
2828
import examples_swr_site_pages_en_docs_meta from \\"../../../../../examples/swr-site/pages/en/docs/_meta.tsx\\";
2929
import examples_swr_site_pages_en_docs_advanced_meta from \\"../../../../../examples/swr-site/pages/en/docs/advanced/_meta.tsx\\";
3030
import examples_swr_site_pages_en_examples_meta from \\"../../../../../examples/swr-site/pages/en/examples/_meta.ts\\";
@@ -72,8 +72,17 @@ describe('collectPageMap', () => {
7272
route: \\"/en/blog/swr-v1\\",
7373
frontMatter: {
7474
\\"sidebar_label\\": \\"SWR V1\\",
75+
\\"title\\": \\"Announcing SWR 1.0\\",
7576
\\"image\\": \\"https://assets.vercel.com/image/upload/v1630059453/swr/v1.png\\",
76-
\\"description\\": \\"Almost 2 years ago we open sourced SWR, the tiny data-fetching React library that people love. Today we are reaching another milestone: the 1.0 version of SWR.\\"
77+
\\"description\\": \\"Almost 2 years ago we open sourced SWR, the tiny data-fetching React library that people love. Today we are reaching another milestone: the 1.0 version of SWR\\",
78+
\\"date\\": new Date(1630022400000),
79+
\\"authors\\": [{
80+
\\"name\\": \\"Shu Ding\\",
81+
\\"link\\": \\"https://twitter.com/shuding_\\"
82+
}, {
83+
\\"name\\": \\"Jiachi Liu\\",
84+
\\"link\\": \\"https://twitter.com/huozhi\\"
85+
}]
7786
}
7887
}]
7988
}, {

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
import type { ProcessorOptions } from '@mdx-js/mdx'
22
import type { MathJax3Config } from 'better-react-mathjax'
3+
import type { FC, ReactNode } from 'react'
4+
import { isValidElement } from 'react'
35
import type { Options as RehypeKatexOptions } from 'rehype-katex'
46
import type { Options as RehypePrettyCodeOptions } from 'rehype-pretty-code'
57
import { z } from 'zod'
68
import type { PageOpts } from '../types'
79

10+
function isFunction(value: unknown): boolean {
11+
return typeof value === 'function'
12+
}
13+
14+
export const fc = [isFunction, { message: 'Must be React.FC' }] as const
15+
16+
function isReactNode(value: unknown): boolean {
17+
return (
18+
value == null ||
19+
typeof value === 'string' ||
20+
isFunction(value) ||
21+
isValidElement(value as any)
22+
)
23+
}
24+
25+
export const reactNode = [
26+
isReactNode,
27+
{ message: 'Must be React.ReactNode or React.FC' }
28+
] as const
29+
830
export const searchSchema = z.boolean().or(
931
z.strictObject({
1032
/**
@@ -96,7 +118,9 @@ export const pageThemeSchema = z.strictObject({
96118
sidebar: z.boolean(),
97119
timestamp: z.boolean(),
98120
toc: z.boolean(),
99-
typesetting: z.enum(['default', 'article'])
121+
typesetting: z.enum(['default', 'article']),
122+
topContent: z.custom<ReactNode | FC>(...reactNode),
123+
bottomContent: z.custom<ReactNode | FC>(...reactNode)
100124
})
101125

102126
/**

‎pnpm-lock.yaml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.