@@ -24,35 +24,43 @@ export const DEFAULT_KEYWORDS = [
2424] ;
2525export const DEFAULT_OG_IMAGE = "/images/overview-full.png" ;
2626
27+ function normalizeSiteUrl ( siteUrl : string = SITE_URL ) {
28+ return new URL ( "/" , siteUrl ) . toString ( ) . replace ( / \/ $ / , "" ) ;
29+ }
30+
2731export function toAbsoluteUrl ( path : string , base : string = SITE_URL ) {
28- return new URL ( path , base ) . toString ( ) ;
32+ return new URL ( path , normalizeSiteUrl ( base ) ) . toString ( ) ;
2933}
3034
31- export function createOrganizationSchema ( ) : StructuredData {
35+ export function createOrganizationSchema ( siteUrl : string = SITE_URL ) : StructuredData {
36+ const resolvedSiteUrl = normalizeSiteUrl ( siteUrl ) ;
37+
3238 return {
3339 "@context" : "https://schema.org" ,
3440 "@type" : "Organization" ,
35- "@id" : `${ SITE_URL } /#organization` ,
41+ "@id" : `${ resolvedSiteUrl } /#organization` ,
3642 name : ORGANIZATION_NAME ,
3743 alternateName : ORGANIZATION_ALTERNATE_NAME ,
3844 url : ORGANIZATION_URL ,
39- logo : toAbsoluteUrl ( "/images/logo-light-FIT2CLOUD.svg" ) ,
45+ logo : toAbsoluteUrl ( "/images/logo-light-FIT2CLOUD.svg" , resolvedSiteUrl ) ,
4046 sameAs : [ ORGANIZATION_URL ] ,
4147 } ;
4248}
4349
44- export function createWebsiteSchema ( ) : StructuredData {
50+ export function createWebsiteSchema ( siteUrl : string = SITE_URL ) : StructuredData {
51+ const resolvedSiteUrl = normalizeSiteUrl ( siteUrl ) ;
52+
4553 return {
4654 "@context" : "https://schema.org" ,
4755 "@type" : "WebSite" ,
48- "@id" : `${ SITE_URL } /#website` ,
56+ "@id" : `${ resolvedSiteUrl } /#website` ,
4957 name : `${ SITE_NAME } 官网` ,
5058 alternateName : SITE_NAME ,
51- url : `${ SITE_URL } /` ,
59+ url : `${ resolvedSiteUrl } /` ,
5260 inLanguage : "zh-CN" ,
5361 description : DEFAULT_DESCRIPTION ,
5462 publisher : {
55- "@id" : `${ SITE_URL } /#organization` ,
63+ "@id" : `${ resolvedSiteUrl } /#organization` ,
5664 } ,
5765 } ;
5866}
@@ -61,11 +69,15 @@ export function createWebPageSchema({
6169 title,
6270 description,
6371 url,
72+ siteUrl = SITE_URL ,
6473} : {
6574 title : string ;
6675 description : string ;
6776 url : string ;
77+ siteUrl ?: string ;
6878} ) : StructuredData {
79+ const resolvedSiteUrl = normalizeSiteUrl ( siteUrl ) ;
80+
6981 return {
7082 "@context" : "https://schema.org" ,
7183 "@type" : "WebPage" ,
@@ -75,40 +87,42 @@ export function createWebPageSchema({
7587 description,
7688 inLanguage : "zh-CN" ,
7789 isPartOf : {
78- "@id" : `${ SITE_URL } /#website` ,
90+ "@id" : `${ resolvedSiteUrl } /#website` ,
7991 } ,
8092 about : {
8193 "@type" : "Thing" ,
8294 name : SITE_NAME ,
8395 } ,
8496 publisher : {
85- "@id" : `${ SITE_URL } /#organization` ,
97+ "@id" : `${ resolvedSiteUrl } /#organization` ,
8698 } ,
8799 } ;
88100}
89101
90- export function createSoftwareApplicationSchema ( ) : StructuredData {
102+ export function createSoftwareApplicationSchema ( siteUrl : string = SITE_URL ) : StructuredData {
103+ const resolvedSiteUrl = normalizeSiteUrl ( siteUrl ) ;
104+
91105 return {
92106 "@context" : "https://schema.org" ,
93107 "@type" : "SoftwareApplication" ,
94- "@id" : `${ SITE_URL } /#software` ,
108+ "@id" : `${ resolvedSiteUrl } /#software` ,
95109 name : SITE_NAME ,
96- url : `${ SITE_URL } /` ,
110+ url : `${ resolvedSiteUrl } /` ,
97111 description : DEFAULT_DESCRIPTION ,
98112 applicationCategory : "DeveloperApplication" ,
99113 operatingSystem : "Linux" ,
100- image : toAbsoluteUrl ( DEFAULT_OG_IMAGE ) ,
101- screenshot : toAbsoluteUrl ( "/images/dashboard-preview.png" ) ,
114+ image : toAbsoluteUrl ( DEFAULT_OG_IMAGE , resolvedSiteUrl ) ,
115+ screenshot : toAbsoluteUrl ( "/images/dashboard-preview.png" , resolvedSiteUrl ) ,
102116 downloadUrl : GITHUB_URL ,
103- softwareHelp : toAbsoluteUrl ( "/docs" ) ,
117+ softwareHelp : toAbsoluteUrl ( "/docs" , resolvedSiteUrl ) ,
104118 isAccessibleForFree : true ,
105119 offers : {
106120 "@type" : "Offer" ,
107121 price : "0" ,
108122 priceCurrency : "CNY" ,
109123 } ,
110124 publisher : {
111- "@id" : `${ SITE_URL } /#organization` ,
125+ "@id" : `${ resolvedSiteUrl } /#organization` ,
112126 } ,
113127 sameAs : [ GITHUB_URL ] ,
114128 featureList : [
0 commit comments