1: posts
Reading ModeRO
$ cat 20210908_first-post.md

#Building a technical blog with Next.js

Date:2021-09-08 (Wed)
>The stack behind my new blog and the details that mattered to me, from MDX articles to styling and code examples.

##Table of Contents

##Introduction

First post on the new blog! 🎉

I’ve been learning Next.js and can finally build most of what I can picture.
I built this blog from scratch in Next.js to give myself a place to publish what I learn.
I have taken quite a lot of inspiration from Zenn and Qiita.

There are still many things that haven't been implemented yet, but since they have finally taken shape, I'm posting my first article.
Regarding the parts that are not yet implemented, we will continue to implement them in the future and will also introduce the situation in the article.

##The technology stack

I created the blog using the following technology stack.

  • Next.js (+TypeScript)
  • TailwindCSS
  • MDX

###Next.js

Actually, I have had a technical blog using HUGO for a while.
At the time of creation, I had little knowledge of the frontend, and I was only tinkering with and using the templates that others had created.
When modifying HUGO templates, you had to directly edit HTML and CSS, which was a challenge because it didn't lead to high maintenance.

Another reason is also performance, which is the greatest attraction of Next.js.
Previously, I had asked a friend to help me create a blog with Next.js, and I was shocked to find that my Lighthouse score was almost completely compromised.
If it's the case, I wanted to make a blog that transitions smoothly for myself as well.

###TailwindCSS

I used TailwindCSS for styling.
TailwindCSS allows styling by adding Class attributes corresponding to each CSS property, called Utility Classes.
Since you can style while implementing pages and components, you can proceed with development efficiently.
Also, since Utility Classes are compatible with many CSS properties, once you get familiar with them, you can select a Utility Class without even looking at the documentation, which is another favorite point.

###MDX

MDX means that you can use React components in Markdown.
Since we are using the React framework Next.js, we adopted MDX to embed components as needed within the articles.

For example, if a post describes something like this:

JSX
<div className="rounded-lg border-2 border-blue-200 text-center text-2xl">You can style the text like this</div>

It will be displayed as follows.

You can decorate it like this

If you have components you use frequently in the future, you can create them in a separate file so that you can import and use them later.

##Details I cared about

Finally, I would like to introduce the points I was particularly focused on when creating this blog.
This time, the part I paid the most attention to was the code blocks.
Since this is a blog about programming, it is expected that source code will often be included.
I implemented it to be as visually appealing and user-friendly as possible.

First, let's look at the code syntax highlighting.
By specifying the language as shown below, we will color it according to that language.

```javascript
const hello = "Hello World!";

console.log(hello);
```
JavaScript
const hello = 'Hello World!';

console.log(hello);

I used prism-react-renderer for the syntax highlighting.
This is a React component for Prism.js that implements syntax highlighting.

Also, just like with Zenn and Qiita, if you enter the file name, it will also display it.

```python:hello.py
hello = "Hello World!"

print(hello)
```
hello.py
hello = "Hello World!"

print(hello)

I tried to be a bit picky and make sure that the language icon is also displayed next to the file name.
I also tried to display this icon in the tag section as well.
This section is about something I thought was nice while looking at Zenn.
Since it's a good opportunity, I tried to show an icon in the code block section as well.

Additionally, you can copy the code in this code block by pressing the Copy button in the top right corner.
There are some sites with a copy button like this occasionally, but personally, I felt that it would be helpful if there were one, so I implemented it this time.

##Wrapping up

I now have a technical blog built with Next.js.
There are still plenty of things I’d like to add. I’ll keep improving it as I use it.

Here’s what’s on my list:

  • Implementation of Unimplemented Pages (Works, About)
  • Implementing RSS and Sitemap functionalities
  • Mobile design enhancement

## Comments

"20210908_first-post.md" [readonly]3L, 4720B
utf-8100%