@@ -3,23 +3,20 @@ import type { FC, PropsWithChildren } from 'react';
3
3
4
4
import { Name , SiteUrl , Summary } from '../models/configuration' ;
5
5
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
+ > ;
13
9
14
10
export const PageHead : FC < PageHeadProps > = ( {
15
11
title,
16
12
description = Summary ,
17
- image = 'https://github.com/idea2app.png' ,
13
+ ogImage = 'https://github.com/idea2app.png' ,
18
14
type = 'website' ,
19
15
url = SiteUrl ,
20
16
children,
21
17
} ) => {
22
18
const fullTitle = ( title ? `${ title } - ` : '' ) + Name ;
19
+ const fullUrl = url . startsWith ( '/' ) ? `${ SiteUrl } ${ url } ` : url ;
23
20
24
21
return (
25
22
< Head >
@@ -31,18 +28,18 @@ export const PageHead: FC<PageHeadProps> = ({
31
28
< meta property = "og:title" content = { fullTitle } />
32
29
< meta property = "og:description" content = { description } />
33
30
< 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 } />
36
33
< meta property = "og:site_name" content = { Name } />
37
34
38
35
{ /* Twitter */ }
39
36
< meta name = "twitter:card" content = "summary_large_image" />
40
37
< meta name = "twitter:title" content = { fullTitle } />
41
38
< meta name = "twitter:description" content = { description } />
42
- < meta name = "twitter:image" content = { image } />
39
+ < meta name = "twitter:image" content = { ogImage } />
43
40
44
41
{ /* 规范链接 */ }
45
- < link rel = "canonical" href = { url } />
42
+ < link rel = "canonical" href = { fullUrl } />
46
43
47
44
{ children }
48
45
</ Head >
0 commit comments