Giter Site home page Giter Site logo

pavlovtech / nextblog Goto Github PK

View Code? Open in Web Editor NEW
54.0 1.0 1.0 17.72 MB

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

Home Page: https://alexpavlov.dev

TypeScript 69.92% JavaScript 13.55% CSS 16.54%
contentlayer markdown nextjs

nextblog's Introduction

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

nextblog's People

Contributors

pavlovtech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

onmybob

nextblog's Issues

Not an issue

Just suggesting in case you don't know, but you can use redirects in next.config.js instead of putting a redirect in your root page.tsx.

About Next redirects

const nextConfig = {
    redirects: async () => {
        return [
            {
                source: '/',
                destination: '/blog',
                permanent: true,
            },
        ];
     },
    ...
}

Great job by the way

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.