From 84cff5cfacc50e2ab0f554e89de969dde0cae50c Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 8 Jan 2024 18:40:50 -0500 Subject: [PATCH] Changed replace_vars to replace every occurence of a variable, not just the first occurence; Started working on generating index page --- build.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index fcec28f..c02b324 100755 --- a/build.sh +++ b/build.sh @@ -69,9 +69,9 @@ add_header_and_footer() { } replace_vars() { -# Loop through 'meta_key' array, search for the first occurence of the values in the HTML doc, and replace them with corresponding values in 'meta_value'. +# Loop through 'meta_key' array, search for all occurences of the values in the HTML doc, and replace them with corresponding values in 'meta_value'. for index in $(seq 0 `expr "${#meta_key[@]}" - 1`); do - sed -i "0, /[\$][\$]${meta_key[$index]}[\$][\$]/ {s/[\$][\$]${meta_key[$index]}[\$][\$]/${meta_value[index]}/}" $1 + sed -i "s/[\$][\$]${meta_key[$index]}[\$][\$]/${meta_value[index]}/g" $1 done } @@ -108,6 +108,26 @@ md_to_html() { done } +gen_index_page() { # Generate an index page (site map) that includes links to the other pages + files=$(find $BASE_PATH/output -name "*.html") + + for file in $files; do + title=$(cat $file | grep "" | head -n 1 | awk -F'[<>]' '{print $3}') # Find the title of the web page + suffix=" - Two More Cents" + title=${title%"$suffix"} # Remove the website name from it + + pub_date=$(cat $file | grep "date-published" | head -n 1 | awk -F'[<>]' '{print $3}') # Find the date published + prefix="Published on " # Find date published of webpage + pub_date=${pub_date#"$prefix"} # Remove the prefix from it + pub_date=${awk "{print $1 $3}" "$pub_date"} # Extract the month and year + + echo "$title $pub_date" + + file_path=$(realpath --relative-to="${BASE_PATH}/output" $file) + + done +} + clean_up() { rm -r ${BASE_PATH}/temp } @@ -118,4 +138,5 @@ setup_temp_dir setup_output_dir del_files_in_output md_to_html +gen_index_page clean_up