diff --git a/apps/www/contentlayer.config.ts b/apps/www/contentlayer.config.ts index b1ebcea4564..13ab0eff9d7 100644 --- a/apps/www/contentlayer.config.ts +++ b/apps/www/contentlayer.config.ts @@ -6,21 +6,13 @@ export const BlogPost = defineDocumentType(() => ({ filePathPattern: `**/*.mdx`, // contentType: 'mdx', fields: { - author: { type: 'string', required: true }, - author_url: { type: 'string', required: false }, - author_title: { type: 'string', required: false }, - author_image_url: { type: 'string', required: false }, date: { type: 'string', required: true }, description: { type: 'string', required: true }, categories: { type: 'list', of: { type: 'string' }, required: true }, image: { type: 'string', required: false }, - launchweek: { type: 'string', required: false }, tags: { type: 'list', of: { type: 'string' }, required: false }, title: { type: 'string', required: true }, thumb: { type: 'string', required: false }, - toc_depth: { type: 'number', required: false }, - video: { type: 'string', required: false }, - youtubeHero: { type: 'string', required: false }, }, computedFields: { url: { diff --git a/apps/www/package.json b/apps/www/package.json index 69d22441b09..06362d3b077 100644 --- a/apps/www/package.json +++ b/apps/www/package.json @@ -12,7 +12,7 @@ "lint": "next lint", "clean": "rimraf node_modules", "typecheck": "pnpm run content:build && tsc --noEmit", - "content:build": "contentlayer2 build && node scripts/generateStaticContent.mjs", + "content:build": "contentlayer2 build && node scripts/stripContentlayerBody.mjs && node scripts/generateStaticContent.mjs", "prettier": "prettier --cache --write \"./{pages,components,lib,stores,styles,tests}/**/*.{ts,tsx,md,js,jsx,json}\"", "postbuild": "node ./internals/generate-sitemap.mjs && ./../../scripts/upload-static-assets.sh", "knip": "knip" diff --git a/apps/www/scripts/stripContentlayerBody.mjs b/apps/www/scripts/stripContentlayerBody.mjs new file mode 100644 index 00000000000..f6f6ea818e1 --- /dev/null +++ b/apps/www/scripts/stripContentlayerBody.mjs @@ -0,0 +1,36 @@ +import { promises as fs } from 'fs' +import path from 'path' +import { fileURLToPath } from 'url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) +const blogpostDir = path.join(__dirname, '../.contentlayer/generated/BlogPost') + +async function stripBodyFromBlogpostJsonFiles() { + try { + const stat = await fs.stat(blogpostDir).catch(() => null) + if (!stat || !stat.isDirectory()) return + + const entries = await fs.readdir(blogpostDir) + const jsonFiles = entries.filter((name) => name.endsWith('.json')) + + await Promise.all( + jsonFiles.map(async (fileName) => { + const fullPath = path.join(blogpostDir, fileName) + try { + const raw = await fs.readFile(fullPath, 'utf8') + const data = JSON.parse(raw) + if (data && typeof data === 'object' && 'body' in data) { + delete data.body + await fs.writeFile(fullPath, JSON.stringify(data), 'utf8') + } + } catch { + // Skip files that cannot be processed + } + }) + ) + } catch { + // Silently ignore to avoid failing the build if optional + } +} + +await stripBodyFromBlogpostJsonFiles()