Browse Source

site: fix 404 page (#40366)

pull/40506/head
afc163 2 years ago
committed by GitHub
parent
commit
8f5f7cf814
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      .dumi/pages/404/index.tsx
  2. 13
      .dumi/theme/common/CommonHelmet.tsx
  3. 26
      .dumi/theme/slots/Content/index.tsx

40
.dumi/pages/404/index.tsx

@ -32,33 +32,25 @@ const NotFoundPage: React.FC<NotFoundProps> = ({ router }) => {
// Report if necessary
const { yuyanMonitor } = window as any;
if (yuyanMonitor) {
yuyanMonitor.log({
code: 11,
msg: `Page not found: ${location.href}; Source: ${document.referrer}`,
});
}
yuyanMonitor?.log({
code: 11,
msg: `Page not found: ${location.href}; Source: ${document.referrer}`,
});
}, []);
return (
<div id="page-404">
<section>
<Result
status="404"
title="404"
subTitle={
isZhCN ? '你访问的页面貌似不存在?' : 'Sorry, the page you visited does not exist.'
}
extra={
<Link to={utils.getLocalizedPathname('/', isZhCN)}>
<Button type="primary" icon={<HomeOutlined />}>
{isZhCN ? '返回 Ant Design 首页' : 'Back to home page'}
</Button>
</Link>
}
/>
</section>
</div>
<Result
status="404"
title="404"
subTitle={isZhCN ? '你访问的页面貌似不存在?' : 'Sorry, the page you visited does not exist.'}
extra={
<Link to={utils.getLocalizedPathname('/', isZhCN)}>
<Button type="primary" icon={<HomeOutlined />}>
{isZhCN ? '返回 Ant Design 首页' : 'Back to home page'}
</Button>
</Link>
}
/>
);
};

13
.dumi/theme/common/CommonHelmet.tsx

@ -5,10 +5,15 @@ const CommonHelmet = () => {
const meta = useRouteMeta();
const [title, description] = useMemo(() => {
const helmetTitle = `${meta.frontmatter.subtitle || ''} ${
meta.frontmatter?.title
} - Ant Design`;
const helmetDescription = meta.frontmatter.description;
let helmetTitle;
if (!meta.frontmatter.subtitle && !meta.frontmatter.title) {
helmetTitle = '404 Not Found - Ant Design';
} else {
helmetTitle = `${meta.frontmatter.subtitle || ''} ${
meta.frontmatter?.title || ''
} - Ant Design`;
}
const helmetDescription = meta.frontmatter.description || '';
return [helmetTitle, helmetDescription];
}, [meta]);

26
.dumi/theme/slots/Content/index.tsx

@ -187,18 +187,20 @@ const Content: React.FC<{ children: ReactNode }> = ({ children }) => {
</section>
</Affix>
<article css={styles.articleWrapper} className={classNames({ rtl: isRTL })}>
<Typography.Title style={{ fontSize: 30 }}>
{meta.frontmatter?.title}
{meta.frontmatter.subtitle && (
<span style={{ marginLeft: 12 }}>{meta.frontmatter.subtitle}</span>
)}
{!pathname.startsWith('/components/overview') && (
<EditButton
title={<FormattedMessage id="app.content.edit-page" />}
filename={meta.frontmatter.filename}
/>
)}
</Typography.Title>
{meta.frontmatter?.title && meta.frontmatter.subtitle ? (
<Typography.Title style={{ fontSize: 30 }}>
{meta.frontmatter?.title}
{meta.frontmatter.subtitle && (
<span style={{ marginLeft: 12 }}>{meta.frontmatter.subtitle}</span>
)}
{!pathname.startsWith('/components/overview') && (
<EditButton
title={<FormattedMessage id="app.content.edit-page" />}
filename={meta.frontmatter.filename}
/>
)}
</Typography.Title>
) : null}
{/* 添加作者、时间等信息 */}
{meta.frontmatter.date || meta.frontmatter.author ? (
<Typography.Paragraph style={{ opacity: 0.65 }}>

Loading…
Cancel
Save