Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 49 additions & 24 deletions app/[lang]/(home)/blog/category/[category]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateBlogMetadata } from '@/lib/utils/metadata';
import { generatePageMetadata } from '@/lib/utils/metadata';
import { redirect } from 'next/navigation';
import {
getCategories,
Expand All @@ -13,11 +13,55 @@ import BlogGrid from '../../components/BlogGrid';
import CategoryBar from '../../components/CategoryBar';
import TagsBar from '../../components/TagBar';
import { GodRays } from '@/new-components/GodRays';
import type { Metadata } from 'next';

type CategoryPageParams = { category: string; lang: languagesType };

const categoryMetadataCopy: Record<
languagesType,
Record<'title' | 'description', string>
> = {
en: {
title: 'Blog Category',
description: 'Browse Sealos blog articles by category.',
},
'zh-cn': {
title: '博客分类',
description: '按分类浏览 Sealos 博客文章。',
},
};

export async function generateMetadata({
params,
}: {
params: CategoryPageParams;
}): Promise<Metadata> {
const categories = await getCategories();
const decodedCategory = decodeURIComponent(params.category);
const copy = categoryMetadataCopy[params.lang];

if (!categories.includes(decodedCategory)) {
return generatePageMetadata({
...copy,
pathname: '/blog',
lang: params.lang,
});
}

const categoryTitle = formatCategoryTitle(decodedCategory);

return generatePageMetadata({
title: `${categoryTitle} - ${copy.title}`,
description: copy.description,
pathname: `/blog/category/${encodeURIComponent(decodedCategory)}`,
lang: params.lang,
});
}

export default async function CategoryPage({
params,
}: {
params: { category: string; lang: languagesType };
params: CategoryPageParams;
}) {
const categories = await getCategories();
const { category, lang } = params;
Expand All @@ -28,29 +72,12 @@ export default async function CategoryPage({
}

const allPosts = getSortedBlogPosts({
category: category,
category,
tags: [],
lang: lang,
lang,
});
const posts = allPosts;
const tags = await getAllTags(allPosts);

const categoryTitle = formatCategoryTitle(category);

const translations: Record<
languagesType,
Record<'title' | 'description', string>
> = {
en: {
title: `${categoryTitle} Articles`,
description: `Blog articles in the ${categoryTitle.toLowerCase()} category`,
},
'zh-cn': {
title: `${categoryTitle}`,
description: `${categoryTitle.toLowerCase()}分类下的博客`,
},
};

return (
<>
<GodRays
Expand Down Expand Up @@ -109,7 +136,7 @@ export default async function CategoryPage({
</section>

<section className="container mt-10">
<BlogGrid posts={posts.map(toBlogPostSummary)} lang={lang} />
<BlogGrid posts={allPosts.map(toBlogPostSummary)} lang={lang} />
</section>
</>
);
Expand Down Expand Up @@ -149,5 +176,3 @@ export async function generateStaticParams(): Promise<
return [];
}
}

export const generateMetadata = generateBlogMetadata;
10 changes: 10 additions & 0 deletions app/[lang]/(home)/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ import TagsBar from './components/TagBar';
import { languagesType } from '@/lib/i18n';
import BlogGridWithTagFilter from './components/BlogGridWithTagFilter';
import { BlogHeader } from './components/BlogHeader';
import { generatePageMetadata } from '@/lib/utils/metadata';
import type { Metadata } from 'next';

type BlogIndexProps = {
params: { lang: languagesType };
};

export function generateMetadata(): Metadata {
return generatePageMetadata({
title: 'Blog',
description: 'Explore Sealos blog posts and technical insights.',
pathname: '/blog',
});
}

/** Blog index: tag filtering is done on the client for static export. */
export default async function BlogPage({ params: { lang } }: BlogIndexProps) {
const categories = await getCategories();
Expand Down
11 changes: 11 additions & 0 deletions app/[lang]/(home)/pricing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ import { MorePlans } from './components/MorePlans';
import { FeaturesSection } from './components/FeaturesSection';
import { FAQSection } from './components/FAQSection';
import { mainPricingPlans } from './config/plans';
import { generatePageMetadata } from '@/lib/utils/metadata';
import Image from 'next/image';
import HeroLinesImage from './assets/hero-lines.svg';
import type { Metadata } from 'next';

interface PageProps {
params: Promise<{
lang: string;
}>;
}

export function generateMetadata(): Metadata {
return generatePageMetadata({
title: 'Pricing',
description:
'Explore Sealos pricing plans with 7-day free trial and no credit card required.',
pathname: '/pricing',
});
}

export default async function PricingPage({ params }: PageProps) {
const { lang } = await params;
const langPrefix = `/${lang}`;
Expand Down
7 changes: 2 additions & 5 deletions app/api/robots/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import { i18n } from '@/lib/i18n';
import { NextResponse } from 'next/server';

export async function GET() {
export function GET() {
const host =
i18n.defaultLanguage === 'en' ? 'https://sealos.io' : 'https://sealos.run';
const enHost = 'https://sealos.io';
const zhHost = 'https://sealos.run';

const robotsTxt = `User-agent: *
Allow: /
Expand All @@ -16,8 +14,7 @@ Disallow: /en/
Host: ${host}

Sitemap: ${host}/sitemap.xml
Sitemap: ${enHost}/en/ai-quick-reference/sitemap.xml
Sitemap: ${zhHost}/zh-cn/ai-quick-reference/sitemap.xml`;
Sitemap: ${host}/ai-quick-reference/sitemap.xml`;

return new NextResponse(robotsTxt, {
headers: {
Expand Down
4 changes: 2 additions & 2 deletions app/sitemap-index.xml/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const revalidate = false;
/**
* Sitemap index: references main sitemap and ai-faq sitemap.
* Main sitemap is at /sitemap.xml (contains all main site URLs)
* AI FAQ sitemap is at /sitemap-ai-faq.xml (contains all AI quick reference pages)
* AI FAQ sitemap is at /ai-quick-reference/sitemap.xml (contains all AI quick reference pages)
*/
export function GET() {
const baseUrl =
Expand All @@ -18,7 +18,7 @@ export function GET() {
<loc>${baseUrl}/sitemap.xml</loc>
</sitemap>
<sitemap>
<loc>${baseUrl}/sitemap-ai-faq.xml</loc>
<loc>${baseUrl}/ai-quick-reference/sitemap.xml</loc>
</sitemap>
</sitemapindex>`;

Expand Down
102 changes: 52 additions & 50 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,83 @@ import { getAllPlatformSlugs } from '@/app/[lang]/(home)/comparison/config/platf

export const revalidate = false;

const escapeXmlChars = (url: string): string =>
url
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
const normalizePathname = (pathname: string): string =>
pathname === '/' ? '/' : `${pathname.replace(/\/+$/, '')}/`;

const toSitemapItem = (
getUrl: (path: string) => string,
path: string,
changeFrequency: NonNullable<MetadataRoute.Sitemap[number]['changeFrequency']>,
priority: number,
): MetadataRoute.Sitemap[number] => ({
url: getUrl(path),
changeFrequency,
priority,
});

/**
* Main sitemap: contains all main site URLs directly.
* AI FAQ pages are in a separate sitemap at /sitemap-ai-faq.xml
* AI FAQ pages are in a separate sitemap at /ai-quick-reference/sitemap.xml
*/
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const locale = process.env.NEXT_PUBLIC_DEFAULT_LOCALE;
const defaultDomain = locale?.includes('zh-cn') ? 'https://sealos.run' : 'https://sealos.io';
const getUrl = (path: string) => new URL(path, defaultDomain).toString();
const isZhCn = locale?.includes('zh-cn');
const defaultDomain = isZhCn ? 'https://sealos.run' : 'https://sealos.io';
const getUrl = (path: string) => {
const url = new URL(path, defaultDomain);
url.pathname = normalizePathname(url.pathname);
return url.toString();
};

const docPages = await Promise.all(
source.getPages().map(async (page) => ({
url: escapeXmlChars(getUrl(page.url)),
changeFrequency: 'weekly' as const,
priority: 0.5,
})),
);
const docPages: MetadataRoute.Sitemap = source
.getPages()
.map((page) => toSitemapItem(getUrl, page.url, 'weekly', 0.5));

const blogPages = await Promise.all(
blog.getPages().map(async (post) => ({
url: escapeXmlChars(getUrl(post.url)),
changeFrequency: 'weekly' as const,
priority: 0.6,
})),
);
const blogPages: MetadataRoute.Sitemap = blog
.getPages()
.map((post) => toSitemapItem(getUrl, post.url, 'weekly', 0.6));

const staticProductPages: MetadataRoute.Sitemap = [
{ url: escapeXmlChars(getUrl('/products/devbox')), changeFrequency: 'monthly', priority: 0.8 },
{ url: escapeXmlChars(getUrl('/products/databases')), changeFrequency: 'monthly', priority: 0.8 },
{ url: escapeXmlChars(getUrl('/products/app-store')), changeFrequency: 'monthly', priority: 0.8 },
];
'/products/devbox',
'/products/databases',
'/products/app-store',
].map((path) => toSitemapItem(getUrl, path, 'monthly', 0.8));

const appStorePages: MetadataRoute.Sitemap = appsConfig.map((app) => ({
url: escapeXmlChars(getUrl(`/products/app-store/${app.slug}`)),
changeFrequency: 'weekly',
priority: 0.7,
}));
const appStorePages: MetadataRoute.Sitemap = appsConfig.map((app) =>
toSitemapItem(getUrl, `/products/app-store/${app.slug}`, 'weekly', 0.7),
);

const allPlatformSlugs = getAllPlatformSlugs();
const comparisonPages: MetadataRoute.Sitemap = [];
for (let i = 0; i < allPlatformSlugs.length; i++) {
for (let j = i + 1; j < allPlatformSlugs.length; j++) {
comparisonPages.push({
url: escapeXmlChars(getUrl(`/comparison/${allPlatformSlugs[i]}-vs-${allPlatformSlugs[j]}`)),
changeFrequency: 'weekly',
priority: 0.8,
});
comparisonPages.push(
toSitemapItem(
getUrl,
`/comparison/${allPlatformSlugs[i]}-vs-${allPlatformSlugs[j]}`,
'weekly',
0.8,
),
);
}
}

const chineseSpecificPages: MetadataRoute.Sitemap =
locale?.includes('zh-cn') ?
[
{ url: 'https://sealos.run/case/', changeFrequency: 'monthly', priority: 0.8 },
{ url: 'https://sealos.run/price', changeFrequency: 'monthly', priority: 0.8 },
{ url: 'https://sealos.run/aiproxy', changeFrequency: 'monthly', priority: 0.8 },
]
: [];
isZhCn
? ['/case', '/price', '/aiproxy'].map((path) =>
toSitemapItem(getUrl, path, 'monthly', 0.8),
)
: [];

return [
{ url: getUrl('/'), changeFrequency: 'monthly', priority: 1 },
toSitemapItem(getUrl, '/', 'monthly', 1),
...staticProductPages,
...appStorePages,
...chineseSpecificPages,
{ url: getUrl('/docs'), changeFrequency: 'monthly', priority: 0.8 },
{ url: getUrl('/blog'), changeFrequency: 'monthly', priority: 0.8 },
{ url: getUrl('/ai-quick-reference'), changeFrequency: 'monthly', priority: 0.8 },
{ url: getUrl('/comparison'), changeFrequency: 'weekly', priority: 0.8 },
toSitemapItem(getUrl, '/docs', 'monthly', 0.8),
toSitemapItem(getUrl, '/blog', 'monthly', 0.8),
toSitemapItem(getUrl, '/ai-quick-reference', 'monthly', 0.8),
toSitemapItem(getUrl, '/comparison', 'weekly', 0.8),
...comparisonPages,
...docPages,
...blogPages,
Expand Down
Loading