24 lines
1.2 KiB
TypeScript
24 lines
1.2 KiB
TypeScript
import type { Config } from './api/types';
|
|
import { NAVIGATION_SITE_NAME, OFFICIAL_TG_HANDLE, OFFICIAL_TG_URL, SITE_URL } from './site';
|
|
|
|
const object=(value:unknown):Record<string,unknown>=>{
|
|
if(typeof value==='string'){try{return object(JSON.parse(value));}catch{return {};}}
|
|
return value&&typeof value==='object'&&!Array.isArray(value)?value as Record<string,unknown>:{};
|
|
};
|
|
const text=(value:unknown)=>typeof value==='string'?value.replace(/<[^>]*>/g,'').replace(/[\u0000-\u001f\u007f]/g,' ').replace(/\s+/g,' ').trim():'';
|
|
const firstText=(...values:unknown[])=>values.map(text).find(Boolean)||'';
|
|
|
|
/** The entry, permanent address and contact channel are fixed; only the description comes from configuration. */
|
|
export function navigationPageData(config:Config) {
|
|
const settings=object(config.config);
|
|
const navigationSeo=object(config.seoNavInfo);
|
|
const siteName=NAVIGATION_SITE_NAME;
|
|
const routes=[{line:1,href:SITE_URL,label:'线路一'}];
|
|
return {
|
|
siteName,
|
|
description:firstText(navigationSeo.dhDescription,navigationSeo.description,settings.dhDescription)||'全网最新最火短剧,黄果吃瓜为你呈现',
|
|
routes,permanent:SITE_URL,
|
|
telegram:OFFICIAL_TG_URL,telegramHandle:OFFICIAL_TG_HANDLE,
|
|
};
|
|
}
|