Posted On Jul 1

Building a Blog with Next.js: A Step-by-Step Guide

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

Let's take a look at how to make a blog using NextJS and VERCEL. There is also a way to make a word press blog spot, but if you make it yourself as a developer, it will be a good experience.

Create Next.js Project

npx create-next-app cozy-world

Since I'm going to make Next.js with typescript, I wrote the following.

npx create-next-app@latest --typescript cozy-world

Apply the Next.js blog template

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

There is a blog boilerplate using Nextjs in vercel's official document, so apply it by referring to this repository.

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

Use the blog-starter code to remove unnecessary parts and use it.

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

Because cozy-world is largely divided into blog posts and projects, I modified it to have the folder structure as above.

SCSS

The style of this blog uses scss.

yarn add sass

When sass is installed, you can create it by creating component.module.scss under the component folder as shown below.

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

If the file name is written as module.scss, the unique class name in each component is automatically applied.

The scss file was applied using bind of classnames as shown below.

import React from "react";
import style from "./Header.module.scss";
import classnames from "classnames/bind";
import Link from "next/link";

const cx = classnames.bind(style);

const Header = () => {
  return (
    <header className={cx("header")}>
      <div className={cx("inner")}>
        <h1 className={cx("title")}>
          <Link href={"/"}>Cozy World</Link>
        </h1>
        <nav className={cx("nav_area")}>
          <Link href={"/posts"} className={cx("nav_item")}>
            Posts
          </Link>
          <Link href={"/projects"} className={cx("nav_item")}>
            Projects
          </Link>
        </nav>
      </div>
    </header>
  );
};

export default Header;

If written as above, the class name is uniquely applied as shown in the picture below.

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

Deploy

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

Now that we have created the basic structure for our blog and written the css, let's deploy it using vercel.

Create a new project after signing up for vercel.

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

When a project is pushed to a github repository, it is automatically deployed.

250466992-88684525-bfce-4688-bb1e-8404cdd5fc0c

Today, I learned how to simply create a blog using Nextjs and vercel.

Next, we will cover the process of adding necessary features to the blog.