# mkblog

A Hugo-style static site generator in Go for markdown posts with optional YAML front matter.

## Features

- Markdown content from `content/*.md`
- Additional site content assets from:
  - `content/files/*` (listed on home/blog views and published at `/files/*`)
  - `content/casts/*` (for asciinema cast files published at `/casts/*`)
  - `content/snippets/*` (source files used by the `source` shortcode)
- Optional YAML front matter (`title`, `date`, `tags`, `draft`, `hidden`, `slug`)
- Asciinema shortcode support:
  - `{{< asciinema "/casts/demo.cast" theme="solarized-dark" loop=true >}}`
  - default embed theme is `none` (transparent background + inherited font)
- Source shortcode support:
  - `{{< source "/snippets/demo.go" lines="12-34" lang=go title="watch loop" hl="18,23-24" >}}`
- Pretty URLs (`/blog/slug/`)
- Generated pages:
  - Home (`/`)
  - Post pages (`/blog/<slug>/`)
  - Tag pages (`/tags/<tag>/`)
  - Archive pages (`/archives/<year>/` and `/archives/<year>/<month>/`)
- Theme support at build time (`themes/<name>/layouts|partials|assets`)
- `build` and `serve` commands

## Quick start

```bash
go run ./cmd/mkblog build
go run ./cmd/mkblog serve --watch
```

Then open `http://localhost:1313`.

To build the `mkblog` executable from the repository root (Go 1.22 or newer):

```sh
go build -o mkblog ./cmd/mkblog
./mkblog --version
```

The local build reports `dev` as its version. Use `./mkblog build` to generate
the site, or `./mkblog build --theme unix-machina` to use UnixMachina.

## Commands

```bash
mkblog --version
mkblog build [--config config.yaml] [--content content] [--static static] [--themes themes] [--theme default] [--out public] [--include-drafts] [--include-future]
mkblog serve [same flags as build] [--port 1313] [--watch]
```

## Deployment

For a quick SSH + `rsync --delete` deployment flow, see [DEPLOY.md](/usr/home/code/ssg/DEPLOY.md).

For the longer nginx-oriented walkthrough, see [BLOG_DEPLOY.md](/usr/home/code/ssg/BLOG_DEPLOY.md).

Release bundles built by [scripts/build-release.sh](/usr/home/code/ssg/scripts/build-release.sh) include only the `default` theme. A separate theme pack is also generated at `releases/themes/<version>/themes-<version>.tar.xz`.

## Notes on Asciinema embeds

The shortcode injects local player assets from `static/assets/` (`/assets/asciinema-player.css`, `/assets/asciinema-player.min.js`, and `/assets/asciinema-init.js`) and points the player to your cast path (for example `/casts/demo.cast`).

If no theme is specified, the embed uses `theme="none"` (transparent background and inherited font).

Cast source files should be placed in `content/casts/`.

## Terminal and copyable code blocks

Add `input` or `output` after the language in a fenced code block:

````md
```sh input
curl -I https://example.com
```

```text output
HTTP/2 200
```
````

`input` adds an **Input** label and a Copy button; `output` adds an **Output** label.
Use `go copy` (or another language followed by `copy`) for a copyable code block
without a terminal label. Copying preserves the contents and line breaks; omit
shell prompts from input blocks. Ordinary fences keep their existing rendering.

To syntax-check every `sh input` block in a Markdown file, run from the repository
root (requires Go and `sh`):

```sh
go run ./scripts/check-sh-input.go content/applix-full.md
```

Example output (the block count depends on the file):

```text
content/applix-full.md: checked 72 sh input blocks; 0 failed
```

The checker runs `sh -n` on each block without executing its commands. It reports
the Markdown filename and line for failures, continues through all input blocks,
and exits unsuccessfully if any fail. It skips output blocks and ordinary `sh`
blocks. Quoted scripts passed to `sh -c`, SSH, or written inside here-documents
remain strings to the outer shell and are not separately checked.

UnixMachina (`unix-machina`) provides the distinct backgrounds, attached labels,
and Copy buttons beside the labels. Other themes render labels but need their own styles
and copy script. Copy works with JavaScript in browsers that permit clipboard
access; if both clipboard methods fail, the button reports the failure.

## Notes on Source embeds

The `source` shortcode reads files from `content/snippets/` and renders syntax-highlighted HTML at build time.

- `{{< source "/snippets/demo.go" >}}` embeds the whole file
- `{{< source "/snippets/demo.go" lines="12-34" >}}` embeds an inclusive range
- `lang=...` overrides lexer detection, `title=...` sets the caption, and `hl="18,23-24"` highlights original file line numbers inside the displayed block

## Content layout

```text
content/
  *.md
  files/
    resume.txt
  casts/
    demo.cast
  snippets/
    demo.go
```

