Skip to content

Commit 9832b6a

Browse files
committed
[refactor] Update PageHead component to use Partial type for props; [fix] Adjust SiteUrl and DefaultImage for better configuration handling
1 parent e7ecc64 commit 9832b6a

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

components/PageHead.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@ import type { FC, PropsWithChildren } from 'react';
33

44
import { Name, SiteUrl, Summary } from '../models/configuration';
55

6-
export type PageHeadProps = PropsWithChildren<{
7-
title?: string;
8-
description?: string;
9-
image?: string;
10-
type?: string;
11-
url?: string;
12-
}>;
6+
export type PageHeadProps = PropsWithChildren<
7+
Partial<Record<'title' | 'description' | 'ogImage' | 'type' | 'url', string>>
8+
>;
139

1410
export const PageHead: FC<PageHeadProps> = ({
1511
title,
1612
description = Summary,
17-
image = 'https://github.com/idea2app.png',
13+
ogImage = 'https://github.com/idea2app.png',
1814
type = 'website',
1915
url = SiteUrl,
2016
children,
2117
}) => {
2218
const fullTitle = (title ? `${title} - ` : '') + Name;
19+
const fullUrl = url.startsWith('/') ? `${SiteUrl}${url}` : url;
2320

2421
return (
2522
<Head>
@@ -31,18 +28,18 @@ export const PageHead: FC<PageHeadProps> = ({
3128
<meta property="og:title" content={fullTitle} />
3229
<meta property="og:description" content={description} />
3330
<meta property="og:type" content={type} />
34-
<meta property="og:image" content={image} />
35-
<meta property="og:url" content={url} />
31+
<meta property="og:image" content={ogImage} />
32+
<meta property="og:url" content={fullUrl} />
3633
<meta property="og:site_name" content={Name} />
3734

3835
{/* Twitter */}
3936
<meta name="twitter:card" content="summary_large_image" />
4037
<meta name="twitter:title" content={fullTitle} />
4138
<meta name="twitter:description" content={description} />
42-
<meta name="twitter:image" content={image} />
39+
<meta name="twitter:image" content={ogImage} />
4340

4441
{/* 规范链接 */}
45-
<link rel="canonical" href={url} />
42+
<link rel="canonical" href={fullUrl} />
4643

4744
{children}
4845
</Head>

models/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const Name = process.env.NEXT_PUBLIC_SITE_NAME,
22
Summary = process.env.NEXT_PUBLIC_SITE_SUMMARY,
3-
DefaultImage = process.env.NEXT_PUBLIC_LOGO || '/og.png',
4-
SiteUrl = 'https://idea2.app';
3+
DefaultImage = process.env.NEXT_PUBLIC_LOGO || '/idea2app.svg',
4+
SiteUrl = `https://${process.env.VERCEL_URL || 'idea2.app'}`;
55

66
export const isServer = () => typeof window === 'undefined';
77

pages/_document.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import InitColorSchemeScript from '@mui/material/InitColorSchemeScript';
22
import Document, { DocumentContext, Head, Html, Main, NextScript } from 'next/document';
33
import Script from 'next/script';
44

5-
import { DefaultImage, SiteUrl } from '../models/configuration';
5+
import { DefaultImage, Name, SiteUrl } from '../models/configuration';
66
import { LanguageCode, parseSSRContext } from '../models/Translation';
77

88
/**
@@ -12,14 +12,14 @@ import { LanguageCode, parseSSRContext } from '../models/Translation';
1212
const siteNameJsonLd = {
1313
'@context': 'https://schema.org',
1414
'@type': 'WebSite',
15-
name: 'idea2app',
15+
name: Name,
1616
url: SiteUrl,
1717
};
1818

1919
const organizationJsonLd = {
2020
'@context': 'https://schema.org',
2121
'@type': 'Organization',
22-
name: 'idea2app',
22+
name: Name,
2323
url: SiteUrl,
2424
logo: DefaultImage,
2525
sameAs: ['https://github.com/idea2app'],

0 commit comments

Comments
 (0)