Blog System Migration
ARCHITECTURE •
Situation
The blog system used file-based routes with TSX components (/blog/[slug]/page.tsx).
I had to rebuild the whole project to publish an article. It was inefficient, and most of all, inconvenient.
Then, I realized markdown syntax could be applicable to this project, as many platforms support it.
Tasks
- Database Integration: Leverage existing Neon PostgreSQL + Prisma infrastructure
- Content Pipeline: Design markdown processing pipeline with consistent styling
- Custom Components: Map markdown elements to Next.js optimized components (Image, Link)
- Routing Strategy: Migrate from slug-based to ID-based URLs
- Backward Compatibility: Maintain old URLs via redirects (SEO preservation)
- Security & Performance: Implement URL sanitization, image optimization, lazy loading
Actions
Phase 1: Infrastructure Preparation
- Designed normalized schema:
posttable with many-to-manytagrelations via junction table - Created the
@juun/dbpackage: a framework-agnostic database client with namespace pattern - Added caching layer using
next/cacheto reduce database queries by ~99% - Structured both DB and cache APIs with consistent namespace pattern (
post.get.all(),post.get.byId())
Phase 2: Content Pipeline Development
- Designed markdown processing pipeline using unified/remark/rehype ecosystem:
gray-matter: Extract frontmatter metadataremark-parse→remark-gfm→remark-rehype: Markdown to HTML ASTrehype-raw: Parse raw HTML nodesrehype-unwrap-images: Prevent hydration errorsrehype-react: Convert AST to React elements
- Implemented custom component mappings:
<a>→ Next.jsLink(client-side navigation) / secure external links