`static/` is still copied as pass-through assets. Legacy `static/files` and `static/casts` are supported as a fallback but are deprecated in favor of `content/files` and `content/casts`.

## Authoring posts

`mkblog` loads posts from `content/**/*.md`.

The canonical format is Markdown with YAML front matter:

```md
---
title: "Hello World"
date: 2026-02-25
tags:
  - freebsd
  - cli
slug: hello-world
draft: false
hidden: false
---

Sample post body.
```

When front matter is present, `title` and `date` are required. `tags`, `slug`, `draft`, and `hidden` are optional.

Plain Markdown files without a front matter block also work. In that case `mkblog` infers metadata during the build:

- `title` from the filename
- `slug` from the filename
- `date` from the file modification time
- `tags` as an empty list
- `draft` as `false`
- `hidden` as `false`

Example: `content/ssh-notes.md` builds as a post titled `Ssh Notes` at `/blog/ssh-notes/`.

`mkblog build` does not rewrite source files to inject front matter. If a file starts with a front matter block, it is validated strictly. Malformed YAML or invalid explicit dates still fail the build.

Use `draft: true` for in-progress posts that should be excluded from normal builds unless `--include-drafts` is used.

Use `hidden: true` for posts that should still get a direct URL, but should not appear on the home page, blog index, tag pages, or archive pages.

## Default theme style

The bundled `default` theme renders pages as a CRT-style terminal:

- command-output inspired listings (`ls -l`/`cat` style)
- scanline + flicker effects with reduced-motion fallback
- inline SVG file/folder icons (no large Nerd Font download)

## Unix Machina theme

The `unix-machina` theme combines a paper-and-terminal layout with vintage
computer imagery. It self-hosts Courier Prime for article text and VT323 for
terminal-style headings, and includes responsive layouts for every page type
generated by mkblog.

Build with it using:

```bash
go run ./cmd/mkblog build --theme unix-machina
```

## Web Null theme

The `web-null` theme is a dense editorial interpretation of `/dev/null`: cream
paper, a black system masthead, orange interrupt markers, olive punch-card
panels, and responsive article, topic, and archive indexes. Courier Prime and
VT323 are self-hosted with the theme.

Build with it using:

```bash
go run ./cmd/mkblog build --theme web-null
```

## Blog Interrupt theme

The `blog-interrupt` theme presents the site as an `/etc/interrupt` field
manual: a persistent black interrupt console, cream document canvas,
measurement ruler, red signal markers, and olive terminal/punch-card panels.
It includes responsive layouts for every page type generated by mkblog.

Build with it using:

```bash
go run ./cmd/mkblog build --theme blog-interrupt
```

## Teletype theme variants

Six paper-based teletype variants are available for evaluation:

- `teletype-clean` (lightest paper/ink effects)
- `teletype-balanced` (moderate paper texture and ink bleed)
- `teletype-worn` (strongest vintage/worn-paper look)
- `teletype-css` (Special Elite + CSS-only teletype styling)
- `teletype-jitter` (Special Elite + per-character JS jitter/ink variation)
- `tt-jit-wrap` (teletype-jitter styling with word-safe wrapping)

Build examples:

```bash
go run ./cmd/mkblog build --theme teletype-clean
go run ./cmd/mkblog build --theme teletype-balanced
go run ./cmd/mkblog build --theme teletype-worn
go run ./cmd/mkblog build --theme teletype-css
go run ./cmd/mkblog build --theme teletype-jitter
go run ./cmd/mkblog build --theme tt-jit-wrap
```

## Amber CRT theme variants

Six amber/CRT-inspired variants are available:

- `amber-balanced` (subtle glow/scanlines, tuned for readability)
- `amber-strong` (heavier retro glow/scanlines/vignette)
- `amber-new` (strong CRT with CSS + scanlines + noise + curvature)
- `amber-new-max` (maximum retro with heavier glow/flicker/noise and stronger distortion)
- `amber` (amber-new-max styling without jitter/flicker motion)
- `legacy` (Tron: Legacy-inspired cyan/blue neon CRT variant)

Build examples:

```bash
go run ./cmd/mkblog build --theme amber-balanced
go run ./cmd/mkblog build --theme amber-strong
go run ./cmd/mkblog build --theme amber-new
go run ./cmd/mkblog build --theme amber-new-max
go run ./cmd/mkblog build --theme amber
go run ./cmd/mkblog build --theme legacy
```

## Solaris dtterm theme variants

Two Solaris CDE/Motif-inspired dtterm variants are available:

- `dtterm-solaris` (high-fidelity CDE/Motif chrome and palette)
- `dtterm-solaris-max` (stronger Motif bevel/chrome treatment)

Build examples:

```bash
go run ./cmd/mkblog build --theme dtterm-solaris
go run ./cmd/mkblog build --theme dtterm-solaris-max
```
