HaoAws/lib/seo.ts

359 lines
14 KiB
TypeScript
Raw Normal View History

2025-09-16 16:37:48 +08:00
import { Locale, getTranslations } from './i18n';
export interface SEOData {
title: string;
description: string;
keywords: string[];
}
export interface PageSEO {
[key: string]: SEOData;
}
// 保留原有的静态配置作为后备方案
export const seoConfig: Record<Locale, PageSEO> = {
'zh-CN': {
about: {
title: '关于我们 - HaoAWS企业云计算与数字化转型专家',
description:
'HaoAWS是一家专注于AWS云服务与企业数字化转型的科技公司。拥有150+AWS专业团队服务800+成功项目,致力于通过专业的云计算解决方案帮助企业实现数字化转型。',
keywords: [
'AWS云服务',
'企业数字化',
'云计算咨询',
'云架构设计',
'HaoAWS公司',
'数字化专家',
'云技术服务',
'企业转型',
],
},
products: {
title: '产品与服务 - 全方位AWS云计算解决方案',
description:
'提供AWS云架构设计、数据分析平台、云迁移服务、网络安全解决方案等全方位云技术服务。专业团队为您量身定制云计算转型方案。',
keywords: [
'AWS云架构',
'数据分析平台',
'云迁移服务',
'云计算解决方案',
'网络安全',
'系统集成',
'云技术咨询',
],
},
news: {
title: '新闻资讯 - 云计算行业动态与技术趋势',
description:
'获取最新的云计算行业动态、数字化转型趋势、AWS技术发展、云计算资讯等。了解HaoAWS公司最新动态和技术洞察。',
keywords: [
'云计算新闻',
'数字化趋势',
'AWS技术',
'云计算资讯',
'行业动态',
'技术洞察',
'HaoAWS',
],
},
support: {
title: '客户支持 - 专业技术支持服务',
description:
'提供7x24小时专业技术支持服务包括在线咨询、技术文档、培训服务等。我们的专家团队随时为您解决技术问题。',
keywords: [
'技术支持',
'客户服务',
'在线咨询',
'技术培训',
'问题解决',
'专家团队',
'售后服务',
],
},
},
'zh-TW': {
about: {
title: '關於我們 - HaoAWS企業雲端運算與數位化轉型專家',
description:
'HaoAWS是一家專注於AWS雲端服務與企業數位化轉型的科技公司。擁有150+AWS專業團隊服務800+成功專案,致力於透過專業的雲端運算解決方案幫助企業實現數位化轉型。',
keywords: [
'AWS雲端服務',
'企業數位化',
'雲端運算諮詢',
'雲端架構設計',
'HaoAWS公司',
'數位化專家',
'雲端技術服務',
'企業轉型',
],
},
products: {
title: '產品與服務 - 全方位AWS雲端運算解決方案',
description:
'提供AWS雲端架構設計、數據分析平台、雲端遷移服務、網路安全解決方案等全方位雲端技術服務。專業團隊為您量身定制雲端運算轉型方案。',
keywords: [
'AWS雲端架構',
'數據分析平台',
'雲端遷移服務',
'雲端運算解決方案',
'網路安全',
'系統整合',
'雲端技術諮詢',
],
},
news: {
title: '新聞資訊 - 雲端運算行業動態與技術趨勢',
description:
'獲取最新的雲端運算行業動態、數位化轉型趨勢、AWS技術發展、雲端運算資訊等。了解HaoAWS公司最新動態和技術洞察。',
keywords: [
'雲端運算新聞',
'數位化趨勢',
'AWS技術',
'雲端運算資訊',
'行業動態',
'技術洞察',
'HaoAWS',
],
},
support: {
title: '客戶支援 - 專業技術支援服務',
description:
'提供7x24小時專業技術支援服務包括線上諮詢、技術文件、培訓服務等。我們的專家團隊隨時為您解決技術問題。',
keywords: [
'技術支援',
'客戶服務',
'線上諮詢',
'技術培訓',
'問題解決',
'專家團隊',
'售後服務',
],
},
},
en: {
about: {
title: 'About Us - HaoAWS Enterprise Cloud Computing & Digital Transformation Experts',
description:
'HaoAWS is a technology company focused on AWS cloud services and enterprise digital transformation. With 150+ AWS professional team members and 800+ successful projects, we help enterprises achieve digital transformation through professional cloud computing solutions.',
keywords: [
'AWS cloud services',
'enterprise digitalization',
'cloud computing consulting',
'cloud architecture design',
'HaoAWS company',
'digital experts',
'cloud tech services',
'business transformation',
],
},
products: {
title: 'Products & Services - Comprehensive AWS Cloud Computing Solutions',
description:
'Offering AWS cloud architecture design, data analytics platforms, cloud migration services, cybersecurity solutions and comprehensive cloud technical services. Professional team provides customized cloud computing transformation solutions.',
keywords: [
'AWS cloud architecture',
'data analytics platform',
'cloud migration',
'cloud computing solutions',
'cybersecurity',
'system integration',
'cloud technology consulting',
],
},
news: {
title: 'News & Updates - Cloud Computing Industry Trends & Technology Insights',
description:
'Get the latest cloud computing industry news, digital transformation trends, AWS technology developments, cloud computing insights. Stay updated with HaoAWS company news and technical insights.',
keywords: [
'cloud computing news',
'digital trends',
'AWS technology',
'cloud computing',
'industry insights',
'technology updates',
'HaoAWS',
],
},
support: {
title: 'Customer Support - Professional Technical Support Services',
description:
'Providing 24/7 professional technical support services including online consultation, technical documentation, training services. Our expert team is ready to solve your technical challenges.',
keywords: [
'technical support',
'customer service',
'online consultation',
'technical training',
'problem solving',
'expert team',
'after-sales service',
],
},
},
};
// 从locale文件获取SEO数据的新函数
export async function getSEODataFromLocale(locale: Locale, page: string): Promise<SEOData | null> {
try {
const translations = await getTranslations(locale, page);
if (translations?.seo) {
return {
title: translations.seo.title,
description: translations.seo.description,
keywords: translations.seo.keywords || [],
};
}
return null;
} catch (error) {
console.warn(`Failed to load SEO data from locale file for ${locale}/${page}:`, error);
return null;
}
}
export async function getSEOData(locale: Locale, page: string): Promise<SEOData> {
// 首先尝试从locale文件获取SEO数据
const localeData = await getSEODataFromLocale(locale, page);
if (localeData) {
return localeData;
}
// 如果locale文件中没有SEO数据则使用静态配置
return (
seoConfig[locale]?.[page] ||
seoConfig[locale]?.home ||
seoConfig['zh-CN'].home || {
title: '创新科技',
description: '专注企业数字化转型的科技公司',
keywords: ['数字化转型', '企业软件开发', 'AI解决方案'],
}
);
}
export async function generateMetadata(locale: Locale, page: string) {
const seoData = await getSEOData(locale, page);
const baseUrl = 'https://haoaws.com';
const currentUrl = `${baseUrl}${locale === 'zh-CN' ? '' : `/${locale}`}${page === 'home' ? '' : `/${page}`}`;
const companyNames = {
'zh-CN': '创新科技',
'zh-TW': '創新科技',
en: 'Innovation Tech',
};
return {
title: seoData.title,
description: seoData.description,
keywords: seoData.keywords.join(', '),
authors: [{ name: companyNames[locale], url: baseUrl }],
creator: companyNames[locale],
publisher: companyNames[locale],
formatDetection: {
email: false,
address: false,
telephone: false,
},
metadataBase: new URL(baseUrl),
openGraph: {
title: seoData.title,
description: seoData.description,
url: currentUrl,
siteName: companyNames[locale],
type: 'website',
locale: locale === 'zh-CN' ? 'zh_CN' : locale === 'zh-TW' ? 'zh_TW' : 'en_US',
images: [
{
url: '/og-image-home.jpg',
width: 1200,
height: 630,
alt: seoData.title,
type: 'image/jpeg',
},
{
url: '/og-image-square.jpg',
width: 800,
height: 800,
alt: seoData.title,
type: 'image/jpeg',
},
],
},
twitter: {
card: 'summary_large_image',
title: seoData.title,
description: seoData.description,
images: ['/twitter-image.jpg'],
creator: '@innovation_tech',
site: '@innovation_tech',
},
alternates: {
canonical: currentUrl,
languages: {
'zh-CN': `${baseUrl}${page === 'home' ? '' : `/${page}`}`,
'zh-TW': `${baseUrl}/zh-TW${page === 'home' ? '' : `/${page}`}`,
en: `${baseUrl}/en${page === 'home' ? '' : `/${page}`}`,
'x-default': `${baseUrl}${page === 'home' ? '' : `/${page}`}`,
},
},
robots: {
index: true,
follow: true,
nocache: false,
googleBot: {
index: true,
follow: true,
noimageindex: false,
'max-video-preview': -1,
'max-image-preview': 'large',
'max-snippet': -1,
},
},
verification: {
google: 'your-google-site-verification',
yandex: 'your-yandex-verification',
yahoo: 'your-yahoo-verification',
other: {
'baidu-site-verification': 'your-baidu-verification',
sogou_site_verification: 'your-sogou-verification',
},
},
category: page === 'home' ? 'technology' : page,
classification: 'Business',
referrer: 'origin-when-cross-origin',
colorScheme: 'light',
themeColor: [
{ media: '(prefers-color-scheme: light)', color: '#ffffff' },
{ media: '(prefers-color-scheme: dark)', color: '#000000' },
],
viewport: {
width: 'device-width',
initialScale: 1,
maximumScale: 5,
},
manifest: '/site.webmanifest',
icons: {
icon: [
{ url: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' },
{ url: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
],
apple: [{ url: '/apple-touch-icon.png', sizes: '180x180', type: 'image/png' }],
other: [
{
rel: 'mask-icon',
url: '/safari-pinned-tab.svg',
color: '#000000',
},
],
},
appleWebApp: {
capable: true,
title: companyNames[locale],
statusBarStyle: 'default',
},
applicationName: companyNames[locale],
generator: 'Next.js',
abstract: seoData.description,
archives: [`${baseUrl}/news`],
assets: [`${baseUrl}/assets`],
bookmarks: [`${baseUrl}/products`],
};
}