Categorygithub.com/ZacxDev/go-static-site
modulepackage
0.9.2
Repository: https://github.com/zacxdev/go-static-site.git
Documentation: pkg.go.dev

# README

Go Static Site

The one-file declarative static site generator. Define your site routes/sources in a single manifest file.

Introduction

Go Static Site is designed with simplicity in mind - we believe configuring your static site should be as straightforward as describing it. By using a single YAML manifest file, you can define your entire site structure, including routes, templates, JavaScript bundles, and translations. No more memorizing magic directory layouts or file naming patterns.

Features

  • πŸ—ΊοΈ Single file configuration
  • 🌐 i18n enabled by default
  • πŸ“¦ JavaScript transpilation and injection using checksums to enable heavy caching without risk of serving stale code
  • πŸ–ŒοΈ Template rendering with Plush
  • Partial injection for simple modular and reusable component templates
  • ✍️ Markdown support with frontmatter
  • πŸ—ΊοΈ Automatic sitemap generation
  • πŸ”„ Development server with hot reloading (coming soon)
  • πŸ“± Static site generation for production

Stack

  • Go: Core runtime and static site generation
  • Plush: Template engine for HTML templates
  • esbuild: JavaScript bundling and optimization
  • Markdown: Content authoring with frontmatter support
  • Gorilla Mux: Routing
  • YAML: Configuration format

Quick Start

  1. Install the generator:
go install github.com/yourusername/go-static-site@latest
  1. Create a manifest.yaml file in your project root:
origin: https://mysite.com

partials:
  header:
    source: "templates/partials/header.plush.html"
    template_type: "PLUSH"

routes:
  - path: /
    source: pages/home.plush.html
    template_type: PLUSH
    partial_deps:
      - header
    javascript_deps:
      - main

  - path: /blog/:slug
    source: pages/blog/[slug]/[lang].md
    template_type: MARKDOWN
    partial_deps:
      - header
    javascript_deps:
      - blog

javascript:
  main:
    source: src/main.ts
    out_dir: static/js
  blog:
    source: src/blog.ts
    out_dir: static/js

translations:
  - code: en
    source: translations/en.yaml
    source_type: YAML
  - code: es
    source: translations/es.yaml
    source_type: YAML

not_found_page_source: pages/404.plush.html
  1. Start the development server:
go-static-site serve
  1. Build for production:
go-static-site build

Project Structure

your-project/
β”œβ”€β”€ manifest.yaml
β”œβ”€β”€ pages/
β”‚   β”œβ”€β”€ home.plush.html
β”‚   β”œβ”€β”€ blog/
β”‚   β”‚   └── my-post/
β”‚   β”‚       β”œβ”€β”€ en.md
β”‚   β”‚       └── es.md
β”‚   └── 404.plush.html
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.ts
β”‚   └── blog.ts
β”œβ”€β”€ static/
β”‚   └── css/
β”‚       └── styles.css
β”œβ”€β”€ templates/
β”‚   └── layouts/
β”‚       └── base.plush.html
└── translations/
    β”œβ”€β”€ en.yaml
    └── es.yaml

Configuration

Routes

Routes can be static or dynamic:

  • Static routes: /about, /contact
  • Dynamic routes: /blog/:slug, /products/:id
  • Language-specific routes are automatically generated based on your translations

JavaScript Bundling

  • Uses esbuild for blazing fast bundling
  • Automatic file hashing for cache busting
  • Bundles are specified in the manifest and can be referenced in routes

Templates

Two template types are supported:

  • PLUSH: HTML templates with Go's Plush templating engine
  • MARKDOWN: Markdown files with YAML frontmatter

Translations

  • YAML-based translation files
  • Automatic language route generation
  • Translation helper available in templates: <%= text("key") %>

Markdown Frontmatter

title: My Blog Post
description: A great post about things
---
# Content starts here

Your markdown content...

Development

# Start development server
go-static-site serve -p 9010

# Build static site
go-static-site build

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author