Building Portfolio in Next.js
Tutorials
Building Portfolio in Next.js

By Subash Maharjan


Chapters
  • Chapter 1

    Introduction

  • Chapter 2

    Project Architecture

  • Chapter 3

    SCSS Design Tokens

  • Chapter 4

    The Hero Component

  • Chapter 5

    The MDX Content Layer

  • Chapter 6

    Syntax Highlighting & Project Filters

  • Chapter 7

    Smooth Layout Transitions

  • Chapter 8

    Modern Contact Forms

  • Chapter 9

    SEO & Deployment

  • Chapter 10

    Lighthouse Performance & Blogging

  • Chapter 11

    Interactive Playgrounds & Subscriptions

  • Chapter 12

    Dynamic Social Previews & Launch

  • Chapter 13

    Project Summary for Recruiters

  • building portfolio in nextjs

    The MDX Content Layer

    Chapter 5

    2 min read

    On this page
    1. Installation2. Defining your Content structure3. Dynamic Rendering with App Router4. Customizing MDX Components
    Company LogoSubash
    HOMEABOUTPORTFOLIOCONTENTSCONTACT

    To manage project case studies, we'll use a Content Layer approach. While Contentlayer was a popular choice, many developers in 2026 have transitioned to Velite or next-mdx-remote for better maintenance and App Router compatibility.

    1. Installation

    Install the necessary tools to process MDX and handle frontmatter (metadata like titles and dates).

    npm install next-mdx-remote @next/mdx @mdx-js/loader @mdx-js/react

    2. Defining your Content structure

    Create a central directory for your projects. Each file will represent a unique project page.

    src/content/
    └── projects/
        ├── amazing-web-app.mdx
        └── mobile-design-system.mdx

    Example MDX File (amazing-web-app.mdx):

    ---
    title: "Amazing Web App"
    date: "2026-02-20"
    tags: ["Next.js", "SCSS", "TypeScript"]
    ---
     
    # The Challenge
    Building a scalable architecture for...

    3. Dynamic Rendering with App Router

    Use a Dynamic Route Segment to fetch and render your MDX content based on the URL slug.

    // src/app/portfolio/[slug]/page.tsx
    import { MDXRemote } from 'next-mdx-remote/rsc';
    import fs from 'fs';
    import path from 'path';
    import matter from 'gray-matter';
     
    export default async function ProjectPage({ params }: { params: { slug: string } }) {
      const { slug } = params;
      const filePath = path.join(process.cwd(), 'src/content/projects', `${slug}.mdx`);
      const fileContent = fs.readFileSync(filePath, 'utf8');
      
      // Parse frontmatter (metadata) and content
      const { content, data } = matter(fileContent);
     
      return (
        <article className="container">
          <header>
            <h1>{data.title}</h1>
            <p>{data.date}</p>
          </header>
          
          {/* Render the MDX content on the server */}
          <MDXRemote source={content} />
        </article>
      );
    }

    4. Customizing MDX Components

    You can map standard Markdown elements (like h1 or p) to your own React components or SCSS Modules.

    // Define custom components
    const components = {
      h1: (props: any) => <h1 className="text-crimson" {...props} />,
      p: (props: any) => <p className="text-muted" {...props} />,
    };
     
    // Use them in the MDXRemote component
    <MDXRemote source={content} components={components} />

    Performance Tip: Use generateStaticParams to pre-render these pages at build time, ensuring your portfolio is lightning-fast and SEO-optimized.

    HOME
    ABOUT
    PORTFOLIO
    CONTENTS
    CONTACT

    © 2026Subash Maharjan™

    Made byHudeoworks Design