From d9227e15f3185b5affa0fcc9814c87cebf570eb6 Mon Sep 17 00:00:00 2001 From: yann64 Date: Sun, 11 Oct 2026 20:13:17 +0200 Subject: [PATCH] Add news posts with banner summaries on the home page Posts live in content/post/; the five latest are summarised on the home page. Builds for check/deploy go to build/ so they do not collide with a running hugo server writing to public/. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YDRjtmAiNpo5mK5N3d7QwZ --- .gitignore | 1 + Makefile | 25 ++++++++++++++----------- README.md | 17 +++++++++++++++-- archetypes/post.md | 11 +++++++++++ assets/css/main.css | 18 ++++++++++++++++++ content/post/_index.md | 3 +++ hugo.toml | 8 ++++++++ layouts/_partials/banner.html | 14 ++++++++++++++ layouts/_partials/post-summary.html | 11 +++++++++++ layouts/home.html | 15 +++++++++++++-- layouts/post/section.html | 7 +++++++ layouts/post/single.html | 13 +++++++++++++ 12 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 archetypes/post.md create mode 100644 content/post/_index.md create mode 100644 layouts/_partials/banner.html create mode 100644 layouts/_partials/post-summary.html create mode 100644 layouts/post/section.html create mode 100644 layouts/post/single.html diff --git a/.gitignore b/.gitignore index 3b3c8b1d..4ca67841 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /public/ +/build/ /resources/_gen/ .hugo_build.lock __pycache__/ diff --git a/Makefile b/Makefile index 64708394..fc6dda12 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,31 @@ OC ?= ../oc +# not public/: a running `hugo server` renders there, with its live-reload script +BUILD ?= build # test server: the web share of barbel-lescar, mounted from the file manager (smb://barbel-lescar/web) DEPLOY_DIR ?= /run/user/$(shell id -u)/gvfs/smb-share:server=barbel-lescar,share=web/oldcomputers DEPLOY_URL ?= https://barbel.synology.me/oldcomputers/ -.PHONY: content build check serve deploy +.PHONY: content build check serve deploy post content: ## regenerate content/ and static/media/ from the extraction repo python3 $(OC)/scripts/05_hugo.py --target $(CURDIR) -build: ## build the site into public/ - rm -rf public - hugo --panicOnWarning --minify +build: ## build the site into $(BUILD)/ + rm -rf $(BUILD) + hugo --panicOnWarning --minify -d $(BUILD) check: build ## build, then verify every internal link and image - python3 tools/check_links.py public + python3 tools/check_links.py $(BUILD) serve: ## local preview on http://localhost:1313 hugo server -deploy: ## build, check, and copy public/ to DEPLOY_DIR (served at DEPLOY_URL) - rm -rf public - hugo --panicOnWarning --minify - python3 tools/check_links.py public +post: ## new post: make post NAME=my-title, then edit content/post/-my-title.md + @test -n "$(NAME)" || { echo "usage: make post NAME=my-title"; exit 1; } + hugo new content post/$(shell date +%F)-$(NAME).md + +deploy: check ## build, check, and copy $(BUILD)/ to DEPLOY_DIR (served at DEPLOY_URL) @test -d "$(dir $(DEPLOY_DIR))" || { echo "share not mounted: $(dir $(DEPLOY_DIR))"; exit 1; } mkdir -p "$(DEPLOY_DIR)" - rsync -r --size-only --info=stats1 public/media/ "$(DEPLOY_DIR)/media/" - rsync -rc --delete --exclude=/media/ --info=stats1 public/ "$(DEPLOY_DIR)/" + rsync -r --size-only --info=stats1 $(BUILD)/media/ "$(DEPLOY_DIR)/media/" + rsync -rc --delete --exclude=/media/ --info=stats1 $(BUILD)/ "$(DEPLOY_DIR)/" diff --git a/README.md b/README.md index 260bf553..7c200c9d 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,29 @@ Static rebuild of old-computers.com with [Hugo](https://gohugo.io/) (0.158 or ne | `content/{museum,machine-tabs,companies,software,history,magazine,fun}/` | generated, replaced on every `make content` | | `static/media/` | generated (copied images and documents) | | `data/slugs.json` | generated, keeps URLs stable between runs — do not delete | +| `content/post/` | written by hand: news posts, see below | | `content/_index.md`, `layouts/`, `assets/`, `hugo.toml`, `tools/` | written by hand | -| `public/` | build output, not versioned | +| `build/`, `public/` | build output (`make build`, `hugo server`), not versioned | Content pages are Markdown with YAML front matter and can be corrected by hand, but a later `make content` overwrites them: lasting fixes belong in the extraction repository. +## Posts + + make post NAME=my-title + +creates `content/post/-my-title.md` (any `.md` file in `content/post/` is a post). The +date comes from the file name unless `date:` is set; `author:` is optional. For a banner, put an +image under `static/media/` and set `banner: /media/....jpg`. Write the text in Markdown and +remove `draft: true` to publish. The five most recent posts appear on the home page with their +banner, date, author and summary (`summary:` in the front matter, or the text before +``, or the first lines); all posts are listed under News. Posts are never touched by +`make content`. + ## Usage make content # regenerate from ../oc (OC=path to use another location) - make build # build into public/ + make build # build into build/ make check # build + verify every internal link and image make serve # preview on http://localhost:1313 make deploy # build and copy to the test server (share must be mounted; see DEPLOY_DIR/DEPLOY_URL) diff --git a/archetypes/post.md b/archetypes/post.md new file mode 100644 index 00000000..b6d07f1c --- /dev/null +++ b/archetypes/post.md @@ -0,0 +1,11 @@ +--- +title: "{{ replace (replaceRE `^\d{4}-\d{2}-\d{2}-` "" .File.ContentBaseName) "-" " " | title }}" +author: +# banner: image shown on the home page and at the top of the post, e.g. /media/posts/my-image.jpg +# (file stored under static/media/) +banner: +# summary: optional; without it the text before (or the first lines) is used +draft: true +--- + +Write the post here. diff --git a/assets/css/main.css b/assets/css/main.css index afea00b5..1253aa73 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -111,3 +111,21 @@ table { border-collapse: collapse; } .comments li { margin-bottom: 12px; overflow-wrap: anywhere; } .comments .meta { margin: 0 0 6px; font-size: 0.9rem; } .prev-next { display: flex; justify-content: space-between; gap: 16px; margin-top: 24px; } + +.posts { display: grid; gap: 16px; } +.post-summary { + display: grid; + grid-template-columns: minmax(0, 280px) 1fr; + gap: 16px; + background: var(--panel); + border: 1px solid var(--line); + border-radius: 4px; + padding: 12px; +} +.post-summary:not(:has(.banner)) { grid-template-columns: 1fr; } +.post-summary .banner img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 2px; } +.post-summary h3 { margin: 0 0 2px; font-size: 1.15rem; } +.post-summary .meta { margin: 0 0 8px; font-size: 0.85rem; } +.post-summary p:last-child { margin-bottom: 0; } +.post-banner { display: block; width: 100%; max-height: 420px; object-fit: cover; margin: 0 0 16px; border-radius: 4px; } +@media (max-width: 600px) { .post-summary { grid-template-columns: 1fr; } } diff --git a/content/post/_index.md b/content/post/_index.md new file mode 100644 index 00000000..569ac4c7 --- /dev/null +++ b/content/post/_index.md @@ -0,0 +1,3 @@ +--- +title: News +--- diff --git a/hugo.toml b/hugo.toml index e4996447..66f5a25c 100644 --- a/hugo.toml +++ b/hugo.toml @@ -6,6 +6,10 @@ disableKinds = ["rss", "sitemap"] # pages keep working when the site is served from a sub-directory relativeURLs = true +# a post named 2026-10-11-my-title.md gets its date from the file name (and the URL /post/my-title/) +[frontmatter] + date = ["date", ":filename", ":default"] + [params] description = "The Old-Computers.com museum of computers, consoles and pongs, rebuilt from the Wayback Machine archive." @@ -21,6 +25,10 @@ relativeURLs = true collection = "collections" [menus] + [[menus.main]] + name = "News" + pageRef = "/post" + weight = 5 [[menus.main]] name = "Museum" pageRef = "/museum" diff --git a/layouts/_partials/banner.html b/layouts/_partials/banner.html new file mode 100644 index 00000000..0c7266a7 --- /dev/null +++ b/layouts/_partials/banner.html @@ -0,0 +1,14 @@ +{{/* dict "page" "width" -> URL of the post banner, resized when it is a bundle image */}} +{{- $url := "" -}} +{{- with .page.Params.banner -}} + {{- with $.page.Resources.GetMatch . -}} + {{- if and (eq .MediaType.MainType "image") (ne .MediaType.SubType "svg") -}} + {{- $url = (.Resize (printf "%dx" $.width)).RelPermalink -}} + {{- else -}} + {{- $url = .RelPermalink -}} + {{- end -}} + {{- else -}} + {{- $url = . -}} + {{- end -}} +{{- end -}} +{{- return $url -}} diff --git a/layouts/_partials/post-summary.html b/layouts/_partials/post-summary.html new file mode 100644 index 00000000..c4849f94 --- /dev/null +++ b/layouts/_partials/post-summary.html @@ -0,0 +1,11 @@ +
+ {{ with partial "banner.html" (dict "page" . "width" 640) }} + + {{ end }} +
+

