ebc422f2536ce7fe88b95d108b87a7bb49fbcd09
2 # Desc: Prints mediawiki code for a journal year in the bk4 wiki.
3 # Usage: /bin/bash mw_create_year_journal.sh [int year]
5 # Example: /bin/bash mw_create_year_journal.sh 2023 > output.txt
10 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
11 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
12 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
16 if [[ $# -ne 1 ]]; then die
"FATAL:Invalid arg count:$#"; fi;
17 ## Strip leading zeros
18 yyyy
="$((10#${yyyy}))";
22 if [[ ! $yyyy =~
$re ]]; then die
"FATAL:Invalid year string:$yyyy"; fi;
23 if [[ ! $yyyy -ge 1582 ]]; then die
"FATAL:Invalid year string:$yyyy"; fi;
27 yyyy_prev
="$((yyyy - 1))";
28 yyyy_next
="$((yyyy + 1))";
30 # Form and print header
31 printf "{{bk journal header year}}\n";
32 printf "[[Journal]] for the year [[%d]]. " "$yyyy";
33 printf "Preceded by [[%d]]. " "$yyyy_prev";
34 printf "Followed by [[%d]]. " "$yyyy_next";
37 printf "==Events==\n";
41 for (( mm
=1; mm
<= 12; mm
++ )); do
42 printf "==[[%4d-%02d]]==\n" "$yyyy" "$mm";
46 # Form and print footer
50 printf "%s\n%s\n%s\n" "$s1" "$s2" "$s3";
53 printf "==See Also==\n";
54 printf "* [[Summary of months of {{PAGENAME}}]]\n"
57 printf "==Ext. Links==\n";
60 printf "{{bk journal footer year}}\n";
62 s1
="[[Category:Journals by year]]";