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