{{ .Title }}

+

{{ if not .Date.IsZero }}{{ end }}{{ with .Params.author }}{{ if not $.Date.IsZero }} · {{ end }}{{ . }}{{ end }}

+
{{ .Summary }}
+ {{ if .Truncated }}

Read more →

{{ end }} +
+
diff --git a/layouts/home.html b/layouts/home.html index 41a38f70..8684a5cc 100644 --- a/layouts/home.html +++ b/layouts/home.html @@ -1,14 +1,25 @@ {{ define "main" }}

{{ .Title }}

{{ .Content }}
+{{ with site.GetPage "/post" }} +{{ $posts := .RegularPages.ByDate.Reverse }} +{{ if $posts }} +

{{ .Title }}

+
+ {{ range first 5 $posts }}{{ partial "post-summary.html" . }}{{ end }} +
+{{ if gt (len $posts) 5 }}

All posts →

{{ end }} +{{ end }} +{{ end }} +

Sections

{{ range site.Menus.main }} - {{ with .Page }} + {{ with .Page }}{{ if ne .Section "post" }} {{ .Title }} {{ len .RegularPages }} {{ if eq (len .RegularPages) 1 }}page{{ else }}pages{{ end }} - {{ end }} + {{ end }}{{ end }} {{ end }}

Browse the museum

diff --git a/layouts/post/section.html b/layouts/post/section.html new file mode 100644 index 00000000..9a55e564 --- /dev/null +++ b/layouts/post/section.html @@ -0,0 +1,7 @@ +{{ define "main" }} +

{{ .Title }}

+
{{ .Content }}
+
+ {{ range .RegularPages.ByDate.Reverse }}{{ partial "post-summary.html" . }}{{ end }} +
+{{ end }} diff --git a/layouts/post/single.html b/layouts/post/single.html new file mode 100644 index 00000000..bcef5c46 --- /dev/null +++ b/layouts/post/single.html @@ -0,0 +1,13 @@ +{{ define "main" }} +
+

{{ .Parent.Title }}

+

{{ .Title }}

+

{{ if not .Date.IsZero }}{{ end }}{{ with .Params.author }}{{ if not $.Date.IsZero }} · {{ end }}{{ . }}{{ end }}

+ {{ with partial "banner.html" (dict "page" . "width" 1000) }}{{ end }} +
{{ .Content }}
+ +
+{{ end }}