diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 782402d56c..adf0acb18c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -35,6 +35,14 @@ jobs: path: website fetch-depth: 0 # full history required to determine last edit + - name: Fetch full history for submodules + working-directory: website + run: git submodule foreach --recursive "git fetch --unshallow --all 2>/dev/null || git fetch --all" + + - name: Inject last_modified_at dates from submodules + working-directory: website + run: bash inject_dates.sh + - name: Fetch - precice develop uses: actions/checkout@v4 with: @@ -72,6 +80,19 @@ jobs: bundler-cache: true working-directory: website + - name: Patch jekyll-last-modified-at to respect frontmatter + working-directory: website + run: | + set -euo pipefail + shopt -s nullglob + hook_files=(vendor/bundle/ruby/*/gems/jekyll-last-modified-at-*/lib/jekyll-last-modified-at/hook.rb) + if [ "${#hook_files[@]}" -ne 1 ]; then + echo "Expected exactly one jekyll-last-modified-at hook.rb file, found ${#hook_files[@]}:" >&2 + printf ' %s\n' "${hook_files[@]}" >&2 + exit 1 + fi + sed -i 's/item\.data\["last_modified_at"\] = Determinator/item.data["last_modified_at"] ||= Determinator/' "${hook_files[0]}" + - name: Build website working-directory: website env: diff --git a/inject_dates.sh b/inject_dates.sh new file mode 100644 index 0000000000..6de8156b1b --- /dev/null +++ b/inject_dates.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# inject_dates.sh +# Run this from the website root before jekyll build. +# It goes into each submodule, finds every markdown file, +# gets its true last-commit date from git, and injects/updates +# the last_modified_at field in the frontmatter so that +# jekyll-last-modified-at uses the correct date instead of +# falling back to filesystem mtime. + +set -euo pipefail + +git submodule foreach --recursive ' + echo "==> Processing submodule: $displaypath" + + git ls-files "*.md" "*.markdown" | while IFS= read -r file; do + + last_date=$(git log -1 --date=format:"%Y-%m-%d %H:%M:%S" --pretty=format:"%cd" -- "$file" 2>/dev/null) + + if [ -z "$last_date" ]; then + echo " SKIP (no git date): $file" + continue + fi + + filepath="$toplevel/$displaypath/$file" + + if [ ! -f "$filepath" ]; then + echo " SKIP (not on disk): $file" + continue + fi + + if awk '\''NR==1 { if ($0 == "---") { in_front=1; next } else { exit 1 } } in_front && NR>1 && $0 == "---" { exit 0 } END { exit 1 }'\'' "$filepath"; then + + if grep -q "^last_modified_at:" "$filepath"; then + sed -i "s|^last_modified_at:.*|last_modified_at: $last_date|" "$filepath" + else + sed -i "0,/^---/{s|^---|---\nlast_modified_at: $last_date|}" "$filepath" + fi + + else + tmpfile=$(mktemp) + printf -- "---\nlast_modified_at: %s\n---\n" "$last_date" | cat - "$filepath" > "$tmpfile" + mv "$tmpfile" "$filepath" + fi + + echo " OK: $file -> $last_date" + + done + + echo " done." +' + +echo "" +echo "All submodule dates injected successfully." \ No newline at end of file