#!/usr/bin/env ruby # Translates the form field "veroeffentlicht" (Decap, positive polarity: on # = published) into Hugo's native draft field (inverted: draft: true = # unpublished) - only in the local _content copy (not in the content repo), # before every Hugo build. Decap cannot write a boolean field inverted into # a differently named frontmatter field, hence this translation step # instead of a direct CMS mapping. Must run before # compute-methoden-sichtbarkeit.rb, which in turn reads the draft field set # here for variants (that script aborts if it still finds untranslated # "veroeffentlicht" fields, see there). require_relative 'lib/frontmatter' root = File.expand_path('..', __dir__) varianten_dir = File.join(root, '_content', 'varianten') changed = 0 if Dir.exist?(varianten_dir) Dir.glob(File.join(varianten_dir, '*', 'index.md')).each do |file| result = Frontmatter.read(file) next unless result fm, body = result # Missing "veroeffentlicht" (e.g. a variant committed directly via the # PR path, bypassing Decap's boolean widget with its "default: false") # must translate to unpublished, not be skipped untranslated - a # missing "draft" frontmatter key defaults to visible in Hugo, so # skipping this file entirely would publish it unintentionally. veroeffentlicht = fm.key?('veroeffentlicht') ? fm.delete('veroeffentlicht') == true : false fm['draft'] = !veroeffentlicht Frontmatter.write(file, fm, body, feldreihenfolge: Frontmatter::VARIANTEN_FELDER) changed += 1 end end puts "veroeffentlicht -> draft übersetzt: #{changed} Variante(n)"