Skip to content

Commit afa1675

Browse files
committed
[add] Enhance PageHead component with Open Graph and Twitter meta tags; [add] robots.txt and sitemap.xml for SEO optimization
1 parent 9d4b58a commit afa1675

File tree

4 files changed

+89
-12
lines changed

4 files changed

+89
-12
lines changed

components/PageHead.tsx

+40-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,49 @@ import type { FC, PropsWithChildren } from 'react';
44
export type PageHeadProps = PropsWithChildren<{
55
title?: string;
66
description?: string;
7+
image?: string;
8+
type?: string;
9+
url?: string;
710
}>;
811

912
const Name = process.env.NEXT_PUBLIC_SITE_NAME,
10-
Summary = process.env.NEXT_PUBLIC_SITE_SUMMARY;
13+
Summary = process.env.NEXT_PUBLIC_SITE_SUMMARY,
14+
SiteUrl = 'https://idea2.app';
1115

12-
export const PageHead: FC<PageHeadProps> = ({ title, description = Summary, children }) => (
13-
<Head>
14-
<title>{(title ? `${title} - ` : '') + Name}</title>
16+
export const PageHead: FC<PageHeadProps> = ({
17+
title,
18+
description = Summary,
19+
image = 'https://github.com/idea2app.png',
20+
type = 'website',
21+
url = SiteUrl,
22+
children,
23+
}) => {
24+
const fullTitle = (title ? `${title} - ` : '') + Name;
1525

16-
{description && <meta name="description" content={description} />}
26+
return (
27+
<Head>
28+
{/* 基础 meta 标签 */}
29+
<title>{fullTitle}</title>
30+
<meta name="description" content={description} />
1731

18-
{children}
19-
</Head>
20-
);
32+
{/* Open Graph */}
33+
<meta property="og:title" content={fullTitle} />
34+
<meta property="og:description" content={description} />
35+
<meta property="og:type" content={type} />
36+
<meta property="og:image" content={image} />
37+
<meta property="og:url" content={url} />
38+
<meta property="og:site_name" content={Name} />
39+
40+
{/* Twitter */}
41+
<meta name="twitter:card" content="summary_large_image" />
42+
<meta name="twitter:title" content={fullTitle} />
43+
<meta name="twitter:description" content={description} />
44+
<meta name="twitter:image" content={image} />
45+
46+
{/* 规范链接 */}
47+
<link rel="canonical" href={url} />
48+
49+
{children}
50+
</Head>
51+
);
52+
};

pages/_document.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,23 @@ import { DefaultImage } from './api/Lark/file/[id]';
1111
const siteNameJsonLd = {
1212
'@context': 'https://schema.org',
1313
'@type': 'WebSite',
14-
name: 'Ameliorate',
14+
name: 'idea2app',
1515
url: 'https://idea2.app/',
16+
description: 'Industry-wide IT transformation expert',
17+
potentialAction: {
18+
'@type': 'SearchAction',
19+
target: 'https://idea2.app/search?q={search_term_string}',
20+
'query-input': 'required name=search_term_string',
21+
},
22+
};
23+
24+
const organizationJsonLd = {
25+
'@context': 'https://schema.org',
26+
'@type': 'Organization',
27+
name: 'idea2app',
28+
url: 'https://idea2.app',
29+
logo: 'https://github.com/idea2app.png',
30+
sameAs: ['https://github.com/idea2app'],
1631
};
1732

1833
export default function Document() {
@@ -21,9 +36,6 @@ export default function Document() {
2136
<Head>
2237
<link rel="icon" href={DefaultImage} />
2338
<link rel="manifest" href="/manifest.json" />
24-
<meta property="og:type" content="website" />
25-
<meta property="og:site_name" content="idea2app" />
26-
<meta property="og:url" content={siteNameJsonLd.url} />
2739

2840
<Script src="https://polyfill.web-cell.dev/feature/PWAManifest.js" />
2941
<link rel="preconnect" href="https://fonts.googleapis.com" />
@@ -43,6 +55,7 @@ export default function Document() {
4355
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=code,dark_mode,diversity_3,keyboard_arrow_down,language,light_mode,menu,translate,trending_up&display=swap"
4456
/>
4557
<script type="application/ld+json">{JSON.stringify(siteNameJsonLd)}</script>
58+
<script type="application/ld+json">{JSON.stringify(organizationJsonLd)}</script>
4659
</Head>
4760

4861
<body>

public/robots.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
User-agent: *
2+
Allow: /
3+
4+
Sitemap: https://idea2.app/sitemap.xml

public/sitemap.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3+
<url>
4+
<loc>https://idea2.app/</loc>
5+
<changefreq>daily</changefreq>
6+
<priority>1.0</priority>
7+
</url>
8+
<url>
9+
<loc>https://idea2.app/project</loc>
10+
<changefreq>weekly</changefreq>
11+
<priority>0.8</priority>
12+
</url>
13+
<url>
14+
<loc>https://idea2.app/requirement</loc>
15+
<changefreq>weekly</changefreq>
16+
<priority>0.8</priority>
17+
</url>
18+
<url>
19+
<loc>https://idea2.app/member</loc>
20+
<changefreq>weekly</changefreq>
21+
<priority>0.7</priority>
22+
</url>
23+
<url>
24+
<loc>https://idea2.app/open-source</loc>
25+
<changefreq>weekly</changefreq>
26+
<priority>0.7</priority>
27+
</url>
28+
</urlset>

0 commit comments

Comments
 (0)