How guangzhengli/nextjs-blog-template works
Main Components
• Next.js Application: At the core, the project uses Next.js (with the new app directory structure) to manage routing and server-side rendering.
• Routing & Pages (src/app): Includes the main pages such as homepage, blog listing (src/app/blog/page.tsx), blog details (src/app/blog/[...slug]/page.tsx), and error routes (not-found.tsx, robots.ts, sitemap.ts).
• Content (src/content): Markdown and MDX files are stored under src/content/blog. These files represent the actual blog posts and are integrated into the application.
• Configuration & Utilities (src/lib): Contains centralized configuration (src/lib/config.ts) for site settings (SEO, social links, author info, etc.) along with utility functions (src/lib/toc.ts, src/lib/utils.ts).
• Hooks (src/hooks): Custom React hooks (e.g., use-mounted.ts) which likely enhance component behavior.
• Build & Deployment Scripts (scripts and public): The scripts directory includes custom scripts (generate-rss.js and generate-sitemap.js) for generating RSS feeds and sitemaps. The public directory holds assets and the generated feeds (atom.xml, feed.json, rss.xml, site.webmanifest).
• Tooling & Configuration: Files like tsconfig.json, eslint.config.mjs, package.json, next.config.ts, and postcss.config.mjs indicate TypeScript use, linting rules, and build configuration that support the overall project architecture.
Relationships and Interactions
• User/Browser: Interacts with the Next.js frontend.
• Frontend (app pages and UI components): Dynamically fetches and renders content (markdown/mdx) from the src/content directory and applies the configurations from src/lib/config.ts.
• Components and Hooks: UI components interact with custom hooks and utilities to provide interactive behavior and consistent layout.
• Build Scripts: Scripts (under scripts/) run during build/deployment to generate essential assets (RSS feeds, sitemaps) and are triggered by package.json commands (npm run generate-rss, npm run generate-sitemap).
• External Services: Integration with Giscus for comments and configuration for social media links (github, twitter, etc.) as set in config.
Architectural Patterns & Design Principles
• Separation of Concerns: Code is organized according to functionality—routing (src/app), UI (src/components), content (src/content), configuration (src/lib).
• Modularization: Reusable components and utilities help maintain clarity and ease of updates.
• Convention over Configuration: Leveraging Next.js app directory conventions, standardized naming, and centralized configuration (src/lib/config.ts).
• Server-Side Rendering & Static Optimization: Next.js handles both dynamic and static content, as seen in the pages and build scripts.
• Extensibility: Clear separation between core functionality and configurations allow easy extensions and theming.