From 3aad82d6e811212b81d574058afc6a7134e45706 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 23 Oct 2023 15:03:36 +0300 Subject: [s2] Reworked sitemap creation with a single awk script This should be generally faster and opens more possibilities for file-dependant properties Also went away with the process substitution, improving portability --- csg | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/csg b/csg index 870c88a..1ce0d3c 100755 --- a/csg +++ b/csg @@ -304,19 +304,23 @@ 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" +$CSG_AWK -v url="$URL" -v dest="$DESTINATION" -v date="$(date +%Y-%m-%d)" ' + BEGIN { + print "" ORS \ + "" + lendest = length(dest) + } + { + $0 = substr($0, index($0, dest) + lendest) + print "" url $0 "" date "1.0" + } + END { print "" } +'<< EOF > "$DESTINATION/sitemap.xml" +$(find "$DESTINATION" -type f -name "*.html") +EOF endTimer "[Stage 2] Done" -- cgit v1.3.1-26-gb76a