feat: support disable blog module
This commit is contained in:
parent
46fd529390
commit
866988d73c
@ -14,7 +14,6 @@ type Href = Parameters<typeof getLocalePathname>[0]['href'];
|
||||
const staticRoutes = [
|
||||
'/',
|
||||
'/pricing',
|
||||
'/blog',
|
||||
'/docs',
|
||||
'/about',
|
||||
'/contact',
|
||||
@ -48,88 +47,91 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
})
|
||||
);
|
||||
|
||||
// add categories
|
||||
sitemapList.push(
|
||||
...categorySource.getPages().flatMap((category) =>
|
||||
routing.locales.map((locale) => ({
|
||||
url: getUrl(`/blog/category/${category.slugs[0]}`, locale),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
}))
|
||||
)
|
||||
);
|
||||
|
||||
// add paginated blog list pages
|
||||
routing.locales.forEach((locale) => {
|
||||
const posts = blogSource
|
||||
.getPages(locale)
|
||||
.filter((post) => post.data.published);
|
||||
const totalPages = Math.max(
|
||||
1,
|
||||
Math.ceil(posts.length / websiteConfig.blog.paginationSize)
|
||||
// add blog related routes if enabled
|
||||
if (websiteConfig.blog.enable) {
|
||||
// add categories
|
||||
sitemapList.push(
|
||||
...categorySource.getPages().flatMap((category) =>
|
||||
routing.locales.map((locale) => ({
|
||||
url: getUrl(`/blog/category/${category.slugs[0]}`, locale),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
}))
|
||||
)
|
||||
);
|
||||
// /blog/page/[page] (from 2)
|
||||
for (let page = 2; page <= totalPages; page++) {
|
||||
sitemapList.push({
|
||||
url: getUrl(`/blog/page/${page}`, locale),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// add paginated category pages
|
||||
routing.locales.forEach((locale) => {
|
||||
const localeCategories = categorySource.getPages(locale);
|
||||
localeCategories.forEach((category) => {
|
||||
// posts in this category and locale
|
||||
const postsInCategory = blogSource
|
||||
// add paginated blog list pages
|
||||
routing.locales.forEach((locale) => {
|
||||
const posts = blogSource
|
||||
.getPages(locale)
|
||||
.filter((post) => post.data.published)
|
||||
.filter((post) =>
|
||||
post.data.categories.some((cat) => cat === category.slugs[0])
|
||||
);
|
||||
.filter((post) => post.data.published);
|
||||
const totalPages = Math.max(
|
||||
1,
|
||||
Math.ceil(postsInCategory.length / websiteConfig.blog.paginationSize)
|
||||
Math.ceil(posts.length / websiteConfig.blog.paginationSize)
|
||||
);
|
||||
// /blog/category/[slug] (first page)
|
||||
sitemapList.push({
|
||||
url: getUrl(`/blog/category/${category.slugs[0]}`, locale),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
});
|
||||
// /blog/category/[slug]/page/[page] (from 2)
|
||||
// /blog/page/[page] (from 2)
|
||||
for (let page = 2; page <= totalPages; page++) {
|
||||
sitemapList.push({
|
||||
url: getUrl(
|
||||
`/blog/category/${category.slugs[0]}/page/${page}`,
|
||||
locale
|
||||
),
|
||||
url: getUrl(`/blog/page/${page}`, locale),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// add posts (single post pages)
|
||||
sitemapList.push(
|
||||
...blogSource.getPages().flatMap((post) =>
|
||||
routing.locales
|
||||
.filter((locale) => post.locale === locale)
|
||||
.map((locale) => ({
|
||||
url: getUrl(`/blog/${post.slugs.join('/')}`, locale),
|
||||
// add paginated category pages
|
||||
routing.locales.forEach((locale) => {
|
||||
const localeCategories = categorySource.getPages(locale);
|
||||
localeCategories.forEach((category) => {
|
||||
// posts in this category and locale
|
||||
const postsInCategory = blogSource
|
||||
.getPages(locale)
|
||||
.filter((post) => post.data.published)
|
||||
.filter((post) =>
|
||||
post.data.categories.some((cat) => cat === category.slugs[0])
|
||||
);
|
||||
const totalPages = Math.max(
|
||||
1,
|
||||
Math.ceil(postsInCategory.length / websiteConfig.blog.paginationSize)
|
||||
);
|
||||
// /blog/category/[slug] (first page)
|
||||
sitemapList.push({
|
||||
url: getUrl(`/blog/category/${category.slugs[0]}`, locale),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
}))
|
||||
)
|
||||
);
|
||||
});
|
||||
// /blog/category/[slug]/page/[page] (from 2)
|
||||
for (let page = 2; page <= totalPages; page++) {
|
||||
sitemapList.push({
|
||||
url: getUrl(
|
||||
`/blog/category/${category.slugs[0]}/page/${page}`,
|
||||
locale
|
||||
),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// add posts (single post pages)
|
||||
sitemapList.push(
|
||||
...blogSource.getPages().flatMap((post) =>
|
||||
routing.locales
|
||||
.filter((locale) => post.locale === locale)
|
||||
.map((locale) => ({
|
||||
url: getUrl(`/blog/${post.slugs.join('/')}`, locale),
|
||||
lastModified: new Date(),
|
||||
priority: 0.8,
|
||||
changeFrequency: 'weekly' as const,
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// add docs
|
||||
const docsParams = source.generateParams();
|
||||
|
@ -3,6 +3,7 @@
|
||||
import { Routes } from '@/routes';
|
||||
import type { NestedMenuItem } from '@/types';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { websiteConfig } from './website';
|
||||
|
||||
/**
|
||||
* Get footer config with translations
|
||||
@ -41,11 +42,15 @@ export function getFooterLinks(): NestedMenuItem[] {
|
||||
{
|
||||
title: t('resources.title'),
|
||||
items: [
|
||||
{
|
||||
title: t('resources.items.blog'),
|
||||
href: Routes.Blog,
|
||||
external: false,
|
||||
},
|
||||
...(websiteConfig.blog.enable
|
||||
? [
|
||||
{
|
||||
title: t('resources.items.blog'),
|
||||
href: Routes.Blog,
|
||||
external: false,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: t('resources.items.docs'),
|
||||
href: Routes.Docs,
|
||||
|
@ -34,6 +34,7 @@ import {
|
||||
WandSparklesIcon,
|
||||
} from 'lucide-react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { websiteConfig } from './website';
|
||||
|
||||
/**
|
||||
* Get navbar config with translations
|
||||
@ -59,11 +60,15 @@ export function getNavbarLinks(): NestedMenuItem[] {
|
||||
href: Routes.Pricing,
|
||||
external: false,
|
||||
},
|
||||
{
|
||||
title: t('blog.title'),
|
||||
href: Routes.Blog,
|
||||
external: false,
|
||||
},
|
||||
...(websiteConfig.blog.enable
|
||||
? [
|
||||
{
|
||||
title: t('blog.title'),
|
||||
href: Routes.Blog,
|
||||
external: false,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: t('docs.title'),
|
||||
href: Routes.Docs,
|
||||
|
@ -34,12 +34,12 @@ export const websiteConfig: WebsiteConfig = {
|
||||
},
|
||||
features: {
|
||||
enableDiscordWidget: false,
|
||||
enableCrispChat: process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true',
|
||||
enableUpgradeCard: true,
|
||||
enableUpdateAvatar: true,
|
||||
enableAffonsoAffiliate: false,
|
||||
enablePromotekitAffiliate: false,
|
||||
enableDatafastRevenueTrack: false,
|
||||
enableCrispChat: process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true',
|
||||
enableTurnstileCaptcha: process.env.NEXT_PUBLIC_DEMO_WEBSITE === 'true',
|
||||
},
|
||||
routes: {
|
||||
@ -68,6 +68,7 @@ export const websiteConfig: WebsiteConfig = {
|
||||
},
|
||||
},
|
||||
blog: {
|
||||
enable: false,
|
||||
paginationSize: 6,
|
||||
relatedPostsSize: 3,
|
||||
},
|
||||
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
@ -111,6 +111,7 @@ export interface I18nConfig {
|
||||
* Blog configuration
|
||||
*/
|
||||
export interface BlogConfig {
|
||||
enable: boolean; // Whether to enable the blog
|
||||
paginationSize: number; // Number of posts per page
|
||||
relatedPostsSize: number; // Number of related posts to show
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user