diff --git a/.gitignore b/.gitignore index 4eb0a41..2c0bdde 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ hugo/.hugo_build.lock /_content/ # Creation/modification dates, computed from the git history of _content/ -# instead of maintained, see scripts/generate-dates.sh +# instead of maintained, see scripts/generate-verlauf.rb /hugo/data/methoden.json /hugo/data/varianten.json diff --git a/hugo/content-static/aenderungen/_index.md b/hugo/content-static/aenderungen/_index.md new file mode 100644 index 0000000..c33c348 --- /dev/null +++ b/hugo/content-static/aenderungen/_index.md @@ -0,0 +1,3 @@ +--- +title: "Änderungsverlauf" +--- diff --git a/hugo/layouts/_default/baseof.html b/hugo/layouts/_default/baseof.html index 05edaf2..ddecda5 100644 --- a/hugo/layouts/_default/baseof.html +++ b/hugo/layouts/_default/baseof.html @@ -181,11 +181,13 @@ {{ with .Site.Params.datenschutz_url }}
  • Datenschutz
  • {{ else }}
  • Datenschutz
  • {{ end }}
  • Redaktion
  • Status
  • +
  • Änderungsverlauf
  • + diff --git a/hugo/layouts/_default/single.html b/hugo/layouts/_default/single.html index 1f5003b..fba12f1 100644 --- a/hugo/layouts/_default/single.html +++ b/hugo/layouts/_default/single.html @@ -36,5 +36,7 @@ {{ end }} + + {{ partial "aenderungshistorie.html" . }} {{ end }} diff --git a/hugo/layouts/aenderungen/list.html b/hugo/layouts/aenderungen/list.html new file mode 100644 index 0000000..e48c544 --- /dev/null +++ b/hugo/layouts/aenderungen/list.html @@ -0,0 +1,170 @@ +{{ define "main" }} +{{/* One row per raw change event (methods and variants both contribute + their own, un-merged verlauf entries here - unlike + partials/aenderungshistorie.html on individual method pages, this page + deliberately does NOT fold a method's variants into its own rows, see + the plan discussion: "jede Änderung eine Textzeile" across the whole + site). Zielgruppe/Kompetenzbereich/Kategorie/Tags live on the method, + not the variant (see the Manifest field catalog) - a variant's row + therefore borrows these from its owning method via + methode-fuer-variante.html, same as steckbrief-box.html does. */}} +{{ $zeilen := slice }} + +{{ range where site.RegularPages "Section" "" }} + {{ $seite := . }} + {{ $spanne := partialCached "variantenspanne.html" $seite $seite.RelPermalink }} + {{ $titelHTML := printf "%s" $seite.RelPermalink ($seite.Params.titel | default $seite.Title) }} + {{ with index hugo.Data.methoden $seite.File.ContentBaseName }} + {{ range .verlauf }} + {{ $zeilen = $zeilen | append (dict + "eintrag" . "titelHTML" $titelHTML + "zielgruppe" ($seite.Params.zielgruppe | default slice) + "kompetenzbereich" ($seite.Params.kompetenzbereich | default slice) + "kategorie" ($seite.Params.kategorie | default slice) + "tags" ($seite.Params.tags | default slice) + "lizenz" $spanne.lizenzen + "dauerMin" $spanne.dauerMin "dauerMax" $spanne.dauerMax "dauerSeen" $spanne.dauerSeen + "groesseMin" $spanne.groesseMin "groesseMax" $spanne.groesseMax "groesseSeen" $spanne.groesseSeen + ) }} + {{ end }} + {{ end }} +{{ end }} + +{{ range where site.RegularPages "Section" "varianten" }} + {{ $variante := . }} + {{ $methode := partial "methode-fuer-variante.html" $variante }} + {{ $label := $variante.Params.untertitel | default $variante.Title }} + {{ $zielgruppe := slice }}{{ $kompetenzbereich := slice }}{{ $kategorie := slice }}{{ $tags := slice }} + {{ with $methode }} + {{ $label = printf "%s – %s" (.Params.titel | default .Title) $label }} + {{ $zielgruppe = .Params.zielgruppe | default slice }} + {{ $kompetenzbereich = .Params.kompetenzbereich | default slice }} + {{ $kategorie = .Params.kategorie | default slice }} + {{ $tags = .Params.tags | default slice }} + {{ end }} + {{ $titelHTML := printf "%s" $variante.RelPermalink $label }} + {{ $dauerSeen := isset $variante.Params "dauer_minuten" }} + {{ $groesseSeen := isset $variante.Params "gruppengroesse_min" }} + {{ $lizenz := slice }}{{ with $variante.Params.lizenz }}{{ $lizenz = slice . }}{{ end }} + {{ with index hugo.Data.varianten $variante.File.ContentBaseName }} + {{ range .verlauf }} + {{ $zeilen = $zeilen | append (dict + "eintrag" . "titelHTML" $titelHTML + "zielgruppe" $zielgruppe "kompetenzbereich" $kompetenzbereich "kategorie" $kategorie "tags" $tags + "lizenz" $lizenz + "dauerMin" $variante.Params.dauer_minuten "dauerMax" $variante.Params.dauer_minuten "dauerSeen" $dauerSeen + "groesseMin" $variante.Params.gruppengroesse_min "groesseMax" $variante.Params.gruppengroesse_max "groesseSeen" $groesseSeen + ) }} + {{ end }} + {{ end }} +{{ end }} + +{{ $zeilen = sort $zeilen "eintrag.datum" "desc" }} + +{{/* Bounds for the filter panel, same aggregation idea as index.html + (there per method, here across all rows already collected above). */}} +{{ $lizenzen := slice }} +{{ $dauerMin := 0 }}{{ $dauerMax := 0 }}{{ $dauerSeen := false }} +{{ $groesseMin := 0 }}{{ $groesseMax := 0 }}{{ $groesseSeen := false }} +{{ range $zeilen }} + {{ $lizenzen = $lizenzen | append .lizenz }} + {{ if .dauerSeen }} + {{ if $dauerSeen }} + {{ if lt .dauerMin $dauerMin }}{{ $dauerMin = .dauerMin }}{{ end }} + {{ if gt .dauerMax $dauerMax }}{{ $dauerMax = .dauerMax }}{{ end }} + {{ else }}{{ $dauerMin = .dauerMin }}{{ $dauerMax = .dauerMax }}{{ $dauerSeen = true }}{{ end }} + {{ end }} + {{ if .groesseSeen }} + {{ if $groesseSeen }} + {{ if lt .groesseMin $groesseMin }}{{ $groesseMin = .groesseMin }}{{ end }} + {{ if gt .groesseMax $groesseMax }}{{ $groesseMax = .groesseMax }}{{ end }} + {{ else }}{{ $groesseMin = .groesseMin }}{{ $groesseMax = .groesseMax }}{{ $groesseSeen = true }}{{ end }} + {{ end }} +{{ end }} +{{ $lizenzen = $lizenzen | uniq | sort }} + +
    +

    +
    + Filter +
    +
    + Zielgruppe + {{ range $term, $pages := .Site.Taxonomies.zielgruppe }} + + {{ end }} +
    +
    + Kompetenzbereich + {{ range $term, $pages := .Site.Taxonomies.kompetenzbereich }} + + {{ end }} +
    +
    + Kategorie + {{ range $term, $pages := .Site.Taxonomies.kategorie }} + + {{ end }} +
    + {{ if gt (len $lizenzen) 1 }} +
    + Lizenz + {{ range $lizenzen }}{{ end }} +
    + {{ end }} + {{ if $dauerSeen }} +
    +
    Dauer: {{ $dauerMin }}–{{ $dauerMax }} Min.
    +
    +
    + + +
    +
    + {{ end }} + {{ if $groesseSeen }} +
    +
    Gruppengröße: {{ $groesseMin }}–{{ $groesseMax }}
    +
    +
    + + +
    +
    + {{ end }} + {{/* Date bounds are computed client-side from the rendered rows' + data-datum (see static/js/aenderungen.js) instead of here - a + plain date string isn't a usable value, and + the JS already needs to parse every row's date for filtering + anyway, so bounds fall out of that same pass for free. */}} +
    +
    Zeitraum: –
    +
    +
    + + +
    +
    + +
    +
    +
    + + + +{{ end }} diff --git a/hugo/layouts/partials/aenderungshistorie.html b/hugo/layouts/partials/aenderungshistorie.html new file mode 100644 index 0000000..9d8eefb --- /dev/null +++ b/hugo/layouts/partials/aenderungshistorie.html @@ -0,0 +1,42 @@ +{{/* Renders the change history section for a Methode or Variante page, + called with that page as context. For a Variante: just its own + "verlauf" (hugo.Data.varianten). For a Methode: its own "verlauf" + merged with every belonging Variante's "verlauf" (via + varianten-fuer-methode.html, same lookup as variantenspanne.html), + each foreign entry tagged with the variant's untertitel so + aenderungssatz.html can append "(Variante ...)" - sorted newest first + across the merged set. No title/link needed in the sentences here + (aenderungssatz.html's titelHTML stays ""): the entity itself already + is the page we're on. */}} +{{ $p := . }} +{{ $eintraege := slice }} + +{{ if eq $p.Section "varianten" }} + {{ with index hugo.Data.varianten $p.File.ContentBaseName }} + {{ range .verlauf }}{{ $eintraege = $eintraege | append . }}{{ end }} + {{ end }} +{{ else }} + {{ with index hugo.Data.methoden $p.File.ContentBaseName }} + {{ range .verlauf }}{{ $eintraege = $eintraege | append . }}{{ end }} + {{ end }} + {{ range partial "varianten-fuer-methode.html" $p }} + {{ $variante := . }} + {{ with index hugo.Data.varianten $variante.File.ContentBaseName }} + {{ range .verlauf }} + {{ $eintraege = $eintraege | append (merge . (dict "variante" ($variante.Params.untertitel | default $variante.Title))) }} + {{ end }} + {{ end }} + {{ end }} + {{ $eintraege = sort $eintraege "datum" "desc" }} +{{ end }} + +{{ with $eintraege }} +
    +

    Änderungsverlauf

    + +
    +{{ end }} diff --git a/hugo/layouts/partials/aenderungssatz.html b/hugo/layouts/partials/aenderungssatz.html new file mode 100644 index 0000000..d497ecd --- /dev/null +++ b/hugo/layouts/partials/aenderungssatz.html @@ -0,0 +1,55 @@ +{{/* Renders one change-history entry as a full German sentence, per the + pattern " von wurde(n) am durch + geändert." (or " wurde am durch angelegt." for a + creation entry). Called with a dict: + eintrag - one entry from hugo.Data.methoden/varianten's "verlauf" + array (datum/autor/typ/felder), optionally with an extra + "variante" key (the variant's untertitel) when merged in + from a variant into a method's aggregated history, see + aenderungshistorie.html. + titelHTML - pre-rendered link HTML to the method/variant ("Titel"), or "" when this is rendered + directly on the entity's own page (no need to name the + subject there, see aenderungshistorie.html). + Returns a safe HTML string (the sentence, no wrapping element - callers + decide how to wrap it, see aenderungshistorie.html and + layouts/aenderungen/list.html). */}} +{{ $eintrag := .eintrag }} +{{ $titelHTML := .titelHTML | default "" }} +{{ $autor := $eintrag.autor | htmlEscape }} + +{{ $labels := dict + "kennung" "Kennung" "titel" "Titel" "kurzbeschreibung" "Kurzbeschreibung" + "verwendungsmoeglichkeit" "Verwendungsmöglichkeit" "zielgruppe" "Zielgruppe" + "kompetenzbereich" "Kompetenzbereich" "kategorie" "Kategorie" "tags" "Tags" + "lernchancen" "Lernchancen" "herkunft" "Herkunft" "initiatoren" "Initiator:innen" + "methode" "Methode" "untertitel" "Untertitel" "varianten_beschreibung" "Varianten-Beschreibung" + "veroeffentlicht" "Veröffentlicht" "dauer_minuten" "Dauer" + "gruppengroesse_min" "Gruppengröße (mindestens)" "gruppengroesse_max" "Gruppengröße (höchstens)" + "material" "Material" "autoren" "Autor:innen" "lizenz" "Lizenz" "quellen" "Quellen" + "anhaenge" "Anhänge" "inhalt" "Inhalt" +}} + +{{ $datum := $eintrag.datum | time.AsTime | dateFormat "02.01.2006" }} +{{ $suffix := "" }} +{{ with $eintrag.variante }}{{ $suffix = printf " (Variante „%s“)" (. | htmlEscape) }}{{ end }} + +{{ $satz := "" }} +{{ if eq $eintrag.typ "erstellt" }} + {{ $subjekt := $titelHTML }} + {{ if eq $subjekt "" }}{{ $subjekt = "Seite" }}{{ end }} + {{ $satz = printf "%s wurde am %s durch %s angelegt%s." $subjekt $datum $autor $suffix }} +{{ else }} + {{ $felderLesbar := slice }} + {{ range $eintrag.felder }}{{ $felderLesbar = $felderLesbar | append (or (index $labels .) .) }}{{ end }} + {{ $liste := delimit $felderLesbar ", " }} + {{ $verb := "wurden" }} + {{ if eq (len $eintrag.felder) 1 }}{{ $verb = "wurde" }}{{ end }} + {{ if eq $titelHTML "" }} + {{ $satz = printf "%s %s am %s durch %s geändert%s." $liste $verb $datum $autor $suffix }} + {{ else }} + {{ $satz = printf "%s von %s %s am %s durch %s geändert%s." $liste $titelHTML $verb $datum $autor $suffix }} + {{ end }} +{{ end }} +{{ $safe := $satz | safeHTML }} +{{ return $safe }} diff --git a/hugo/layouts/varianten/single.html b/hugo/layouts/varianten/single.html index 3290e3e..d9f167f 100644 --- a/hugo/layouts/varianten/single.html +++ b/hugo/layouts/varianten/single.html @@ -38,5 +38,7 @@ {{ end }} {{ end }} + + {{ partial "aenderungshistorie.html" $variante }} {{ end }} diff --git a/hugo/static/css/style.css b/hugo/static/css/style.css index dabd91d..9061056 100644 --- a/hugo/static/css/style.css +++ b/hugo/static/css/style.css @@ -452,6 +452,14 @@ a:focus-visible, button:focus-visible { outline: 3px solid var(--color-accent); .method__section { margin: 1.75rem 0; } .method__section h2 { font-size: 1.1rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.25rem; } +/* Log-style change history, both the per-page section (single.html, + varianten/single.html) and the /aenderungen/ overview page - deliberately + plain text rows, no card layout (see aenderungen/list.html). */ +.aenderungsliste { list-style: none; margin: 0; padding: 0; } +.aenderungszeile { padding: 0.6rem 0; border-bottom: 1px solid var(--color-border); font-size: 0.925rem; } +.aenderungszeile:last-child { border-bottom: none; } +.aenderungszeile a { font-weight: 600; } + .method__meta dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 0.75rem 1.5rem; } .method__meta dt { color: var(--color-muted); font-size: 0.8rem; margin: 0; } .method__meta dd { margin: 0; font-weight: 500; } diff --git a/hugo/static/js/aenderungen.js b/hugo/static/js/aenderungen.js new file mode 100644 index 0000000..9789b96 --- /dev/null +++ b/hugo/static/js/aenderungen.js @@ -0,0 +1,193 @@ +(function () { + "use strict"; + + // Same checkbox-facet / dual-range-slider approach as static/js/filter.js + // (homepage), applied to
  • log rows instead of .method-card elements - + // kept as a separate file rather than merged into filter.js, since the + // DOM (#aenderungsliste vs. #method-grid) and the extra date-range facet + // differ enough that sharing would need more branching than duplication. + var list = document.getElementById("aenderungsliste"); + if (!list) return; // Not on the Änderungsverlauf page + + var rows = Array.prototype.slice.call(list.querySelectorAll(".aenderungszeile")); + var resultCount = document.getElementById("result-count"); + var noResults = document.getElementById("no-results"); + var resetButton = document.getElementById("filter-reset"); + var filterPanel = document.getElementById("filter-panel"); + var checkboxes = Array.prototype.slice.call(document.querySelectorAll("[data-facet]")); + var rangeGroups = Array.prototype.slice.call(document.querySelectorAll("[data-range-facet]")); + + function checkboxesFor(facet) { + return checkboxes.filter(function (el) { return el.dataset.facet === facet; }); + } + + function selectedValues(facet) { + return checkboxesFor(facet) + .filter(function (el) { return el.checked; }) + .map(function (el) { return el.value.toLowerCase(); }); + } + + function rowValues(row, key) { + var raw = row.dataset[key] || ""; + return raw ? raw.split("|").map(function (v) { return v.toLowerCase(); }) : []; + } + + // --- Dual range sliders (Dauer, Gruppengröße, Datum) --------------------- + + function rangeState(group) { + return { + group: group, + minInput: group.querySelector("[data-range-min]"), + maxInput: group.querySelector("[data-range-max]"), + isDate: group.hasAttribute("data-datum-range"), + }; + } + + function bounds(state) { + return [parseFloat(state.group.dataset.min), parseFloat(state.group.dataset.max)]; + } + + function formatValue(state, value) { + if (!state.isDate) return value; + return new Date(value).toLocaleDateString("de-DE"); + } + + function updateRangeVisuals(state) { + var b = bounds(state); + var min = parseFloat(state.minInput.value); + var max = parseFloat(state.maxInput.value); + var span = (b[1] - b[0]) || 1; + + var outMin = state.group.querySelector("[data-range-output-min]"); + var outMax = state.group.querySelector("[data-range-output-max]"); + if (outMin) outMin.textContent = formatValue(state, min); + if (outMax) outMax.textContent = formatValue(state, max); + + var fill = state.group.querySelector("[data-range-fill]"); + if (fill) { + var left = ((min - b[0]) / span) * 100; + var right = ((max - b[0]) / span) * 100; + fill.style.left = left + "%"; + fill.style.width = Math.max(0, right - left) + "%"; + } + } + + // The date range's own min/max/value aren't known until the rendered + // rows' data-datum attributes are read (see list.html - a plain date + // string can't be a native bound) - computed here + // once from what's already in the DOM, same pass that filtering needs + // anyway. + var dateBoundsMs = null; + rangeGroups.forEach(function (group) { + if (!group.hasAttribute("data-datum-range")) return; + var timestamps = rows + .map(function (row) { return Date.parse(row.dataset.datum); }) + .filter(function (t) { return !isNaN(t); }); + if (!timestamps.length) return; + dateBoundsMs = [Math.min.apply(null, timestamps), Math.max.apply(null, timestamps)]; + group.dataset.min = dateBoundsMs[0]; + group.dataset.max = dateBoundsMs[1]; + var minInput = group.querySelector("[data-range-min]"); + var maxInput = group.querySelector("[data-range-max]"); + minInput.min = maxInput.min = dateBoundsMs[0]; + minInput.max = maxInput.max = dateBoundsMs[1]; + minInput.value = dateBoundsMs[0]; + maxInput.value = dateBoundsMs[1]; + }); + + var rangeStates = rangeGroups.map(function (group) { + var state = rangeState(group); + + function onMinInput() { + if (parseFloat(state.minInput.value) > parseFloat(state.maxInput.value)) { + state.minInput.value = state.maxInput.value; + } + updateRangeVisuals(state); + applyFilters(); + } + function onMaxInput() { + if (parseFloat(state.maxInput.value) < parseFloat(state.minInput.value)) { + state.maxInput.value = state.minInput.value; + } + updateRangeVisuals(state); + applyFilters(); + } + + state.minInput.addEventListener("input", onMinInput); + state.maxInput.addEventListener("input", onMaxInput); + updateRangeVisuals(state); + return state; + }); + + function rangeIsNarrowed(state) { + var b = bounds(state); + return parseFloat(state.minInput.value) > b[0] || parseFloat(state.maxInput.value) < b[1]; + } + + // --- Filtering ------------------------------------------------------- + + function matchesFacets(row) { + var groups = { zielgruppe: 1, kompetenzbereich: 1, kategorie: 1, lizenz: 1 }; + for (var facet in groups) { + var selected = selectedValues(facet); + if (selected.length === 0) continue; + var values = rowValues(row, facet); + if (!values.some(function (v) { return selected.indexOf(v) !== -1; })) return false; + } + return true; + } + + function matchesRanges(row) { + for (var i = 0; i < rangeStates.length; i++) { + var state = rangeStates[i]; + if (!rangeIsNarrowed(state)) continue; + var facet = state.group.dataset.rangeFacet; + var fMin = parseFloat(state.minInput.value); + var fMax = parseFloat(state.maxInput.value); + + if (facet === "datum") { + var d = Date.parse(row.dataset.datum); + if (isNaN(d) || d < fMin || d > fMax) return false; + } else if (facet === "dauer") { + var dMinRaw = row.dataset.dauerMin, dMaxRaw = row.dataset.dauerMax; + if (dMinRaw === "" || dMaxRaw === "") return false; + if (parseFloat(dMaxRaw) < fMin || parseFloat(dMinRaw) > fMax) return false; + } else if (facet === "groesse") { + var gMinRaw = row.dataset.gruppengroesseMin, gMaxRaw = row.dataset.gruppengroesseMax; + if (gMinRaw === "" || gMaxRaw === "") return false; + if (parseFloat(gMaxRaw) < fMin || parseFloat(gMinRaw) > fMax) return false; + } + } + return true; + } + + function applyFilters() { + var visible = 0; + rows.forEach(function (row) { + var match = matchesFacets(row) && matchesRanges(row); + row.hidden = !match; + if (match) visible++; + }); + if (resultCount) resultCount.textContent = visible + " von " + rows.length + " Änderungen"; + if (noResults) noResults.hidden = visible !== 0; + } + + if (resetButton) { + resetButton.addEventListener("click", function () { + checkboxes.forEach(function (el) { el.checked = false; }); + rangeStates.forEach(function (state) { + var b = bounds(state); + state.minInput.value = b[0]; + state.maxInput.value = b[1]; + updateRangeVisuals(state); + }); + applyFilters(); + }); + } + + checkboxes.forEach(function (el) { + el.addEventListener("change", applyFilters); + }); + + applyFilters(); +})(); diff --git a/scripts/generate-dates.sh b/scripts/generate-dates.sh deleted file mode 100755 index 3dcd384..0000000 --- a/scripts/generate-dates.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -# Generates hugo/data/methoden.json and hugo/data/varianten.json: creation -# and last-modified date per method/variant, determined from the git -# history of _content/. -# -# Hugo's enableGitInfo/.GitInfo only looks for git history in the repo that -# contains the Hugo page root (ableger_demo/ableger) - but _content/ is a -# separate git repo (ableger_demo/ableger_methoden) mounted via -# module.mounts and is not recognized there (.GitInfo stays nil, no error, -# just silently empty). This has affected "last modified" ever since the -# repo split, unnoticed, because Hugo doesn't warn about it. -# For "created" there would be no Hugo-native equivalent anyway, see -# https://github.com/gohugoio/hugo/issues/11810 (open). -# -# So both dates are read here uniformly from git history ourselves, instead -# of relying on .GitInfo. Recomputed fresh on every sync rather than -# maintained (see sync-methoden.sh, which calls this script automatically) - -# no manual date field, git stays the single source of truth. -set -euo pipefail - -ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -CONTENT_REPO="$ROOT/_content" - -dates_for_path() { - local relpath="$1" - local history erstellt geaendert - # One "git log --follow" call instead of two: with the full (not -1) - # history for this path, the first line (newest) is "geaendert" and the - # last line (oldest, following through renames) is "erstellt" - no need - # for a second, separately filtered/unfollowed call to get either. - history="$(git -C "$CONTENT_REPO" log --follow --format=%aI -- "$relpath")" - geaendert="$(echo "$history" | head -1)" - erstellt="$(echo "$history" | tail -1)" - [ -n "$erstellt" ] && [ -n "$geaendert" ] || return 1 - jq -n --arg erstellt "$erstellt" --arg geaendert "$geaendert" '{erstellt: $erstellt, geaendert: $geaendert}' -} - -# Both methods and variants are one folder per entry with content in -# index.md (Hugo page bundle) - variants ever since attachments moved from -# the method to the respective variant, see admin/config.template.yml. -generate_bundle_dates() { - local name="$1" - local dir="$CONTENT_REPO/$name" - local out="$ROOT/hugo/data/$name.json" - mkdir -p "$(dirname "$out")" - local entries="{}" - if [ -d "$dir" ]; then - for entry_dir in "$dir"/*/; do - local slug - slug="$(basename "$entry_dir")" - [ -f "$entry_dir/index.md" ] || continue - local dates - dates="$(dates_for_path "$name/$slug/index.md")" || continue - entries="$(echo "$entries" | jq --arg slug "$slug" --argjson dates "$dates" '. + {($slug): $dates}')" - done - fi - echo "$entries" > "$out" - echo "$name.json aktualisiert: $(echo "$entries" | jq 'length') Einträge" -} - -generate_bundle_dates "methoden" -generate_bundle_dates "varianten" diff --git a/scripts/generate-verlauf.rb b/scripts/generate-verlauf.rb new file mode 100755 index 0000000..1b02ff9 --- /dev/null +++ b/scripts/generate-verlauf.rb @@ -0,0 +1,113 @@ +#!/usr/bin/env ruby +# Generates hugo/data/methoden.json and hugo/data/varianten.json: creation +# date, last-modified date, and a full chronological change history +# (verlauf, newest first) per method/variant - all derived from the git +# history of _content/. Replaces generate-dates.sh (same underlying reason +# for reading git history ourselves instead of relying on Hugo's +# enableGitInfo/.GitInfo, which doesn't see _content/'s separate git repo - +# see the installation guide on the project website. No Hugo-native +# "created" equivalent exists anyway, https://github.com/gohugoio/hugo/issues/11810). +# +# Recomputed fresh on every sync rather than maintained (see +# sync-methoden.sh, which calls this script automatically) - no manual +# date/history field, git stays the single source of truth (Manifest +# Prinzip 8). +require_relative 'lib/frontmatter' +require 'json' + +ROOT = File.expand_path('..', __dir__) +CONTENT_REPO = File.join(ROOT, '_content') + +# One combined "git log" call per file instead of one per commit - %x09 is +# a literal tab byte as field separator, safe against contents containing +# regular spaces/dashes. --name-only together with --follow gives the +# historical path at each commit (needed to read that commit's content via +# "git show", exactly the technique scripts/validate.rb's +# vorherige_kennung already uses for the single most recent rename). +# Oldest commit first (git log's default is newest-first, hence "reverse"). +def commits_for(relpath, content_dir) + raw = `cd #{content_dir} && git log --follow --format='%H%x09%an%x09%aI' --name-only -- #{relpath}` + zeilen = raw.split("\n").reject(&:empty?) + commits = [] + i = 0 + while i < zeilen.length + hash, autor, datum = zeilen[i].split("\t") + pfad = zeilen[i + 1] + commits << { hash: hash, autor: autor, datum: datum, pfad: pfad } + i += 2 + end + commits.reverse +end + +def inhalt_bei(hash, pfad, content_dir) + text = `cd #{content_dir} && git show #{hash}:#{pfad} 2>/dev/null`.force_encoding('UTF-8') + return nil if text.empty? + Frontmatter.parse(text) +end + +# Compares frontmatter key-by-key (simple value inequality, including for +# list-type fields - a reordered-but-unchanged list would show as +# "changed", accepted as a rare, harmless false positive rather than +# building element-level list diffing for this) plus the document body, for +# variants where the actual content (Vorbereitung/Ablauf/Hintergründe) +# lives. +def geaenderte_felder(vorher_fm, vorher_body, jetzt_fm, jetzt_body) + felder = (vorher_fm.keys | jetzt_fm.keys).select { |k| vorher_fm[k] != jetzt_fm[k] } + felder << 'inhalt' if vorher_body != jetzt_body + felder +end + +def verlauf_fuer(relpath, content_dir) + commits = commits_for(relpath, content_dir) + return nil if commits.empty? + + eintraege = [] + vorher_fm = nil + vorher_body = nil + + commits.each do |c| + parsed = inhalt_bei(c[:hash], c[:pfad], content_dir) + next unless parsed + fm, body = parsed + + if vorher_fm.nil? + eintraege << { datum: c[:datum], autor: c[:autor], typ: 'erstellt', felder: [] } + else + felder = geaenderte_felder(vorher_fm, vorher_body, fm, body) + eintraege << { datum: c[:datum], autor: c[:autor], typ: 'geaendert', felder: felder } unless felder.empty? + end + + vorher_fm = fm + vorher_body = body + end + + return nil if eintraege.empty? + + eintraege = eintraege.reverse # newest first + { erstellt: eintraege.last[:datum], geaendert: eintraege.first[:datum], verlauf: eintraege } +end + +# Both methods and variants are one folder per entry with content in +# index.md (Hugo page bundle). +def generate_bundle_verlauf(name) + dir = File.join(CONTENT_REPO, name) + out = File.join(ROOT, 'hugo', 'data', "#{name}.json") + require 'fileutils' + FileUtils.mkdir_p(File.dirname(out)) + + entries = {} + if Dir.exist?(dir) + Dir.glob(File.join(dir, '*')).select { |d| File.directory?(d) }.each do |entry_dir| + slug = File.basename(entry_dir) + next unless File.exist?(File.join(entry_dir, 'index.md')) + daten = verlauf_fuer("#{name}/#{slug}/index.md", CONTENT_REPO) + entries[slug] = daten if daten + end + end + + File.write(out, JSON.pretty_generate(entries)) + puts "#{name}.json aktualisiert: #{entries.length} Einträge" +end + +generate_bundle_verlauf('methoden') +generate_bundle_verlauf('varianten') diff --git a/scripts/generate-version-info.sh b/scripts/generate-version-info.sh index f6f6273..7301508 100755 --- a/scripts/generate-version-info.sh +++ b/scripts/generate-version-info.sh @@ -8,7 +8,7 @@ # marker - once a fork's own commits land, this reflects those, not the # template's history. # -# Unlike hugo/data/methoden.json/varianten.json (generate-dates.sh), this +# Unlike hugo/data/methoden.json/varianten.json (generate-verlauf.rb), this # reads the website repo's own git history directly - no separate # module.mounts repo involved, Hugo's enableGitInfo/.GitInfo would actually # work here, but a plain "git log" call keeps this consistent with the diff --git a/scripts/sync-methoden.sh b/scripts/sync-methoden.sh index 19b4602..88dbac3 100755 --- a/scripts/sync-methoden.sh +++ b/scripts/sync-methoden.sh @@ -51,8 +51,9 @@ echo "_content/ aktuell: $(git -C "$TARGET" rev-parse --short HEAD)" # warnings (exit code 0) deliberately do not block. ruby "$(dirname "${BASH_SOURCE[0]}")/validate.rb" -# Recompute creation dates from the freshly fetched history. -"$(dirname "${BASH_SOURCE[0]}")/generate-dates.sh" +# Recompute creation/change dates and the change history from the freshly +# fetched history. +ruby "$(dirname "${BASH_SOURCE[0]}")/generate-verlauf.rb" # Translate the variants' "veroeffentlicht" field (positive polarity) into # Hugo's native draft field - must run before compute-methoden- diff --git a/scripts/validate.rb b/scripts/validate.rb index 5ae22ce..88473f1 100755 --- a/scripts/validate.rb +++ b/scripts/validate.rb @@ -235,7 +235,7 @@ Dir.glob(File.join(varianten_dir, '*')).select { |d| File.directory?(d) }.each d # Regel 12 (no derived fields) %w[draft erstellt geaendert].each do |feld| - warnungen << "#{rel_path}: enthält abgeleitetes Feld '#{feld}' - das übernimmt apply-veroeffentlicht.rb/generate-dates.sh selbst (Regel 12)" if fm.key?(feld) + warnungen << "#{rel_path}: enthält abgeleitetes Feld '#{feld}' - das übernimmt apply-veroeffentlicht.rb/generate-verlauf.rb selbst (Regel 12)" if fm.key?(feld) end # Regel 8 (required fields)