Upgrade to Next.js 16 with Turbopack and Contentlayer2
- Upgraded Next.js to v16, React to v19 - Migrated from contentlayer to contentlayer2 - Migrated to Turbopack by decoupling Contentlayer from webpack - Updated all page components to handle async params (Next.js 15+ breaking change) - Changed package.json to type: module and renamed config files to .cjs - Updated README with current tech stack and article creation instructions - Fixed tag encoding issue (removed double encoding) - All security vulnerabilities resolved (npm audit: 0 vulnerabilities)
This commit is contained in:
72
README.md
72
README.md
@@ -1,15 +1,16 @@
|
||||
# Personal Blog (Next.js + Contentlayer)
|
||||
|
||||
This is a personal blog built with **Next.js 13 (App Router)**, **Contentlayer**, and **Tailwind CSS**.
|
||||
This is a personal blog built with **Next.js 16 (App Router)**, **Contentlayer2**, and **Tailwind CSS**.
|
||||
Markdown content (posts & pages) lives in a separate repository and is consumed via a git submodule.
|
||||
Recent iterations focused on migrating every image to `next/image`, refreshing the typography scale for mixed Chinese/English copy, and layering an elegant scrolling timeline aesthetic onto the home + blog index.
|
||||
Recent updates include upgrading to Next.js 16 with Turbopack, migrating to Contentlayer2, and implementing React 19 features.
|
||||
|
||||
## Tech Stack
|
||||
|
||||
- **Framework**: Next.js 13 (App Router)
|
||||
- **Framework**: Next.js 16 (App Router) with Turbopack
|
||||
- **Language**: TypeScript
|
||||
- **Runtime**: React 19
|
||||
- **Styling**: Tailwind CSS + Typography plugin
|
||||
- **Content**: Markdown via Contentlayer (`contentlayer/source-files`)
|
||||
- **Content**: Markdown via Contentlayer2 (`contentlayer2/source-files`)
|
||||
- **Theming**: `next-themes` (light/dark), env‑driven accent color system
|
||||
- **Content source**: Git submodule `content` → [`personal-blog`](https://gitea.gbanyan.net/gbanyan/personal-blog.git)
|
||||
|
||||
@@ -294,15 +295,70 @@ This ensures your `content` folder matches the commit referenced in `blog-nextjs
|
||||
|
||||
## Available npm Scripts
|
||||
|
||||
- `npm run dev` – Start Next.js dev server (Contentlayer is integrated via `next-contentlayer`).
|
||||
- `npm run build` – Run `next build` for production.
|
||||
- `npm run dev` – Start Contentlayer and Next.js dev server concurrently (with Turbopack).
|
||||
- `npm run build` – Build content and production bundle (`contentlayer2 build && next build`).
|
||||
- `npm run start` – Start the production server (after `npm run build`).
|
||||
- `npm run lint` – Run Next.js / ESLint linting.
|
||||
- `npm run contentlayer` – Manually run `contentlayer build` (optional).
|
||||
- `npm run sync-assets` – Copy `content/assets` to `public/assets`.
|
||||
|
||||
## Adding New Content
|
||||
|
||||
### Creating a New Blog Post
|
||||
|
||||
1. Navigate to the `content/posts` directory (inside the submodule):
|
||||
|
||||
```bash
|
||||
cd content/posts
|
||||
```
|
||||
|
||||
2. Create a new markdown file (e.g., `my-new-post.md`):
|
||||
|
||||
```markdown
|
||||
---
|
||||
title: "My New Post Title"
|
||||
published_at: "2025-01-15"
|
||||
tags:
|
||||
- "Technology"
|
||||
- "Tutorial"
|
||||
description: "A brief description of the post"
|
||||
feature_image: "../assets/my-image.jpg"
|
||||
---
|
||||
|
||||
Your post content goes here...
|
||||
```
|
||||
|
||||
3. If using images, place them in `content/assets/` and reference them with relative paths:
|
||||
|
||||
```markdown
|
||||

|
||||
```
|
||||
|
||||
4. Commit and push changes in the submodule:
|
||||
|
||||
```bash
|
||||
git add .
|
||||
git commit -m "Add new post: My New Post Title"
|
||||
git push
|
||||
```
|
||||
|
||||
5. Update the parent repository to reference the new submodule commit:
|
||||
|
||||
```bash
|
||||
cd ../..
|
||||
git add content
|
||||
git commit -m "Update content submodule"
|
||||
git push
|
||||
```
|
||||
|
||||
6. The new post will appear automatically after rebuilding or restarting the dev server.
|
||||
|
||||
### Creating a New Static Page
|
||||
|
||||
Follow the same process as above, but create the file in `content/pages/` instead.
|
||||
|
||||
## Deployment Notes
|
||||
|
||||
- This is a standard Next.js 13 App Router project and can be deployed to:
|
||||
- This is a Next.js 16 App Router project with Turbopack and can be deployed to:
|
||||
- Vercel
|
||||
- Any Node.js host running `npm run build && npm run start`
|
||||
- Make sure to:
|
||||
|
||||
@@ -20,11 +20,11 @@ export function generateStaticParams() {
|
||||
}
|
||||
|
||||
interface Props {
|
||||
params: { slug: string };
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
export function generateMetadata({ params }: Props): Metadata {
|
||||
const slug = params.slug;
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const post = getPostBySlug(slug);
|
||||
if (!post) return {};
|
||||
|
||||
@@ -34,8 +34,8 @@ export function generateMetadata({ params }: Props): Metadata {
|
||||
};
|
||||
}
|
||||
|
||||
export default function BlogPostPage({ params }: Props) {
|
||||
const slug = params.slug;
|
||||
export default async function BlogPostPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const post = getPostBySlug(slug);
|
||||
|
||||
if (!post) return notFound();
|
||||
|
||||
@@ -17,11 +17,11 @@ export function generateStaticParams() {
|
||||
}
|
||||
|
||||
interface Props {
|
||||
params: { slug: string };
|
||||
params: Promise<{ slug: string }>;
|
||||
}
|
||||
|
||||
export function generateMetadata({ params }: Props): Metadata {
|
||||
const slug = params.slug;
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const page = getPageBySlug(slug);
|
||||
if (!page) return {};
|
||||
|
||||
@@ -31,8 +31,8 @@ export function generateMetadata({ params }: Props): Metadata {
|
||||
};
|
||||
}
|
||||
|
||||
export default function StaticPage({ params }: Props) {
|
||||
const slug = params.slug;
|
||||
export default async function StaticPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const page = getPageBySlug(slug);
|
||||
|
||||
if (!page) return notFound();
|
||||
|
||||
@@ -22,11 +22,11 @@ export function generateStaticParams() {
|
||||
}
|
||||
|
||||
interface Props {
|
||||
params: { tag: string };
|
||||
params: Promise<{ tag: string }>;
|
||||
}
|
||||
|
||||
export function generateMetadata({ params }: Props): Metadata {
|
||||
const slug = params.tag;
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { tag: slug } = await params;
|
||||
// Find original tag label by slug
|
||||
const tag = allPosts
|
||||
.flatMap((post) => post.tags ?? [])
|
||||
@@ -37,15 +37,15 @@ export function generateMetadata({ params }: Props): Metadata {
|
||||
};
|
||||
}
|
||||
|
||||
export default function TagPage({ params }: Props) {
|
||||
const slug = params.tag;
|
||||
export default async function TagPage({ params }: Props) {
|
||||
const { tag: slug } = await params;
|
||||
|
||||
const posts = allPosts.filter(
|
||||
(post) => post.tags && post.tags.some((t) => getTagSlug(t) === slug)
|
||||
);
|
||||
|
||||
const tagLabel =
|
||||
posts[0]?.tags?.find((t) => getTagSlug(t) === slug) ?? params.tag;
|
||||
posts[0]?.tags?.find((t) => getTagSlug(t) === slug) ?? slug;
|
||||
|
||||
return (
|
||||
<SidebarLayout>
|
||||
|
||||
3
next-env.d.ts
vendored
3
next-env.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
import "./.next/dev/types/routes.d.ts";
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
import { withContentlayer } from 'next-contentlayer2';
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
images: {
|
||||
remotePatterns: []
|
||||
},
|
||||
webpack: (config) => {
|
||||
config.ignoreWarnings = [
|
||||
...(config.ignoreWarnings || []),
|
||||
// Contentlayer dynamic import / cache analysis warnings
|
||||
/@contentlayer\/core[\\/]dist[\\/]dynamic-build\.js/,
|
||||
/@contentlayer\/core[\\/]dist[\\/]getConfig[\\/]index\.js/,
|
||||
/@contentlayer\/core[\\/]dist[\\/]generation[\\/]generate-dotpkg\.js/
|
||||
];
|
||||
return config;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export default withContentlayer(nextConfig);
|
||||
export default nextConfig;
|
||||
|
||||
1714
package-lock.json
generated
1714
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@@ -4,9 +4,9 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"dev": "concurrently \"contentlayer2 dev\" \"next dev\"",
|
||||
"sync-assets": "node scripts/sync-assets.mjs",
|
||||
"build": "npm run sync-assets && next build",
|
||||
"build": "npm run sync-assets && contentlayer2 build && next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"contentlayer": "contentlayer build"
|
||||
@@ -14,8 +14,10 @@
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"type": "commonjs",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@emotion/is-prop-valid": "^1.4.0",
|
||||
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
||||
"@fortawesome/free-brands-svg-icons": "^7.1.0",
|
||||
"@fortawesome/free-solid-svg-icons": "^7.1.0",
|
||||
"@fortawesome/react-fontawesome": "^3.1.0",
|
||||
@@ -24,11 +26,11 @@
|
||||
"framer-motion": "^12.23.24",
|
||||
"gray-matter": "^4.0.3",
|
||||
"markdown-wasm": "^1.2.0",
|
||||
"next": "^13.5.11",
|
||||
"next": "^16.0.3",
|
||||
"next-contentlayer2": "^0.5.8",
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"rehype-autolink-headings": "^7.1.0",
|
||||
"rehype-slug": "^6.0.0",
|
||||
"remark-gfm": "^4.0.1",
|
||||
@@ -40,10 +42,11 @@
|
||||
"@types/node": "^24.10.1",
|
||||
"@types/react": "^19.2.5",
|
||||
"autoprefixer": "^10.4.22",
|
||||
"concurrently": "^9.2.1",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-config-next": "^13.5.11",
|
||||
"eslint-config-next": "^16.0.3",
|
||||
"postcss": "^8.5.6",
|
||||
"tailwindcss": "^3.4.18",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"types": [
|
||||
"node"
|
||||
@@ -40,9 +40,10 @@
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".contentlayer/generated",
|
||||
".next/types/**/*.ts"
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user