Changed replace_vars to replace every occurence of a variable, not just the first occurence; Started working on generating index page
This commit is contained in:
25
build.sh
25
build.sh
@@ -69,9 +69,9 @@ add_header_and_footer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
replace_vars() {
|
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
|
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
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -108,6 +108,26 @@ md_to_html() {
|
|||||||
done
|
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 "<title>" | 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() {
|
clean_up() {
|
||||||
rm -r ${BASE_PATH}/temp
|
rm -r ${BASE_PATH}/temp
|
||||||
}
|
}
|
||||||
@@ -118,4 +138,5 @@ setup_temp_dir
|
|||||||
setup_output_dir
|
setup_output_dir
|
||||||
del_files_in_output
|
del_files_in_output
|
||||||
md_to_html
|
md_to_html
|
||||||
|
gen_index_page
|
||||||
clean_up
|
clean_up
|
||||||
|
Reference in New Issue
Block a user