Feldkatalog konsolidieren: admin/config.template.yml als einzige Quelle
Der Feldkatalog (Feldname/Label/Pflicht) war an mehreren Stellen von Hand dupliziert - entdeckt beim Bau der Änderungshistorie, siehe ableger/website#2. admin/config.template.yml bleibt die eine, dicht kommentierte Quelle (Widget-Typ, Hinweistext, Pattern, Pflicht-Status, Begründungen); ein neuer kleiner Parser (scripts/lib/feldkatalog.rb) liest daraus, alle anderen Stellen lesen jetzt aus diesem Parser statt eigener Kopien: - scripts/validate.rb: methoden_pflichtfelder/varianten_pflichtfelder kommen jetzt aus Feldkatalog.pflichtfelder statt aus zwei hartcodierten Arrays. - hugo/data/feldkatalog.json (neu generiert in scripts/generate-config.sh): {name: label}-Map für hugo/layouts/partials/aenderungssatz.html, dessen komplettes hartcodiertes $labels-Dict entfällt. Volle CMS-Labels erscheinen jetzt auch im Fließtext-Satz (z. B. "Dauer (Minuten)" statt bisher "Dauer"). - scripts/generate-config.sh's VOKABULAR-Renderer (fünfte, bisher nicht in ableger/website#2 erfasste Duplizierungsstelle): label/required werden jetzt aus dem ursprünglichen Template-Block gelesen statt aus einer separaten feld_labels-Kopie. "multiple" bleibt eine explizite kleine Liste - dafür gibt es im freitext-Fallback keine Entsprechung, das ist keine Duplizierung, sondern echte Zusatzinformation. - scripts/pruefe-manifest-doku.rb (neu): vergleicht die Feldkatalog-Tabelle im öffentlichen Manifest-Kapitel (anderes Repo) gegen den Parser, manuell auszuführen - Regel 9 ("maschinell prüfbar") für genau diese Tabelle. Inhaltliche Korrektur dabei (Rücksprache): kategorie, material und initiatoren waren im Code bereits Pflicht, obwohl das Manifest-Kapitel sie als optional auswies - nach Abgleich sollen sie tatsächlich optional bleiben, config.template.yml bekommt entsprechend "required: false". Verifiziert: admin/config.yml vor/nach Diff zeigt ausschließlich die drei neuen "required: false"-Zeilen, sonst nichts (Renderer-Refactor byte-identisch); validate.rb liefert dieselben Pflichtfeld-Listen wie vorher (minus der drei jetzt optionalen Felder); hugo-Build + Sichtprüfung bestätigen die neuen vollen CMS-Labels im Änderungsverlauf.
This commit is contained in:
+46
-21
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user