From 8b0bef099c9ef6edd3749936a8f35667c6f0c35f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 17 Oct 2023 22:04:51 +0300 Subject: [p1,s2] Implemented sitemap generation --- csg | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/csg b/csg index ad2d41c..bde30dc 100755 --- a/csg +++ b/csg @@ -5,7 +5,7 @@ csg_help() { echo 'Usage: csg [-h | -? | --help] - csg [] + csg [] Options: -h, -?, --help Print this help message (also available when given no @@ -17,6 +17,9 @@ Arguments: Format string for page title Accepts any text or HTML, & is replaced with contents title (first h1 header). + Base URL of your website (scheme + authority), without + trailing "/", used for sitemap generation. + Example: https://google.com Optional, folder which contains awk script for editing of generated webpages. @@ -58,8 +61,11 @@ DESTINATION="$(realpath "$2")" && csg_help 2 TITLEF="$3" +URL="$4" +[ -z "$URL" ] && echo "[Error] cannot be an empty string!" \ + && csg_help 3 -AWKSCRIPTS="$4" +AWKSCRIPTS="$5" [ -n "$AWKSCRIPTS" -a ! -d "$AWKSCRIPTS" ] && echo "[Error] $AWKSCRIPTS () isn't a directory or doesn't exist!" \ && csg_help 1 @@ -85,7 +91,7 @@ then CSG_AWK='gawk --posix' else echo '[Error] Couldn'\''t find an awk implementation!' - csg_help 3 + csg_help 4 fi if [ -n "$CSG_MD_TO_HTML" ] @@ -99,7 +105,7 @@ then --parse-no-autolink" else echo '[Error] Couldn'\''t find a Markdown to HTML convertion program!' - csg_help 3 + csg_help 4 fi ### Preprocessing 4 @@ -278,7 +284,27 @@ do do [ "${scr_recip[$i]}" != "${scr_recip[$i]/${file%md}html/}" ] && scripts+=" -f ${scr_path[$i]} " done + transform-file "$file" "$scripts" & done < <(find "$DESTINATION" -type f -name "*.md") wait + +overwriteLine "[Stage 2] Generating sitemap" + # This cannot really be done while transforming files, since you could have static .html pages + +echo ' +' > "$DESTINATION/sitemap.xml" +date="$(date +%Y-%m-%d)" + +while read -r file +do + echo "$URL${file#$DESTINATION}$date1.0" >> "$DESTINATION/sitemap.xml" +done < <(find "$DESTINATION" -type f -name "*.html") + +echo '' >> "$DESTINATION/sitemap.xml" + endTimer "[Stage 2] Done" -- cgit v1.3.1-26-gb76a