-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththeme.config.tsx
127 lines (118 loc) · 3.81 KB
/
theme.config.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React from "react";
import { DocsThemeConfig, useConfig } from "nextra-theme-docs";
import { useRouter } from "nextra/hooks";
import Image from "next/image";
import logo from "public/logo.svg";
import Link from "next/link";
import { authorsMap, backToTopMap, defaultDescriptionMap, editTextMap, feedbackLinkMap, footerMap, gitTimestampMap, logoTextMap, searchPlaceholderMap, tableOfContentsMap, titleTextMap } from "translations/site";
import { useTranslation } from "translations/useTranslation";
const config: DocsThemeConfig = {
logo: () => {
const logoText = useTranslation(logoTextMap);
return (
<>
<Image src={logo} alt="ZZ Logo" width={40} />
<span>{logoText}</span>
</>
)
},
search: {
placeholder: () => useTranslation(searchPlaceholderMap)
},
project: {
link: "https://github.com/ericx20/zz-method-docs",
},
// chat: {
// link: "https://discord.com",
// },
docsRepositoryBase: "https://github.com/ericx20/zz-method-docs/tree/main",
// banner: {
// key: "example-solve-library-release",
// text: <Link href="/blog/zz-example-solve-library">Introducing the ZZ Example Solve Library!</Link>,
// },
i18n: [
{ locale: 'en', name: 'English' },
// { locale: 'fr', name: 'Français' },
// { locale: 'he', name: 'עִברִית', direction: 'rtl' },
// { locale: 'zh', name: '中文' },
],
head() {
const { asPath, defaultLocale, locale } = useRouter();
const { frontMatter } = useConfig();
const url =
"https://zzmethod.com" +
(defaultLocale === locale ? asPath : `/${locale}${asPath}`);
const isHomepage = asPath === "/" || asPath === `/${locale}${asPath}`;
const titleText = useTranslation(titleTextMap);
const defaultDescription = useTranslation(defaultDescriptionMap);
return (
<>
<title>{(isHomepage || !frontMatter.title) ? titleText : `${frontMatter.title} – ${titleText}`}</title>
<meta property="og:url" content={url} />
<meta property="og:title" content={frontMatter.title || titleText} />
<meta
property="og:description"
content={
frontMatter.description || defaultDescription
}
/>
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="icon" href="/favicon.png" type="image/png" />
</>
);
},
main: ({ children }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const { frontMatter } = useConfig();
const authorsTextFn = useTranslation(authorsMap);
return (
<>
<h1 className="_mt-2 _mb-2 _text-4xl _font-bold _tracking-tight">
{frontMatter?.title}
</h1>
{frontMatter?.date && (
<p className="_block _text-sm _text-gray-500 dark:_text-gray-400">
{frontMatter.date}
</p>
)}
{frontMatter?.author && (
<p className="_block _text-sm _text-gray-500 dark:_text-gray-400">
{authorsTextFn(frontMatter.author)}
</p>
)}
<div>{children}</div>
</>
);
},
toc: {
float: true,
title: () => useTranslation(tableOfContentsMap),
backToTop: () => useTranslation(backToTopMap),
},
feedback: {
content: () => useTranslation(feedbackLinkMap)
},
editLink: {
content: () => useTranslation(editTextMap)
},
gitTimestamp: ({ timestamp }) => {
const { locale } = useRouter();
const lastUpdatedOn = useTranslation(gitTimestampMap);
return (
<>
{lastUpdatedOn}{" "}
<time dateTime={timestamp.toISOString()}>
{timestamp.toLocaleDateString(locale, {
day: "numeric",
month: "long",
year: "numeric",
})}
</time>
</>
)
},
footer: {
content: () => useTranslation(footerMap),
},
};
export default config;