Overview
Ever since I read this article Writing a Static Blog Generator in Go by @zupzup a few years ago, I've been wanting to do the same.
After not doing it for a few years just like a lot of things in my life rn, I finally gave it a try.
What I Created
Here is the core package(SSG)
K-Sato1995 / go-simple-ssg
Minimalistic SSG(Static Site Generator) in Go
What this is
Yet another SSG in Go. It's not intended to replace any existing SSGs. I created it as a learning exercise and really enjoyed the process.๐ค
Heavily inspired by this blog post(Writing a Static Blog Generator in Go) by @zupzup.
In case you are wondering how to use this, check out the Initialization process below.
Initialization
Install the cli.
go install github.com/K-Sato1995/go-simple-ssg/simple-ssg-cli@latest
run
simple-ssg-cli init
would create a new project that looks somethi ng like this.
./
โโโ contents/ (Stores markdown files)
โโโ templates/ (Stores template html files and style files)
โโโ generated/ (Stores generated files)
โโโ go.mod
โโโ go.sum
โโโ main.go
cd your project
and just run
go run main.go
You should be able to see the site running on http://localhost:3001
Todo
-
CLI To run generating static contents based on the config file
- put all the code in oneโฆ
and here is a static site I created using the ssg.
https://go-simple-ssg.vercel.app
Structure
The core package mainly consists of two parts
- Generator: Generate static files based on Markdown and Templates(HTML) files.
- CLI: Allows anyone to bootstrap a project.
The core packages looks like this
./
โโโ parser/ (Part that parses Markdown into HTML)
โ โโโ mdToHTML.go
โ โโโ parseMetaData.go
โโโ builder/ (Part that generates static files based on the given md and templates)
โ โโโ bundleCss.go
โ โโโ copyStaticFiles.go
โ โโโ generateDetail.go
โ โโโ generateList.go
โโโ simple-ssg-cli/ (CLI that allows anyone to bootstrap a project)
โโ example/
โโโ config/ (Part that makes the project custamizable for users)
โโโ engine.go
To use it, install the simple-ssg-cli
and execute the init
command.
$ go install github.com/K-Sato1995/go-simple-ssg/simple-ssg-cli@latest
$ simple-ssg-cli init
Doing this will create a new project with the following structure:
./
โโโ contents/ (Stores markdown files)
โโโ templates/ (Stores template html files and style files)
โโโ generated/ (Stores generated files)
โโโ go.mod
โโโ go.sum
โโโ main.go
Lastly, move to the newly created project and run it to build static contents and stuff.
$ cd your_project && go run main.go
Random Thoughts
Doing this made me appreciate existing SSGs like Hugo and Next.js even more๐๐
Top comments (7)
cool work dude
Thanks for mentioning Zas!
it doesn't work
could u share the error msgs and stuff?
im just joking i just wanted to be the first viewer and commenter
dude....๐
thanks for commenting anyways!
Iโm grateful for the effort you put into these posts, they are always a great read. BUY NCR Ranger Armor Coat
Some comments may only be visible to logged-in visitors. Sign in to view all comments.