-
Notifications
You must be signed in to change notification settings - Fork 351
/
theme.config.js
162 lines (154 loc) · 4.53 KB
/
theme.config.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { useRouter } from "next/router";
import { useConfig } from "nextra-theme-docs";
import Logo from "./components/logo";
import Vercel from "./components/vercel";
import useLocalesMap from "./components/use-locales-map";
import {
editTextMap,
feedbackLinkMap,
footerTextMap,
gitTimestampMap,
headDescriptionMap,
languageMap,
searchPlaceholderMap,
tableOfContentsTitleMap,
titleMap,
} from "./translations/text";
/** @type {import('nextra-theme-docs').DocsThemeConfig} */
const themeConfig = {
project: {
link: "https://github.com/vercel/swr",
},
docsRepositoryBase: "https://github.com/vercel/swr-site/blob/main",
useNextSeoProps() {
return {
titleTemplate: "%s – SWR",
};
},
toc: {
float: true,
title: () => useLocalesMap(tableOfContentsTitleMap),
},
search: {
placeholder: () => useLocalesMap(searchPlaceholderMap),
},
editLink: {
text: () => useLocalesMap(editTextMap),
},
feedback: {
content: () => useLocalesMap(feedbackLinkMap),
},
logo: () => {
const title = useLocalesMap(titleMap);
return (
<>
<Logo height={12} />
<span
className="mx-2 font-extrabold hidden md:inline select-none"
title={`SWR: ${title}`}
>
SWR
</span>
</>
);
},
head: () => {
const { route, locales, locale } = useRouter();
const { frontMatter, title } = useConfig();
const titleSuffix = useLocalesMap(titleMap);
const description = useLocalesMap(headDescriptionMap);
const imageUrl = new URL("https://swr-card.vercel.app");
if (!/\/index\.+/.test(route)) {
imageUrl.searchParams.set("title", title || titleSuffix);
}
const contentLanguage = locales.join(", ");
const ogTitle = title ? `${title} – SWR` : `SWR: ${titleSuffix}`;
const ogDescription = frontMatter.description || description;
const ogImage = frontMatter.image || imageUrl.toString();
return (
<>
{/* Favicons, meta */}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicon/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicon/favicon-16x16.png"
/>
<link rel="icon" type="image/svg+xml" href="/favicon/favicon.svg" />
<link rel="manifest" href="/favicon/site.webmanifest" />
<link
rel="mask-icon"
href="/favicon/safari-pinned-tab.svg"
color="#000000"
/>
<meta httpEquiv="Content-Language" content={contentLanguage} />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="apple-mobile-web-app-title" content="SWR" />
<meta name="description" content={ogDescription} />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@vercel" />
<meta name="twitter:image" content={ogImage} />
<meta property="og:title" content={ogTitle} />
<meta property="og:description" content={ogDescription} />
<meta property="og:image" content={ogImage} />
<meta property="og:locale" content={locale} />
{locales
.filter((l) => l !== locale)
.map((l) => (
<meta property="og:locale:alternate" content={l} key={l} />
))}
</>
);
},
footer: {
text: () => {
const { utmSource, text, suffix } = useLocalesMap(footerTextMap);
return (
<a
href={`https://vercel.com/?utm_source=${utmSource}`}
target="_blank"
rel="noopener"
className="inline-flex items-center no-underline text-current font-semibold"
>
<span className="mr-2">{text}</span>
<span>
<Vercel />
</span>
{suffix ? <span className="ml-2">{suffix}</span> : null}
</a>
);
},
},
gitTimestamp({ timestamp }) {
const { locale } = useRouter();
const lastUpdatedOn = useLocalesMap(gitTimestampMap);
return (
<>
{lastUpdatedOn}{" "}
<time dateTime={timestamp.toISOString()}>
{timestamp.toLocaleDateString(locale, {
day: "numeric",
month: "long",
year: "numeric",
})}
</time>
</>
);
},
i18n: Object.entries(languageMap).map(([locale, text]) => ({
locale,
text,
})),
};
export default themeConfig;