Skip to content

Commit 22f98a6

Browse files
authored
tweak: notice of archived site (#597)
* fix: archive header * tweak: archive notice
1 parent 8d3d807 commit 22f98a6

File tree

8 files changed

+103
-79
lines changed

8 files changed

+103
-79
lines changed

gatsby/create-pages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ export const create404 = async ({
307307
path: "/404",
308308
component: template,
309309
context: {
310+
buildType: (process.env.WEBSITE_BUILD_TYPE ??
311+
DEFAULT_BUILD_TYPE) as BuildType,
310312
feature: {
311313
banner: false,
312314
},

src/components/Card/CustomNotice.tsx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import * as React from "react";
21
import { Link, Trans, useI18next } from "gatsby-plugin-react-i18next";
32
import Typography from "@mui/material/Typography";
43

5-
import { Locale, PathConfig } from "shared/interface";
4+
import { PathConfig } from "shared/interface";
65
import { docs } from "../../../docs/docs.json";
7-
import { Important, CustomAlert } from "components/MDXComponents";
8-
import { generateUrl } from "shared/utils";
9-
import LinkComponent from "components/Link";
6+
import { Important } from "components/MDXComponents";
107

118
interface Props {
129
name: string;
@@ -101,20 +98,3 @@ export const MachineTranslationNotice = ({ name, pathConfig }: Props) => {
10198
</Important>
10299
);
103100
};
104-
105-
export const ArchiveTiDBNotice = ({ name, pathConfig }: Props) => {
106-
const stableCfg = { ...pathConfig, version: "stable" };
107-
const path = generateUrl(name, stableCfg);
108-
const targetUrl = `https://docs.pingcap.com${path}`;
109-
return (
110-
<CustomAlert
111-
severity="error"
112-
title={<Trans i18nKey="shortcodes.important" />}
113-
>
114-
<Trans
115-
i18nKey={`doc.archive.tidb`}
116-
components={[<LinkComponent to={targetUrl} fontSize="inherit" />]}
117-
/>
118-
</CustomAlert>
119-
);
120-
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { ErrorOutlineOutlined, OpenInNewOutlined } from "@mui/icons-material";
2+
import { Box, Icon, Stack, Typography } from "@mui/material";
3+
import LinkComponent from "components/Link";
4+
import { PathConfig } from "shared/interface";
5+
import { generateUrl } from "shared/utils";
6+
7+
interface ArchiveBannerProps {
8+
name?: string;
9+
pathConfig?: PathConfig;
10+
}
11+
12+
export function ArchiveBanner({ name, pathConfig }: ArchiveBannerProps) {
13+
let targetUrl = `https://docs.pingcap.com`;
14+
if (name && pathConfig) {
15+
const stableCfg = { ...pathConfig, version: "stable" };
16+
const path = generateUrl(name, stableCfg);
17+
targetUrl = `https://docs.pingcap.com${path}`;
18+
}
19+
20+
return (
21+
<Box
22+
sx={{
23+
flexShrink: 0,
24+
minHeight: "1.5rem",
25+
backgroundColor: "#FEFBF3",
26+
backgroundPosition: "bottom left",
27+
backgroundSize: "400px auto",
28+
backgroundRepeat: "no-repeat",
29+
paddingTop: "0.5rem",
30+
paddingBottom: "0.5rem",
31+
}}
32+
>
33+
<Stack
34+
direction="row"
35+
justifyContent="center"
36+
alignItems="center"
37+
flexWrap="nowrap"
38+
spacing={1}
39+
sx={(theme) => ({
40+
color: "#AE6D0C",
41+
height: "100%",
42+
px: 2,
43+
[theme.breakpoints.down("md")]: {
44+
px: 1,
45+
},
46+
})}
47+
>
48+
<ErrorOutlineOutlined sx={{ fontSize: "1rem", color: "#F2AA18" }} />
49+
50+
<Typography component="span" variant="body2" color="inherit">
51+
You are viewing the archived documentation of TiDB, which no longer
52+
receives updates.
53+
</Typography>
54+
55+
<LinkComponent
56+
to={targetUrl}
57+
sx={{
58+
"&:hover": {
59+
textDecoration: "underline!important",
60+
},
61+
}}
62+
>
63+
<Stack direction="row" alignItems="center" spacing="4px">
64+
<Typography variant="body2" color="secondary">
65+
View latest LTS version docs
66+
</Typography>
67+
<OpenInNewOutlined
68+
sx={{
69+
fontSize: "1rem",
70+
color: "var(--tiui-palette-secondary)",
71+
}}
72+
/>
73+
</Stack>
74+
</LinkComponent>
75+
</Stack>
76+
</Box>
77+
);
78+
}

src/components/Layout/Header.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ import HeaderAction from "components/Layout/HeaderAction";
1212

1313
import TiDBLogo from "media/logo/tidb-logo-withtext.svg";
1414

15-
import { Locale, BuildType } from "shared/interface";
15+
import { Locale, BuildType, PathConfig } from "shared/interface";
1616
import { GTMEvent, gtmTrack } from "shared/utils/gtm";
1717
import { Banner } from "./Banner";
1818
import { generateDocsHomeUrl } from "shared/utils";
1919
import { useI18next } from "gatsby-plugin-react-i18next";
20-
20+
import { ArchiveBanner } from "./Banner/ArchiveBanner";
2121
export default function Header(props: {
2222
bannerEnabled?: boolean;
2323
menu?: React.ReactNode;
2424
locales: Locale[];
2525
docInfo?: { type: string; version: string };
2626
buildType?: BuildType;
2727
pageUrl?: string;
28+
name?: string;
29+
pathConfig?: PathConfig;
2830
}) {
2931
const { language } = useI18next();
3032
const theme = useTheme();
@@ -77,7 +79,10 @@ export default function Header(props: {
7779
buildType={props.buildType}
7880
/>
7981
</Toolbar>
80-
{props.bannerEnabled && <Banner />}
82+
{props.bannerEnabled && props.buildType !== "archive" && <Banner />}
83+
{props.buildType === "archive" && (
84+
<ArchiveBanner name={props.name} pathConfig={props.pathConfig} />
85+
)}
8186
</AppBar>
8287
);
8388
}

src/components/Layout/MDXContent.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as MDXComponents from "components/MDXComponents";
1010
import {
1111
CustomNotice,
1212
MachineTranslationNotice,
13-
ArchiveTiDBNotice,
1413
} from "components/Card/CustomNotice";
1514
import { PathConfig, FrontMatter, BuildType } from "shared/interface";
1615
import { useTotalContributors } from "components/Contributors";
@@ -63,13 +62,6 @@ export default function MDXContent(props: {
6362
return (
6463
<Container disableGutters className={className} maxWidth="lg">
6564
<Box className="markdown-body">
66-
{buildType === "archive" && typeof name !== "undefined" && (
67-
<ArchiveTiDBNotice
68-
name={name}
69-
pathConfig={pathConfig}
70-
availIn={availIn}
71-
/>
72-
)}
7365
{buildType !== "archive" && (
7466
<CustomNotice name={name} pathConfig={pathConfig} availIn={availIn} />
7567
)}

src/components/Layout/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "@fontsource/ibm-plex-sans";
88
import theme from "theme/index";
99
import Header from "components/Layout/Header";
1010
import Footer from "components/Layout/Footer";
11-
import { Locale, BuildType } from "shared/interface";
11+
import { Locale, BuildType, PathConfig } from "shared/interface";
1212

1313
export default function Layout(props: {
1414
children?: React.ReactNode;
@@ -18,6 +18,8 @@ export default function Layout(props: {
1818
docInfo?: { type: string; version: string };
1919
buildType?: BuildType;
2020
pageUrl?: string;
21+
name?: string;
22+
pathConfig?: PathConfig;
2123
}) {
2224
return (
2325
<ThemeProvider theme={theme}>
@@ -29,6 +31,8 @@ export default function Layout(props: {
2931
docInfo={props.docInfo}
3032
buildType={props.buildType}
3133
pageUrl={props.pageUrl}
34+
name={props.name}
35+
pathConfig={props.pathConfig}
3236
/>
3337
{props.children}
3438
<Footer />

src/templates/404Template.tsx

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Box from "@mui/material/Box";
99
import Typography from "@mui/material/Typography";
1010

1111
import Layout from "components/Layout";
12-
import { Locale } from "shared/interface";
12+
import { BuildType, Locale } from "shared/interface";
1313
import { Page404Icon } from "components/Icons";
1414
import Seo from "components/Layout/Seo";
1515

@@ -27,6 +27,7 @@ interface AllLocales {
2727

2828
interface PageNotFoundTemplateProps {
2929
pageContext: {
30+
buildType: BuildType;
3031
feature?: {
3132
banner?: boolean;
3233
};
@@ -35,7 +36,7 @@ interface PageNotFoundTemplateProps {
3536
}
3637

3738
export default function PageNotFoundTemplate({
38-
pageContext: { feature },
39+
pageContext: { feature, buildType },
3940
data,
4041
}: PageNotFoundTemplateProps) {
4142
const pathname =
@@ -72,13 +73,14 @@ export default function PageNotFoundTemplate({
7273
return i18n;
7374
}, [language, data]);
7475

75-
const bannerVisible = feature?.banner && language !== Locale.ja;
76+
const bannerVisible =
77+
(feature?.banner && language !== Locale.ja) || buildType === "archive";
7678

7779
return (
7880
<>
7981
<I18nextProvider i18n={i18n}>
8082
<I18nextContext.Provider value={{ ...context, language }}>
81-
<Layout bannerEnabled={bannerVisible}>
83+
<Layout bannerEnabled={bannerVisible} buildType={buildType}>
8284
<Seo lang={language as Locale} title="404 Not Found" noindex />
8385
<Container
8486
sx={{
@@ -123,13 +125,6 @@ export default function PageNotFoundTemplate({
123125
<Trans i18nKey="doc404.searchDoc" />
124126
</Typography>
125127
</Typography>
126-
{/* <div className={styles.searchInput}>
127-
<SearchInput
128-
docInfo={docInfo}
129-
searchValue={searchValue}
130-
setSearchValue={handleSetSearchValue}
131-
/>
132-
</div> */}
133128
</>
134129
)}
135130
</Stack>
@@ -153,40 +148,6 @@ export default function PageNotFoundTemplate({
153148
</Stack>
154149
</Container>
155150
</Layout>
156-
{/* <Layout is404={true}>
157-
<Seo title="404 Not Found" noindex />
158-
<div className={styles.container}>
159-
<div className={clsx('markdown-body', styles.left)}>
160-
<h1 className={clsx(styles.title)}>
161-
{<Trans i18nKey="doc404.title" />}
162-
</h1>
163-
{['en', 'zh'].includes(language) && (
164-
<>
165-
<div>{<Trans i18nKey="doc404.youMayWish" />}</div>
166-
<ul className={clsx(styles.optionsContainer)}>
167-
<li>
168-
{
169-
<Trans
170-
i18nKey="doc404.goToDocHome"
171-
components={[<Link to="/" />]}
172-
/>
173-
}
174-
</li>
175-
<li>{<Trans i18nKey="doc404.searchDoc" />}</li>
176-
</ul>
177-
<div className={styles.searchInput}>
178-
<SearchInput
179-
docInfo={docInfo}
180-
searchValue={searchValue}
181-
setSearchValue={handleSetSearchValue}
182-
/>
183-
</div>
184-
</>
185-
)}
186-
</div>
187-
<div className={clsx(styles.right)}></div>
188-
</div>
189-
</Layout> */}
190151
</I18nextContext.Provider>
191152
</I18nextProvider>
192153
</>

src/templates/DocTemplate.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export default function DocTemplate({
9191

9292
return (
9393
<Layout
94+
name={name}
95+
pathConfig={pathConfig}
9496
locales={availIn.locale}
9597
bannerEnabled={bannerVisible}
9698
pageUrl={pageUrl}

0 commit comments

Comments
 (0)