Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
1 files changed, 18 insertions, 14 deletions
-rwxr-xr-xcsg32
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 '<?xml version="1.0" encoding="UTF-8"?>
-<urlset
-xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
-http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
-xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' > "$DESTINATION/sitemap.xml"
-date="$(date +%Y-%m-%d)"
-
-while read -r file
-do
- echo "<url><loc>$URL${file#$DESTINATION}</loc><lastmod>$date</lastmod><priority>1.0</priority></url>" >> "$DESTINATION/sitemap.xml"
-done < <(find "$DESTINATION" -type f -name "*.html")
-
-echo '</urlset>' >> "$DESTINATION/sitemap.xml"
+$CSG_AWK -v url="$URL" -v dest="$DESTINATION" -v date="$(date +%Y-%m-%d)" '
+ BEGIN {
+ print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ORS \
+ "<urlset" ORS \
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" ORS \
+ "xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9" ORS \
+ "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"" ORS \
+ "xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"
+ lendest = length(dest)
+ }
+ {
+ $0 = substr($0, index($0, dest) + lendest)
+ print "<url><loc>" url $0 "</loc><lastmod>" date "</lastmod><priority>1.0</priority></url>"
+ }
+ END { print "</urlset>" }
+'<< EOF > "$DESTINATION/sitemap.xml"
+$(find "$DESTINATION" -type f -name "*.html")
+EOF
endTimer "[Stage 2] Done"