Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit8b0bef099c9ef6edd3749936a8f35667c6f0c35f (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-10-17 22:04:51 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-10-17 22:04:51 +0300
Fileseb633f404cad34ab3b4686e335749ffc96d7c630
csg-8b0bef099c9ef6edd3749936a8f35667c6f0c35f.tar
csg-8b0bef099c9ef6edd3749936a8f35667c6f0c35f.tar.gz
csg-8b0bef099c9ef6edd3749936a8f35667c6f0c35f.zip
Parenta22ed0a0c480e06162d99a1dd77ad36c2338a6af (diff)
[p1,s2] Implemented sitemap generation
1 files changed, 30 insertions, 4 deletions
-rwxr-xr-xcsg34
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 <source_dir> <destination_dir> <title_format> [<scripts_dir>]
+ csg <source_dir> <destination_dir> <title_format> <base_url> [<scripts_dir>]
Options:
-h, -?, --help Print this help message (also available when given no
@@ -17,6 +17,9 @@ Arguments:
<title_format> Format string for page title
Accepts any text or HTML, & is replaced with contents
title (first h1 header).
+ <base_url> Base URL of your website (scheme + authority), without
+ trailing "/", used for sitemap generation.
+ Example: https://google.com
<scripts_dir> 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] <base_url> cannot be an empty string!" \
+ && csg_help 3
-AWKSCRIPTS="$4"
+AWKSCRIPTS="$5"
[ -n "$AWKSCRIPTS" -a ! -d "$AWKSCRIPTS" ] && echo "[Error] $AWKSCRIPTS (<scripts_dir>) 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 '<?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"
+
endTimer "[Stage 2] Done"