Skip to content

Blog built with NextJs 13, Contentlayer, Giscus and NextAuth. It uses Github API for admin section that allows managing markdown files rendered with Codemirror.

Notifications You must be signed in to change notification settings

pavlovtech/NextBlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Oleksandr Pavlov
Jan 8, 2024
ada14f8 Β· Jan 8, 2024
May 12, 2023
Jan 8, 2024
Dec 25, 2023
Dec 25, 2023
May 18, 2023
Oct 27, 2023
Sep 29, 2023
May 11, 2023
May 18, 2023
May 11, 2023
Dec 25, 2023
Sep 29, 2023
Dec 16, 2023
Sep 29, 2023
Dec 16, 2023
Dec 25, 2023
May 11, 2023
May 18, 2023
Dec 25, 2023
May 14, 2023

Repository files navigation

NextBlog

My personal blog built with NextJs 13, Contentlayer, Giscus and NextAuth. It uses Github API for admin section that allows managing markdown files rendered with Codemirror.

Design is based on https://github.com/pycoder2000/blog

Demo

Demo: alexpavlov.dev

Motivation

I wanted to build a blog based on markdown files with latest NextJS 13 with server components and host it on Vercel. Additionally, I needed a CMS functionality (CRUD for markdown files), but how do you create a CMS for statically generated web site when content stored only as static files inside the Github repository?

The idea is simple:

  1. Add an admin page with auth using NextAuth
  2. Use Vercel hosting with github integration for CI/CD
  3. Create an API using Github API for managing blog posts
  4. When the change to blog post files is made, it is pushed to github.
  5. Then Vercel automatically starts a new deployment
  6. Web site displayes updated statically generated content

Currently, the best solution for managing markdown files is Contentlayer, so I wanted to use it as well.

For the lack of existing blog starters that with the mentioned functionality I desided to create it myself.

Architecture

image

Home page

image

πŸ“š Tech Stack

Name Link
Framework NextJS
Markdown Contentlayer
Authentication NextAuth
Deployment Vercel
Styling Tailwindcss
Comments Giscus
Data access GitHub API
Markdown editor Codemirror

πŸͺœ Project structure

πŸ“¦ root
β”œβ”€β”€ πŸ—‚οΈ app                     # NextJs 13 app router directory
β”‚ β”œβ”€β”€ πŸ—‚οΈ admin                 # Admin functionality for creating and editing blog posts
β”‚ β”œβ”€β”€ πŸ—‚οΈ api                   # CRUD api blog posts (Github API is used)
β”‚ └── πŸ—‚οΈ blog                  # Blog functionality
β”‚ └── πŸ—‚οΈ components            # Blog UI components
β”œβ”€β”€ πŸ—‚οΈ configs                 # Configs
β”œβ”€β”€ πŸ—‚οΈ lib                     # Utilities
β”œβ”€β”€ πŸ—‚οΈ posts                   # Blog posts in markdown
β”œβ”€β”€ πŸ—‚οΈ public                  # Static files for images
β”œβ”€β”€ πŸ—‚οΈ styles                  # CSS
β”œβ”€β”€ πŸ“ contentlayer.config.ts  # Contentlayer config
└── πŸ“ next.config.js          # configuration related to Next.js

Google Lighthouse performance statistics

image

Admin page

image

Admin page - editing

image

Environment Variables

To run this project, you will need to add the following environment variables to your .env file. They are needed for admin panel for editing your markdown files.

GITHUB_TOKEN = token with access to the content of your blog's repository
NEXTAUTH_SECRET = any secret 
NEXTAUTH_URL= your site's url
ADMIN_EMAIL = your email
ADMIN_PASSWORD= your password

Features

  • Static content generation based on markdown files (./posts folder)
  • Comments with Giscus
  • Code hightlighting
  • Automatic table of content generation
  • Admin panel that works via Github API
  • Mobile-friendly view
  • Projects page
  • Frontmatter support

Quick Start Guide

npm i

npm run dev

TODO

  1. Image upload
  2. Draft support

About

Blog built with NextJs 13, Contentlayer, Giscus and NextAuth. It uses Github API for admin section that allows managing markdown files rendered with Codemirror.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published