# Input: arg1 path input wikicode file
# Output: files wikicode file tree
# Depends: Bash 5.1.16, GNU Coreutils 8.32
-# Version: 0.0.1
+# Version: 0.1.0
re_sp='^(<!-- @subpage:)(.*)([ ]*-->)$'; # subpage marker pattern
d_out=./wikicode/; # default output dir
-f_spl="subpage_list.txt";
+f_spl="subpage_list.txt"; # subpage title list
p_spl="${d_out}/${f_spl}";
-f_splv="subpage_list_validated.txt";
+f_splv="subpage_list_validated.txt"; # subpage title list (validated)
p_splv="${d_out}/${f_splv}";
+f_splwc="subpage_list.wc"; # subpage list wikicode
+p_splwc="${d_out}/${f_splwc}";
yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
yell "STATUS:Finished assemble_subpage_ftree()."; # debug
}; # process input wikicode into subpage content files and subpage list
+print_wc_content() {
+ # Input: var p_spc path subpage content
+ # Output: stdout
+ printf -- "\n----<onlyinclude>\n";
+ cat "$p_spc";
+ printf -- "\n</onlyinclude>----\n";
+}; # print wikicode content
+print_wc_footer() {
+ # Output: stdout
+ printf -- "\n==References==\n<references />\n"
+ printf -- "\n==Footnotes==\n<references group=fn />\n";
+ printf -- "\n==Comments==\n<references group=cmt />\n";
+ printf -- "\n";
+}; # print wikicode footer
create_output_wikicode() {
# Desc: Use subpage list and subpage content files to create
# output subpage wikicode.
die "FATAL:Different line counts for subpage lists:$(declare -p lc_spl lc_splv;)";
fi;
declare -p lc_spl lc_splv; # debug
+
+ # Initialize subpage list wikicode file
+ must touch "$p_splwc";
+ printf "==Stats==\n\n==Subpages==\n" >> "$p_splwc";
# Read content files according to subpage list file
# Note: $i corresponds to “next” line ($lnext). Therefore, use
f_spwc="${lines_splv[i-1]}.wc";
p_spwc="${d_out}/${f_spwc}"; # use validated subpage name
declare -p f_spwc p_spwc; # debug
- if [[ "$i" -gt 0 ]]; then must touch "$p_spwc"; fi;
+ if [[ "$i" -gt 0 ]]; then
+ must touch "$p_spwc";
+ ## Append subpage list wikicode file
+ printf "* [[/%s]]\n" "${lines_splv[i-1]}" >> "$p_splwc";
+ fi;
# Advance input lines
lprev="$lcurr";
fi;
# Print subpage content
- printf -- "\n----<onlyinclude>\n" >> "$p_spwc";
- cat "$p_spc" >> "$p_spwc";
- printf -- "\n</onlyinclude>----\n" >> "$p_spwc";
- printf -- "\n==References==\n<references />\n" >> "$p_spwc";
- printf -- "\n==Footnotes==\n<references group=fn />\n" >> "$p_spwc";
- printf -- "\n==Comments==\n<references group=cmt />\n" >> "$p_spwc";
- printf -- "\n"; >> "$p_spwc";
+ print_wc_content >> "$p_spwc";
+ print_wc_footer >> "$p_spwc";
declare -p i lprev lcurr lnext lprev_hier lcurr_hier lnext_hier; # debug
declare -p fork_level_next fork_level_prev relups_next relups_prev; # debug
printf "====================\n" # debug
done;
+ # Add footer to subpage list wikicode file
+ print_wc_footer >> "$p_splwc";
+
yell "STATUS:Finished create_output_wikicode()."; # debug
}; # generate output subpage wikicode
main() {