Merge pull request 'Feldkatalog konsolidieren: admin/config.template.yml als einzige Quelle (schließt #2)' (#4) from feature/feldkatalog-konsolidieren into main

Reviewed-on: #4
This commit is contained in:
2026-08-30 17:56:59 +02:00
7 changed files with 164 additions and 39 deletions
+6
View File
@@ -31,6 +31,12 @@ hugo/.hugo_build.lock
# is the file to maintain, not config.yml.
/admin/config.yml
# {name: label} for hugo/layouts/partials/aenderungssatz.html, generated
# from admin/config.template.yml's own field labels by
# scripts/generate-config.sh instead of maintained separately - see
# ableger/website#2.
/hugo/data/feldkatalog.json
# Generated by scripts/generate-vorlagen-manifest.rb, scans the docroot
# live (not just this folder) - see the Methoden-Set chapter on the project website.
/methoden-set/vorlagen/vorlagen-manifest.json
+3
View File
@@ -172,6 +172,7 @@ collections:
- label: "Kategorie"
name: "kategorie"
widget: "list"
required: false
hint: "Frei wählbar, z. B. Advent, Firmvorbereitung, Kennenlernen, Konfliktbearbeitung – bewusst kein festes Vokabular"
# VOKABULAR:kategorie:END
- label: "Lernchancen"
@@ -190,6 +191,7 @@ collections:
- label: "Initiator:innen"
name: "initiatoren"
widget: "list"
required: false
hint: "Wer die Methode ursprünglich entwickelt/eingebracht hat. Autor:innen einzelner Varianten stehen bei der jeweiligen Variante, siehe Collection \"Varianten\"."
summary: "{{fields.eintrag}}"
field: { label: "Initiator:in", name: "eintrag", widget: "string" }
@@ -328,6 +330,7 @@ collections:
- label: "Material"
name: "material"
widget: "list"
required: false
hint: "Was für diese Variante konkret gebraucht wird - andere Varianten derselben Methode können anderes Material brauchen"
summary: "{{fields.eintrag}}"
field: { label: "Material", name: "eintrag", widget: "string" }
+8 -12
View File
@@ -26,19 +26,15 @@
{{ $eintrag := .eintrag }}
{{ $titelHTML := .titelHTML | default "" }}
{{ $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"
}}
{{/* Labels from hugo/data/feldkatalog.json (generated by
scripts/generate-config.sh from admin/config.template.yml's own field
labels, see ableger/website#2) instead of a separate hardcoded dict
here - "or ... ." falls back to the raw field name for "inhalt" (the
one pseudo-field not present in the CMS config, added explicitly to
that generated file) and for any future field this partial doesn't
know about yet. */}}
{{ $felderLesbar := slice }}
{{ range $eintrag.felder }}{{ $felderLesbar = $felderLesbar | append (or (index $labels .) .) }}{{ end }}
{{ range $eintrag.felder }}{{ $felderLesbar = $felderLesbar | append (or (index hugo.Data.feldkatalog .) .) }}{{ end }}
{{ $liste := delimit $felderLesbar ", " }}
{{ $verb := "wurden" }}
{{ if eq (len $eintrag.felder) 1 }}{{ $verb = "wurde" }}{{ end }}
+46 -21
View File
@@ -38,6 +38,24 @@ sed -e "s|{{GITEA_DOMAIN}}|$GITEA_DOMAIN|g" \
"$HUGO_TEMPLATE" > "$HUGO_OUT"
echo "hugo.toml generiert: $HUGO_OUT"
# hugo/data/feldkatalog.json: {name: label} for hugo/layouts/partials/
# aenderungssatz.html, read from admin/config.template.yml via
# scripts/lib/feldkatalog.rb instead of a separate hardcoded label dict
# (see ableger/website#2). "inhalt" is added explicitly - it's not a real
# CMS field, but the pseudo-field scripts/generate-verlauf.rb emits for
# body/content changes.
ruby -I"$ROOT/scripts/lib" -rfeldkatalog -rjson -rfileutils -e '
katalog = {}
%w[methoden varianten].each do |collection|
Feldkatalog.felder(collection).each { |f| katalog[f[:name]] = f[:label] }
end
katalog["inhalt"] = "Inhalt"
out = File.join(ARGV[0], "hugo", "data", "feldkatalog.json")
FileUtils.mkdir_p(File.dirname(out))
File.write(out, JSON.pretty_generate(katalog))
' "$ROOT"
echo "feldkatalog.json generiert: $ROOT/hugo/data/feldkatalog.json"
# Export the vocabulary from ableger.yml (content repo) into a temporary
# directory with one text file per field (one allowed value per line) - this
# way the rest of the already-proven logic below (Python, reads from text
@@ -74,19 +92,26 @@ vokabular_dir = Path(vokabular_dir)
for feld in ("GITEA_DOMAIN", "METHODEN_REPO", "OAUTH_CLIENT_ID", "WEBSITE_DOMAIN"):
text = text.replace("{{" + feld + "}}", os.environ[feld])
def render_field(feld, indent, values):
lines = [f'{indent}- label: "{feld_labels.get(feld, feld)}"',
# "multiple" (single- vs. multi-select once a closed vocabulary applies)
# has no equivalent in the free-text fallback widgets ("list"/"string")
# below - it can't be read off the template like label/required can, it's
# genuinely new information, not a duplicate of anything already written
# elsewhere. ONLY this set determines multi-select - "more than one option
# to choose from" (len(values) > 1) is not the same as "multiple values
# selectable at once" and must not be conflated. Found live: "lizenz" has 3
# options, but exactly ONE applies per entry - an earlier condition
# "len(values) > 1 or feld in multi_fields" incorrectly set multiple: true
# as soon as a second vocabulary value was added. Decap then stored lizenz
# as a list ("- CC0") instead of a plain string as soon as someone made a
# selection in the CMS - unnoticed until a value was actually changed.
multi_fields = {"zielgruppe", "kategorie", "tags"}
def render_field(feld, indent, label, required_false, values):
lines = [f'{indent}- label: "{label}"',
f'{indent} name: "{feld}"',
f'{indent} widget: "select"']
# ONLY multi_fields determines multi-select - "more than one option to
# choose from" (len(values) > 1) is not the same as "multiple values
# selectable at once" and must not be conflated. Found live: "lizenz"
# has 3 options, but exactly ONE applies per entry - the earlier
# condition "len(values) > 1 or feld in multi_fields" incorrectly set
# multiple: true as soon as a second vocabulary value was added. Decap
# then stored lizenz as a list ("- CC0") instead of a plain string as
# soon as someone made a selection in the CMS - unnoticed until a value
# was actually changed.
if required_false:
lines.append(f'{indent} required: false')
if feld in multi_fields:
lines.append(f'{indent} multiple: true')
lines.append(f'{indent} options:')
@@ -94,14 +119,6 @@ def render_field(feld, indent, values):
lines.append(f'{indent} - "{wert}"')
return "\n".join(lines)
feld_labels = {
"zielgruppe": "Zielgruppe",
"kategorie": "Kategorie",
"lizenz": "Lizenz",
"tags": "Tags",
}
multi_fields = {"zielgruppe", "kategorie", "tags"}
def replace_block(match):
feld = match.group("feld")
indent = match.group("indent")
@@ -113,12 +130,20 @@ def replace_block(match):
values = [line.strip() for line in vokabular_file.read_text().splitlines() if line.strip()]
if not values:
return match.group(0)
block = render_field(feld, indent, values)
# label/required read straight out of the free-text fallback block
# instead of a second, separately maintained copy (see
# ableger/website#2) - a light regex is enough, no need for a full YAML
# parse of this one block.
fallback = match.group("body")
label_match = re.search(r'label:\s*"([^"]*)"', fallback)
label = label_match.group(1) if label_match else feld
required_false = re.search(r'required:\s*false\b', fallback) is not None
block = render_field(feld, indent, label, required_false, values)
return f"{indent}{start}\n{block}\n{indent}{end}"
pattern = re.compile(
r'(?P<indent>[ \t]*)(?P<start># VOKABULAR:(?P<feld>\w+):START)\n'
r'.*?\n'
r'(?P<body>.*?)\n'
r'[ \t]*(?P<end># VOKABULAR:(?P=feld):END)',
re.DOTALL,
)
+37
View File
@@ -0,0 +1,37 @@
# Reads the field catalog (which frontmatter fields "methoden"/"varianten"
# have, with which label, whether required) straight out of
# admin/config.template.yml instead of duplicating it - that file is
# already the richest, most densely commented source (widget type, hint
# text, pattern, required flag, list sub-fields, rationale comments for
# every design decision), so it stays the one hand-maintained source;
# everything else (scripts/validate.rb's required-field lists,
# hugo/data/feldkatalog.json for aenderungssatz.html) reads from here
# instead of keeping its own copy. See ableger/website#2.
require 'yaml'
module Feldkatalog
CONFIG_TEMPLATE = File.expand_path('../../admin/config.template.yml', __dir__)
# Ordered {name:, label:, required:} per collection ("methoden"/
# "varianten"), as YAML.safe_load sees it directly - the "{{VARIABLE}}"
# placeholders elsewhere in this file (backend/site_url) don't appear
# inside "fields:", so no preprocessing is needed before parsing.
# required is true unless the field explicitly sets "required: false"
# (Decap's own default). The "body" field (varianten' markdown widget,
# the actual document content) is excluded - it isn't a frontmatter
# field at all, "format: frontmatter" maps it to the document body
# instead.
def self.felder(collection)
daten = YAML.safe_load(File.read(CONFIG_TEMPLATE, encoding: 'UTF-8'))
eintrag = daten.fetch('collections').find { |c| c['name'] == collection }
raise "Feldkatalog: Collection #{collection.inspect} nicht gefunden" unless eintrag
eintrag.fetch('fields').reject { |f| f['name'] == 'body' }.map do |f|
{ name: f.fetch('name'), label: f.fetch('label'), required: f['required'] != false }
end
end
def self.pflichtfelder(collection)
felder(collection).select { |f| f[:required] }.map { |f| f[:name] }
end
end
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env ruby
# Compares the Feldkatalog table in the Manifest chapter (public docs site,
# separate repo - bildungselemente/website, content-ableger/ableger/docs/
# basis/manifest/index.md) against admin/config.template.yml (via
# lib/feldkatalog.rb) and warns about drift in field names or the
# Pflicht column. See ableger/website#2: that table already drifted once
# (kategorie/lernchancen/material) unnoticed.
#
# Manual, local check for now (not wired into CI/cron - the doc lives in a
# different repo's build) - a first step toward Regel 9 ("die Regeln sind
# maschinell prüfbar") for this specific table. Doesn't (and can't) check
# the free-text "Bedeutung" column or field order, only Feld/Pflicht.
#
# Usage: ruby scripts/pruefe-manifest-doku.rb /pfad/zu/manifest/index.md
require_relative 'lib/feldkatalog'
doc_path = ARGV[0] or abort 'Usage: pruefe-manifest-doku.rb <pfad-zu-manifest-index.md>'
text = File.read(doc_path, encoding: 'UTF-8')
# The doc has one table per collection, in this order, each row
# "| `feld` | Typ | ja/nein | Bedeutung |" - a heading line containing
# "**Variante** (`varianten/" marks the switch from the methoden- to the
# varianten-table (matching on the path prefix too, so this doesn't
# misfire on the unrelated "Methode vs. Variante" comparison table earlier
# in the same document, Teil C "Zwei Ebenen", which also mentions
# "**Variante**").
collections = %w[methoden varianten]
aktuell = 0
doc_pflicht = { 'methoden' => {}, 'varianten' => {} }
text.each_line do |zeile|
aktuell = 1 if zeile.include?('**Variante** (`varianten/')
next unless (m = zeile.match(/\A\|\s*`(?<feld>\w+)`\s*\|[^|]*\|\s*(?<pflicht>ja|nein)\s*\|/))
doc_pflicht[collections[aktuell]][m[:feld]] = m[:pflicht] == 'ja'
end
fehler = []
collections.each do |collection|
code_felder = Feldkatalog.felder(collection).to_h { |f| [f[:name], f[:required]] }
doc_felder = doc_pflicht[collection]
(code_felder.keys - doc_felder.keys).each { |f| fehler << "#{collection}: `#{f}` fehlt in der Doku-Tabelle" }
(doc_felder.keys - code_felder.keys).each { |f| fehler << "#{collection}: `#{f}` in der Doku-Tabelle, aber nicht in config.template.yml" }
(code_felder.keys & doc_felder.keys).each do |f|
next if code_felder[f] == doc_felder[f]
fehler << "#{collection}: `#{f}` Pflicht=#{code_felder[f] ? 'ja' : 'nein'} im Code, aber " \
"Pflicht=#{doc_felder[f] ? 'ja' : 'nein'} in der Doku-Tabelle"
end
end
if fehler.empty?
puts 'pruefe-manifest-doku: keine Abweichungen gefunden.'
else
puts 'pruefe-manifest-doku: Abweichungen gefunden:'
fehler.each { |f| puts " - #{f}" }
exit 1
end
+7 -6
View File
@@ -20,11 +20,12 @@
# in-progress state while creating an entry, not a violation (see Manifest
# Teil D).
#
# The required-field list below still duplicates admin/config.template.yml
# (website repo) - the vocabulary (Regel 9) has read from ableger.yml
# (content repo) since Schritt 5 (see the project website (background/analysis notes), Befund C),
# but the required-field list itself stays hardcoded here for now.
# The required-field list is read from admin/config.template.yml via
# lib/feldkatalog.rb (see ableger/website#2) instead of being duplicated
# here - the vocabulary (Regel 9) has read from ableger.yml (content repo)
# since Schritt 5 (see the project website (background/analysis notes), Befund C).
require_relative 'lib/frontmatter'
require_relative 'lib/feldkatalog'
require 'set'
root = File.expand_path('..', __dir__)
@@ -86,8 +87,8 @@ def vokabular(daten, name)
werte && Array(werte)
end
methoden_pflichtfelder = %w[kennung titel kurzbeschreibung verwendungsmoeglichkeit zielgruppe kompetenzbereich kategorie lernchancen initiatoren]
varianten_pflichtfelder = %w[veroeffentlicht methode kennung untertitel varianten_beschreibung dauer_minuten gruppengroesse_min gruppengroesse_max material lizenz autoren]
methoden_pflichtfelder = Feldkatalog.pflichtfelder('methoden')
varianten_pflichtfelder = Feldkatalog.pflichtfelder('varianten')
# --- Regel 14: protokoll_version, also the source of the vocabulary (Regel 9) ---
ableger_yml = File.join(content, 'ableger.yml')