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
Simple SSG in Golang
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 (5)
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!
Some comments may only be visible to logged-in visitors. Sign in to view all comments.