From: Steven Baltakatei Sandoval Date: Tue, 6 Aug 2024 14:42:38 +0000 (+0000) Subject: feat(user/mw_wc2sp.sh):Generate subpage list wikicode X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/a80b26ffc2346c0b863477786a36b1542ed0f392?ds=sidebyside feat(user/mw_wc2sp.sh):Generate subpage list wikicode --- diff --git a/user/mw_wc2sp.sh b/user/mw_wc2sp.sh index 421adb7..4973f24 100755 --- a/user/mw_wc2sp.sh +++ b/user/mw_wc2sp.sh @@ -4,14 +4,16 @@ # 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 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 @@ -220,6 +222,20 @@ assemble_subpage_ftree() { 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----\n"; + cat "$p_spc"; + printf -- "\n----\n"; +}; # print wikicode content +print_wc_footer() { + # Output: stdout + printf -- "\n==References==\n\n" + printf -- "\n==Footnotes==\n\n"; + printf -- "\n==Comments==\n\n"; + printf -- "\n"; +}; # print wikicode footer create_output_wikicode() { # Desc: Use subpage list and subpage content files to create # output subpage wikicode. @@ -252,6 +268,10 @@ create_output_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 @@ -273,7 +293,11 @@ create_output_wikicode() { 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"; @@ -323,13 +347,8 @@ create_output_wikicode() { fi; # Print subpage content - printf -- "\n----\n" >> "$p_spwc"; - cat "$p_spc" >> "$p_spwc"; - printf -- "\n----\n" >> "$p_spwc"; - printf -- "\n==References==\n\n" >> "$p_spwc"; - printf -- "\n==Footnotes==\n\n" >> "$p_spwc"; - printf -- "\n==Comments==\n\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 @@ -337,6 +356,9 @@ create_output_wikicode() { 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() {