diff --git a/build.sh b/build.sh index c02b324..e596747 100755 --- a/build.sh +++ b/build.sh @@ -108,10 +108,35 @@ md_to_html() { done } -gen_index_page() { # Generate an index page (site map) that includes links to the other pages + +gen_sorted_file_list() { # Generate a list of the HTMl files, sorted by when they were last modified (read from the contents of the HTML file) files=$(find $BASE_PATH/output -name "*.html") + echo "$files" > $BASE_PATH/temp/file_listing.txt # Write file list to a temp file for file in $files; do + date_mod+=$(cat "$file" | grep "date-published" | awk -F'[<>]' '{print $3}' \ + | cut -d' ' -f '1,2' --complement | tr -d "," | awk '{print $2" "$1" "$3}' \ + | date -f - +"%s") + + # Explanation: +# Line 1 extracts the published date from the HTML file +# Line 2 re-arranges this information, and converts it into DD MM YY format +# Line 3 converts this into a UNIX timestamp + + date_mod+=$'\n' + done + + date_mod=$(echo "$date_mod" | head -n -1) # Remove last (empty) line from variable + echo "$date_mod" > $BASE_PATH/temp/date_mod.txt # Write the corresponding 'date modified' timestamps to a temp file + + paste $BASE_PATH/temp/file_listing.txt $BASE_PATH/temp/date_mod.txt > $BASE_PATH/temp/new_file_list.txt # Combine file list and date modified into a single file + + sorted_file_list=$(sort -k 2 $BASE_PATH/temp/new_file_list.txt) # Sort the data in the file, and store it into a variable + sorted_file_list=$(echo "$sorted_file_list" | awk '{print $1}') # Store only the first column (the file path) in the variable +} + +gen_index_page() { # Generate an index page (site map) that includes links to the other pages + for file in $1; do title=$(cat $file | grep "