#!/usr/bin/env bash # SPDX-FileCopyrightText: 2024 Julien Moutinho (adh14) # SPDX-License-Identifier: AGPL-3.0-or-later # shellcheck disable=SC2034 # shellcheck disable=SC2046 # shellcheck disable=SC2086 # shellcheck disable=SC2119 # shellcheck disable=SC2154 rfcOrga=Rézine rfcRepo=rezine-rfcs rfcList=rfcs rfcDomain=rezine.org # FIXME: host it on rezine.org? rfcGitweb="https://git.sourcephile.fr/julm/$rfcRepo.git" removeAtExit=() exitHook () { rm -rf "${removeAtExit[@]}" } trap exitHook EXIT rfcDirMetadata () { rfcRoot=$(realpath --relative-to . "${0%/*}"/..) rfcDir=$(realpath --relative-to "$rfcRoot" "$rfcDir") rfcBranch=$(realpath --relative-to "$rfcRoot"/rfcs "$rfcDir") rfcYear=$(git log -1 --pretty=%cd --date=format:%Y "$rfcDir/advocacy.md") rfcDate=$(git log -1 --pretty=%cd --date=short "$rfcDir/advocacy.md") } rfcRevision () { local advocacyLatestCommit criticismsLatestCommit advocacyLatestCommit=$(git rev-list --max-count=1 HEAD -- "$rfcDir/advocacy.html") criticismsLatestCommit=$(git rev-list --max-count=1 HEAD -- "$rfcDir/criticisms.html") rfcTagAdvocacyOld="$(git describe --tags "$advocacyLatestCommit")" || true rfcTagCriticismsOld="$(git describe --tags "$criticismsLatestCommit")" || true if test "${rfcTagAdvocacyOld#"${rfcBranch}v"}" != "$rfcTagAdvocacyOld" then IFS=psvc read -r _ _num rfcRevAdvocacy _ <<<"$rfcTagAdvocacyOld" else rfcRevAdvocacy=0; rfcTagAdvocacyOld=init fi if test "${rfcTagCriticismsOld#"${rfcBranch}v"}" != "$rfcTagCriticismsOld" then IFS=psvc read -r _ _num _rfcRevAdvocacy rfcRevCriticisms _ <<<"$rfcTagCriticismsOld" else rfcRevCriticisms=0; rfcTagCriticismsOld=init fi rfcBranchRevision="${rfcBranch}v${rfcRevAdvocacy}" rfcTag="${rfcBranch}c$rfcRevCriticisms" } rfcCitation () { local templateFile metaFile templateFile=$(mktemp --suffix ".md") metaFile=$(mktemp --suffix ".md") removeAtExit+=("$templateFile" "$metaFile") # \${rfcOrga} <[RFC\${rfcTag}](mailto:\${rfcList}+\${rfcTag}@\${rfcDomain})> # — « *\${title}* » — \${rfcDate} — série *Requests for Criticisms* # — \${RFC-Category} « \` \${rfcBranch}\` », # plaidoirie « \` \${rfcRevisionAdvocacy}\` », # critiques « \` \${rfcRevisionCriticisms}\` » # — \${for(RFC-Compasses)}boussole \${it}\${sep} & \${endfor} # — <<\${rfcGitweb}/blob_plain/\${rfcTag}:/rfcs/\${rfcBranch}/index.html>>. cat >"$templateFile" <"$rfcRoot/rfcs/$rfcBranch/citation/v${rfcRevAdvocacy}.script.csl.json" } rfcSource () { if test ! "${rfcNoAdvocacy:+set}"; then cat - "$rfcDir"/advocacy.md < \${rfcOrga} <[RFC\${rfcTag}](mailto:\${rfcList}+\${rfcTag}@\${rfcDomain})> > — « *\${title}* » — \${rfcDate} — série *Requests for Criticisms* > — \${RFC-Category} « \` \${rfcBranch}\` », > plaidoirie « \` \${rfcRevisionAdvocacy}\` », > critiques « \` \${rfcRevisionCriticisms}\` » > — \${for(RFC-Authors)}boussole \${it.boussole} ([\${it.nom}](mailto:\${it.email}))\${sep} & \${endfor} > — <<\${rfcGitweb}/blob_plain/\${rfcTag}:/rfcs/\${rfcBranch}/index.html>>. Vous _devriez_ consulter en priorité sa dernière version qui est disponible en ligne à l'adresse : <<\${rfcGitweb}/blob_plain/\${rfcBranch}:/rfcs/\${rfcBranch}/index.html>> - Statut de cette révision : « \${RFC-Phase} » ::: EOF printf '\n' fi if test ! "${rfcNoHistory:+set}"; then cat "$rfcDir"/history.md printf '\n' fi if test ! "${rfcNoCriticisms:+set}"; then cat "$rfcDir"/criticisms.md fi cat <"$metaFile" <"$sourceFile" rfcCitation pandoc \ --wrap none \ $(rfcMetadata) \ --template "$sourceFile" \ "$sourceFile" | "$@" } rfcPlain () { rfcTemplate \ pandoc --from markdown+emoji --to plain \ --citeproc \ --csl "$rfcRoot"/styles/rfc.csl \ $(printf " --bibliography %s" "$rfcRoot"/refs/*.json \ "$rfcRoot"/rfcs/*/citation/*.csl.json) \ --lua-filter "$rfcRoot"/styles/rfc.lua \ --variable lang=fr-FR \ "$@" } rfcMarkdown () { rfcTemplate \ pandoc --from markdown+emoji --to markdown+emoji \ --table-of-contents \ --toc-depth 6 \ --number-sections \ --citeproc \ --csl "$rfcRoot"/styles/rfc.csl \ $(printf " --bibliography %s" "$rfcRoot"/refs/*.json \ "$rfcRoot"/rfcs/*/citation/*.csl.json) \ --lua-filter "$rfcRoot"/styles/rfc.lua \ --variable lang=fr-FR \ "$@" } rfcHTML () { rfcTemplate \ pandoc --from markdown+emoji --to html5 \ --standalone \ --embed-resources \ --include-in-header "$rfcRoot"/styles/rfc.header.html \ --table-of-contents \ --toc-depth 6 \ --number-sections \ --citeproc \ --csl "$rfcRoot"/styles/rfc.csl \ $(printf " --bibliography %s" "$rfcRoot"/refs/*.json \ "$rfcRoot"/rfcs/*/citation/*.csl.json) \ --lua-filter "$rfcRoot"/styles/rfc.lua \ --variable lang=fr-FR \ "$@" } rfcPDF () { rfcTemplate \ pandoc --from markdown+emoji --to pdf \ --pdf-engine lualatex \ --include-in-header "$rfcRoot"/styles/rfc.header.tex \ --standalone \ --embed-resources \ --table-of-contents \ --toc-depth 6 \ --number-sections \ --citeproc \ --csl "$rfcRoot"/styles/rfc.csl \ $(printf " --bibliography %s" "$rfcRoot"/refs/*.json) \ --lua-filter "$rfcRoot"/styles/rfc.lua \ --variable colorlinks=true \ --variable lang=fr-FR \ --variable links-as-notes=true \ "$@" } rfcTag () { git reset git diff --exit-code -- "$rfcDir" :'!*.html' : "Check if \$rfcRevAdvocacy must be increased." rfcNoCriticisms="set" \ rfcNoHistory="set" \ rfcHTML -o "$rfcDir"/advocacy.html git add "$rfcDir"/advocacy.html rfcRevAdvocacyIncrement=0 if ! git diff --cached --quiet "$rfcDir"/advocacy.html; then rfcRevAdvocacyIncrement=1 # Note that $rfcRevCriticisms is not reset: # criticisms have their own independant revisions # because, in practice, criticisms to an old $rfcRevAdvocacy # can be received and added after a new $rfcRevAdvocacy has been tagged. fi : "Check if \$rfcRevCriticisms must be increased." rfcRevAdvocacy="1" \ rfcNoAdvocacy="set" \ rfcNoHistory="set" \ rfcHTML -o "$rfcDir"/criticisms.html git add "$rfcDir"/criticisms.html rfcRevCriticismsIncrement=0 if ! git diff --cached --quiet "$rfcDir"/criticisms.html; then rfcRevCriticismsIncrement=1 fi if test "$rfcRevAdvocacyIncrement" -gt 0 || test "$rfcRevCriticismsIncrement" -gt 0 then rfcRevAdvocacy=$((rfcRevAdvocacy + rfcRevAdvocacyIncrement)) rfcRevCriticisms=$((rfcRevCriticisms + rfcRevCriticismsIncrement)) rfcBranchRevision="${rfcBranch}v$rfcRevAdvocacy" rfcTag="${rfcBranchRevision}c$rfcRevCriticisms" rfcNoCriticisms="set" \ rfcNoHistory="set" \ rfcHTML -o "$rfcDir"/advocacy.html rfcRevAdvocacy="1" \ rfcNoAdvocacy="set" \ rfcNoHistory="set" \ rfcHTML -o "$rfcDir"/criticisms.html rfcHTML -o "$rfcDir"/index.html #rfcPDF -o "$rfcDir/${rfcRepo}-${rfcBranch}".pdf git add "$rfcDir"/{advocacy,criticisms,index}.html #git add "$rfcDir/${rfcRepo}-${rfcBranch}".pdf git diff --cached --quiet || git commit -m "$rfcBranch: v$rfcRevAdvocacy c$rfcRevCriticisms" git tag --force --sign --message "${rfcOrga} RFC${rfcTag}" "$rfcTag" fi }