diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..621b693 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +[*.{yml,yaml,json}] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 9b2d778..377aad7 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -6,6 +6,11 @@ on: - master pull_request: +# Serialise deploys per ref so two quick pushes cannot publish out of order. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + jobs: build: runs-on: ubuntu-latest @@ -15,11 +20,13 @@ jobs: with: submodules: recursive + # The image runs as a non-root user, so the mounted workspace must be + # writable. Keep HUGO_VERSION in sync with the Makefile. - name: Prepare workspace - run: chmod -R 777 . + run: chmod -R a+rwX . - name: Build - uses: docker://ghcr.io/gohugoio/hugo:latest + uses: docker://ghcr.io/gohugoio/hugo:v0.169.0 with: args: --minify @@ -37,7 +44,7 @@ jobs: strip_components: 1 - name: Send Telegram notification - if: always() + if: always() && github.event_name == 'push' uses: appleboy/telegram-action@v0.1.1 with: to: ${{ secrets.TELEGRAM_TO }} diff --git a/.gitignore b/.gitignore index a6c287a..b6afa69 100644 --- a/.gitignore +++ b/.gitignore @@ -395,6 +395,7 @@ FodyWeavers.xsd # Generated files by hugo /public/ /resources/_gen/ +/.hugo_build.lock # Executable may be added to repository hugo.exe diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..56a961d --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,90 @@ +# AGENTS.md + +Instructions for coding agents working on this repository. Keep them in sync +with the tooling; if a command below stops working, fix the command here first. + +## What this is + +The Hugo source of https://poweronoff.click, a German-language blog about agile +leadership and engineering management by Stan Nowogrudski. Theme: PaperMod +(git submodule). Deployed by Gitea Actions via `scp` on every push to `master`. + +## Commands + +Hugo is **not** installed on the host. Everything runs through the pinned +official Docker image (`HUGO_VERSION` in the `Makefile`, mirrored in +`.gitea/workflows/build.yml`). + +```sh +make build # production build into public/ (minified) +make serve # http://localhost:1313 with drafts, live reload +make check # build + generated-site assertions + internal link check +make new slug=my-post title="Mein Titel" # new draft page bundle +make clean # remove public/ and resources/ +make theme-update # bump the PaperMod submodule, then review + `make check` +``` + +`make check` is the definition of done for any change. It fails on placeholder +text, a leaked `localhost:1313` base URL, or broken internal links. + +## Layout + +| Path | Meaning | +| --- | --- | +| `config.yml` | All site config: params, menus, social icons, footer text | +| `content/posts//index.md` | Page bundle per post; cover image may live next to it | +| `content/*.md` | Standalone pages (about, impressum, data protection) | +| `layouts/shortcodes/obfuscate.html` | Base64 email obfuscation shortcode | +| `static/` | Files served at the site root (images, icons) | +| `themes/PaperMod` | Git submodule. **Never edit it.** Override from `layouts/` instead | +| `.gitea/workflows/build.yml` | Build, deploy, Telegram notification | + +Do not recreate `layouts/partials/footer.html`. It used to be a copy of the +theme footer, which silently stopped working when PaperMod moved to +`layouts/_partials/` (the legal links disappeared from the site). The +Datenschutz/Impressum links now come from `params.footer.text` in `config.yml`. + +## Writing rules + +- Posts are written in **German**; `howto-work-with-stan.md` is the English + exception. Do not translate existing content unless asked. +- Voice: first person, opinionated, practical. Do not add marketing filler. +- New posts start as `draft: true`. `buildDrafts` is off, so drafts never deploy. +- The paragraph before `` becomes the summary; make it meaningful. +- Front matter fields used by the theme: `title`, `date`, `draft`, `tags`, + `categories`, `ShowToc`, `ShowBreadCrumbs`, `cover.{image,alt,caption,relative}`. +- Cover images go in `static/` and are referenced by absolute path + (`/name.jpg`), even with `relative: true`. Use the unsplash/free license + credit in `caption` when the photo is not ours. +- Keep images out of `static/` unless they must be shared; prefer page bundles + with `resources.Get` for new artwork. Flag images larger than ~300 KB. +- Email addresses in content must use the `obfuscate` shortcode: + `{{< obfuscate >}}name@example.com{{< /obfuscate >}}`. +- Do not commit `public/`, `resources/`, `.hugo_build.lock`, or editor droppings. + +## Guardrails + +- **Never push to `master`** unless the user explicitly asks for a deploy. + A push to `master` builds and overwrites the live site. +- Do not touch `config.yml` secrets/analytics IDs, and never commit credentials. + CI secrets (`SSH_USERNAME`, `SSH_PASSWORD`, `SSH_PORT`, `TELEGRAM_TO`, + `TELEGRAM_TOKEN`) live in Gitea repository settings only. +- Deploy uses password `scp` and `rm: false`, so removed files are **not** + deleted on the server. If you delete a post or image, say so explicitly in + the PR/commit message so it can be cleaned up by hand. +- Theme deprecation warnings are upstream PaperMod noise + (`.Language.LanguageDirection`, `.Language.LanguageCode`). Do not try to fix + them in the submodule; wait for `make theme-update`. There are no other + acceptable Hugo warnings. + +## Known issues / backlog + +- `googleAnalytics` in `config.yml` is a dead Universal Analytics ID; a GA4 + `G-…` property is needed before analytics works again. +- `params.images` (Open Graph / Twitter cards) points at 32–60 px icons. Use a + 1200×630 image so shared links render properly. +- Two posts (`a-letter-to-my-younger-self`, `appreciation`) are drafts whose + bodies are still placeholders. They are not published, but do not "clean + them up" without asking — they are the author's unfinished work. +- Deploy would be safer with `rsync --delete` and SSH keys instead of a + password; out of scope unless asked. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e68a734 --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +# Local build helpers. The Hugo binary is not installed on the host: every +# target runs the pinned official image so local and CI builds match. +# +# Keep HUGO_VERSION in sync with the image tag in .gitea/workflows/build.yml. + +HUGO_VERSION ?= 0.169.0 +HUGO_IMAGE ?= ghcr.io/gohugoio/hugo:v$(HUGO_VERSION) +# --user keeps public/ owned by you instead of root (CI works around this with chmod). +DOCKER_RUN = docker run --rm \ + -u "$(shell id -u):$(shell id -g)" \ + -e HOME=/tmp \ + -e HUGO_CACHEDIR=/tmp/hugo-cache \ + -v "$(CURDIR)":/src \ + -w /src +HUGO = $(DOCKER_RUN) $(HUGO_IMAGE) + +.PHONY: help build serve check new clean theme-update + +help: ## Show this help + @grep -hE '^[a-z-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-14s %s\n", $$1, $$2}' + +build: ## Build the production site into public/ + @$(HUGO) --minify --gc --cleanDestinationDir + @echo "ok: public/" + +serve: ## Preview on http://localhost:1313 (drafts included) + @$(DOCKER_RUN) -p 1313:1313 $(HUGO_IMAGE) server --bind 0.0.0.0 --port 1313 --buildDrafts --navigateToChanged + +check: build ## Build, then verify the generated site + @test -f public/index.html + @test -f public/sitemap.xml + @test -f public/robots.txt + @test -f public/index.xml + @! grep -rl "Lorem Ipsum\|dolor sit amet" public --include='*.html' \ + || { echo "FAIL: placeholder text found in public/"; exit 1; } + @! grep -rl "localhost:1313" public --include='*.html' \ + || { echo "FAIL: dev baseURL leaked into public/"; exit 1; } + @python3 scripts/check-links.py public + @echo "ok: site checks passed" + +new: ## Create a draft post: make new slug=my-post title="My title" + @test -n "$(slug)" || { echo 'usage: make new slug=my-post [title="My title"]'; exit 2; } + @scripts/new-post.sh "$(slug)" "$(title)" + +clean: ## Remove build output and generated assets + @rm -rf public resources + @rm -f .hugo_build.lock + +theme-update: ## Move the PaperMod submodule to its latest master commit + @git submodule update --remote themes/PaperMod + @git diff --submodule=log themes/PaperMod + @echo "Review the theme changelog, run 'make check', then commit the gitlink." diff --git a/README.md b/README.md index 4be2df2..1f2f2cb 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,15 @@ Source code for my homepage and my blog poweronoff.click based on [hugo](https://gohugo.io) [![Build Status](https://code.poweronoff.click/steam/poweronoff.click/actions/workflows/build.yml/badge.svg?branch=master)](https://code.poweronoff.click/steam/poweronoff.click/actions?workflow=build.yml) + +## Working on it + +Hugo runs in Docker, nothing to install locally: + +```sh +make serve # preview on http://localhost:1313 +make check # build + link/content checks +make new slug=my-post title="Mein Titel" +``` + +See [AGENTS.md](AGENTS.md) for the repo map, writing conventions and guardrails. diff --git a/config.yml b/config.yml index 6a4523a..d3be140 100644 --- a/config.yml +++ b/config.yml @@ -10,6 +10,8 @@ buildFuture: false buildExpired: false enableEmoji: true +# TODO(analytics): Universal Analytics (UA-*) stopped collecting data on 2023-07-01. +# Create a GA4 property and replace this with its G-XXXXXXXXXX measurement ID (or drop the line). googleAnalytics: UA-179789773-1 minify: @@ -74,6 +76,11 @@ params: - name: twitter url: "https://twitter.com/djsteamson" + footer: + # Rendered by PaperMod's own footer partial. Keeping this here instead of forking + # layouts/_partials/footer.html means theme updates keep working. + text: "[Datenschutzerklärung](/data_protection/) · [Impressum](/impressum/)" + cover: hidden: false # hide everywhere but not in structured data hiddenInList: false # hide on list pages and home @@ -106,6 +113,6 @@ menu: weight: 25 - identifier: howto-work-with-me name: How to work with me - url: /howto-work-with-stan + url: /howto-work-with-stan/ weight: 30 diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html deleted file mode 100644 index 1b75a56..0000000 --- a/layouts/partials/footer.html +++ /dev/null @@ -1,135 +0,0 @@ -{{- if not (.Param "hideFooter") }} - -{{- end }} - -{{- if (not .Site.Params.disableScrollToTop) }} - - - - - -{{- end }} - -{{- partial "extend_footer.html" . }} - - - -{{- if (not .Site.Params.disableScrollToTop) }} - -{{- end }} - -{{- if (not .Site.Params.disableThemeToggle) }} - -{{- end }} - -{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (.Param "ShowCodeCopyButtons")) }} - -{{- end }} diff --git a/scripts/check-links.py b/scripts/check-links.py new file mode 100755 index 0000000..469bdc0 --- /dev/null +++ b/scripts/check-links.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +"""Fail if the generated site links to local paths that were not built. + +Only internal hrefs/srcs that start with "/" are checked and only files under +the given public/ directory are considered. External URLs are ignored. +""" + +import html.parser +import os +import sys +import urllib.parse + + +class LinkParser(html.parser.HTMLParser): + def __init__(self): + super().__init__() + self.links = [] + + def handle_starttag(self, tag, attrs): + for name, value in attrs: + if name in ("href", "src") and value: + self.links.append(value) + + +def resolves(root, path): + def exists(p): + return os.path.exists(os.path.join(root, p)) + + if exists(path): + return True + if exists(os.path.join(path, "index.html")): + return True + if not path.endswith("/") and exists(path + ".html"): + return True + return False + + +def main(): + if len(sys.argv) != 2: + print("usage: check-links.py ", file=sys.stderr) + return 2 + + root = sys.argv[1] + failures = [] + + for dirpath, _, filenames in os.walk(root): + for filename in filenames: + if not filename.endswith(".html"): + continue + page = os.path.join(dirpath, filename) + rel_page = os.path.relpath(page, root) + with open(page, encoding="utf-8", errors="replace") as handle: + parser = LinkParser() + parser.feed(handle.read()) + + for link in parser.links: + if not link.startswith("/") or link.startswith("//"): + continue + path = urllib.parse.unquote(urllib.parse.urlsplit(link).path) + if not resolves(root, path.lstrip("/")): + failures.append(f"{rel_page}: {link}") + + if failures: + print("broken internal links:", file=sys.stderr) + for failure in sorted(set(failures)): + print(" " + failure, file=sys.stderr) + return 1 + + print(f"ok: internal links resolve ({len(os.listdir(root))} top-level entries)") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/new-post.sh b/scripts/new-post.sh new file mode 100755 index 0000000..e44ff1d --- /dev/null +++ b/scripts/new-post.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# Create a Hugo page bundle under content/posts//index.md as a draft. +# Usage: scripts/new-post.sh ["Title"] +set -euo pipefail + +slug="${1:-}" +title="${2:-}" + +if [[ -z "$slug" ]]; then + echo "usage: $(basename "$0") [\"Title\"]" >&2 + exit 2 +fi + +if [[ ! "$slug" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then + echo "slug must be lowercase kebab-case (letters, digits, single hyphens): $slug" >&2 + exit 2 +fi + +dir="content/posts/$slug" +if [[ -e "$dir" ]]; then + echo "already exists: $dir" >&2 + exit 1 +fi + +if [[ -z "$title" ]]; then + title="$(printf '%s' "$slug" | tr '-' ' ')" +fi +title="${title//\"/\\\"}" + +# RFC3339 with a colon in the offset, e.g. 2025-11-06T09:57:00+01:00 +now="$(date +%Y-%m-%dT%H:%M:%S%z | sed -E 's/([+-][0-9]{2})([0-9]{2})$/\1:\2/')" + +mkdir -p "$dir" +cat > "$dir/index.md" < + +TODO: body. +EOF + +echo "created $dir/index.md (draft)" diff --git a/static/56A78726-AD52-427A-908F-7107F42EB7CB_1_105_c.jpeg b/static/56A78726-AD52-427A-908F-7107F42EB7CB_1_105_c.jpeg deleted file mode 100644 index 6d6b3e2..0000000 Binary files a/static/56A78726-AD52-427A-908F-7107F42EB7CB_1_105_c.jpeg and /dev/null differ diff --git a/static/me.jpeg b/static/me.jpeg deleted file mode 100644 index 6d6b3e2..0000000 Binary files a/static/me.jpeg and /dev/null differ