force-static

This commit is contained in:
Francesco Sansalvadore committed 2025-08-18 18:07:08 +02:00
1 parent 1718795529
commit 1783287f97
4 files changed
+7 -28

No files matched your search

+2 -3
View File
@@ -1,11 +1,10 @@
import { draftMode } from 'next/headers'
import BlogPostClient from './BlogPostClient'
import { getAllPostSlugs, getPostdata, getSortedPosts } from 'lib/posts'
import { getAllCMSPostSlugs, getCMSPostBySlug } from 'lib/get-cms-posts'
import { draftMode } from 'next/headers'
import type { Blog, BlogData, PostReturnType } from 'types/post'
import BlogPostClient from './BlogPostClient'
type MatterReturn = {
data: BlogData
content: string
@@ -14,7 +14,7 @@ export async function generateStaticParams() {
return categories.map((category: string) => ({ category }))
}
export const revalidate = 600
export const dynamic = 'force-static'
export async function generateMetadata({ params }: { params: Params }): Promise<Metadata> {
const capitalizedCategory = startCase(params.category.replaceAll('-', ' '))
+3 -23
View File
@@ -1,9 +1,7 @@
import fs from 'fs'
import type { Metadata } from 'next'
import { generateRss } from 'lib/rss'
import BlogClient from './BlogClient'
import { getSortedPosts } from 'lib/posts'
import { getAllCMSPosts } from 'lib/get-cms-posts'
import BlogClient from './BlogClient'
import type { Metadata } from 'next'
export const dynamic = 'force-static'
@@ -33,25 +31,7 @@ export default async function BlogPage() {
return dateB - dateA
})
// Generate RSS feed from static posts
const rss = generateRss(allPostsData)
try {
fs.writeFileSync('./public/rss.xml', rss)
} catch {}
// Generate PlanetPG author feeds
try {
const planetPgPosts = allPostsData.filter((post: any) => post.tags?.includes('planetpg'))
const planetPgAuthors = planetPgPosts.map((post: any) => post.author.split(','))
const uniquePlanetPgAuthors = new Set(([] as string[]).concat(...(planetPgAuthors as any)))
uniquePlanetPgAuthors.forEach((author) => {
const authorPosts = planetPgPosts.filter((post: any) => post.author.includes(author))
if (authorPosts.length > 0) {
const authorRss = generateRss(authorPosts, author as string)
fs.writeFileSync(`./public/planetpg-${author}-rss.xml`, authorRss)
}
})
} catch {}
// RSS writing moved out of runtime to avoid tracing the entire public directory into serverless bundles
return <BlogClient blogs={allPostsData as any} />
}
+1 -1
View File
@@ -14,7 +14,7 @@ export async function generateStaticParams() {
return tags.map((tag: string) => ({ tag }))
}
export const revalidate = 600
export const dynamic = 'force-static'
export async function generateMetadata({ params }: { params: Params }): Promise<Metadata> {
const capitalizedTag = startCase(params.tag.replaceAll('-', ' '))