iTranslated by AI
A Guide to Building a Personal Blog with Next.js
Introduction
My name is yajium (@yajium_), and I am a new graduate engineer.
I am currently in my first year of professional life and started programming this April. Since I use C# at work, I studied Next.js and React from scratch for this project.
I created a personal blog using React + Next.js + Tailwind CSS, so I hope this serves as a helpful reference for others starting from zero!
I began my blog creation after completing the Next.js tutorial, so I recommend starting with the tutorial as your first step.
↓ GitHub
Environment Setup
Setting up blog-starter
For my blog, I used the standard create next-app like in the Next.js tutorial, but this blog-starter seems like a better option.
I will proceed with this blog-starter for this explanation.
- Install yarn
While you can proceed with npm, yarn is reportedly faster (it's like an enhanced version of npm), so we will use yarn.
- This assumes Node.js is already installed. Skip if you already have yarn.
npm install --global yarn
- Create the blog-starter repository
// After moving to the directory where you want to create the repository
yarn create next-app --example blog-starter [your-project-name]
- Move to the [your-project-name] directory created in step 2 and run yarn dev
cd [your-project-name]
yarn dev
- Access http://localhost:3000/ and if the page below is displayed, you're good to go!
Recommended Settings
🌟 Prettier installation
Prettier is a code formatter that allows you to maintain a consistent coding style across your source code.
-
You can run Prettier in real-time by installing a VSCode extension.
Install the following extension in VSCode:
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode -
Open the project created during the environment setup in VSCode, and create a
.vscodedirectory and asetting.jsonconfiguration file directly under the project directory. -
Add the following code inside
setting.json.
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}

-
Enable Format On Save
Open VS Code settings and typeonsavein the search bar. Then, check the box forFormat On Save.

-
Set Prettier as the Default Formatter
Typeformatin the same settings search bar as step 4, select Prettier in theDefault Formatteritem, and turn on settings sync using the button in the upper right.

-
Now your code will be formatted whenever you save!
🌟 ESLint installation
*This is optional since we are creating a personal blog, so you can skip it.
ESLint is what is known as a linter—a tool that statically analyzes programs to find bugs and issues. For example, if you run ESLint while there is a console.log in your source code, it can output an error like "console.log remains! Please fix it." This is helpful when you want to unify coding styles in team development.
↓ For those who want to know more
Like Prettier, you can use a VSCode extension.
Add the following code to your setting.json.
{
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"eslint.alwaysShowStatus": true,
}
Installing Tailwind CSS
It's very simple.
Tailwind CSS is a CSS framework; you might be familiar with Bootstrap as a well-known CSS framework.
The basic way to use Tailwind CSS is, for example, when you want to write CSS for font-size, you can easily apply it by writing something like className="text-xl".
- Move to the repository you created and run the following commands:
yarn add -D tailwindcss postcss autoprefixer
yarn tailwindcss init -p
- In the
contentarray withintailwind.config.js, specify the directories and file paths where you plan to apply Tailwind CSS.
module.exports = {
content: [
+ "./pages/**/*.{js,ts,jsx,tsx}",
+ "./src/components/**/*.{js,ts,jsx,tsx}",
],
...
}
By default, pages and components are already added, so if they are already there, this step is unnecessary.
- Add Tailwind CSS imports to
index.css(orglobals.css)
In this blog-starter, it is namedindex.cssinstead ofglobals.css, so add the following imports to it (skip if they already exist).
+ @tailwind base;
+ @tailwind components;
+ @tailwind utilities;
What are globals.css or index.css? They are CSS files applied to every page. For example, if you write CSS for the p tag in this file, since this CSS file is imported in _app.tsx, that CSS will be applied to the p tags on every page.
- Try using it
You can use it by writing it in the following format.
<h1 className="text-3xl font-bold underline">
Hello world!
</h1>
🌟 Extra Edition
If you have things that will be reused frequently (like li tags), writing classes like <li className="text-3xl font-bold underline"></li> every time would be a lot of work. There is a way to use Tailwind CSS similar to writing regular CSS.
You can use the Tailwind CSS style by using @apply as shown below.
import styles from "../styles/yyy.module.css";
<div className={styles["profile-detail"]}>...</div>
.profile-detail {
@apply mx-10 my-16 grid grid-cols-1 gap-14 text-left;
}
.profile-detail h2 {
@apply border-b border-b-gray-300 pb-3 text-center text-lg font-semibold;
}
In VS Code, an error might occur with @apply. In that case, you can resolve it by installing an extension called PostCSS Language Support.
Font Settings
Now, let's enable your favorite fonts in Tailwind CSS.
- Copy the
@importandfont-familyof your favorite font from Google Fonts or similar sites.

-
Add the
@importtoindex.css(orglobals.css).

-
Add the
font-familytotailwind.config.js.
theme: {
extend: {
+ fontFamily: {
+ fancy: ["Kiwi Maru"],
+ },
},
},
You can use any name for fancy. Enter the font-family name inside the [].
- Use it in practice
As shown below, use it in the formatfont-[the name you set in step 3].
<div className="font-fancy">
<main>{children}</main>
</div>
☃ Little Tips & Tricks ☃
By this point, you should be able to handle basic development. Here, I'll list the libraries I used for my personal blog and the points where I got stuck.
Making Markdown look like Zenn
When converting blog posts into Markdown format, it takes a lot of effort to output them as-is or create custom CSS. For this project, I used Zenn's library to give it a Zenn-like appearance. It was very easy to apply, so I highly recommend it!
Icon Settings
React Icons is very convenient when you want to display icons like the one in the image below.

This article summarizes it well, so please take a look.
SNS Share Buttons
For example, these are Twitter buttons for sharing a post on social media (as seen in the image below). There is also a useful library for this called react-share.
The usage is described in the Readme.

Automatic OGP Image Generation
If you create SNS share buttons, you should definitely have OGP settings as well.
I used @vercel/og. You should be able to implement it by following this reference.
However, I got stuck quite a bit with these OGP image settings, so I'll leave some notes here as precautions.
- Apply Japanese fonts
If you want to dynamically change the OGP image using the post title and that title is in Japanese, it's better to include Japanese fonts before the initial deployment.
The reason for doing this before deployment is that if there are Japanese characters or full-width symbols, vercel/og might not handle them correctly, generating a completely white image. If you deploy in that state, the cache will remain on Twitter's side, and even if you upload corrected code, the cached white image might continue to appear for a year. Although it seems possible to shorten the cache duration, I wasn't able to go that far. If anyone has expertise in this, please let me know in the comments!
Images inside md files
When inserting images within a .md file, you need the path where the image is located. However, on localhost or after deployment, the images couldn't be retrieved, resulting in a Not Found error.
It seems that after converting Markdown to HTML, you need to transform the images into React component <Image> tags.
Following the steps below might work, but when combined with zenn-markdown, it became confusing, so I decided to load them from Google Drive instead.
However, image display is currently quite slow, so I feel like I want to switch to the method above or change it in some way.
If you know a better method, I'd be happy if you could let me know in the comments 😃
Finally
That summarizes what I did when creating a personal blog using Next.js.
I hope you find it helpful!
Reference Articles
Discussion