#!/bin/bash # ===================================================================== # generate-sitemap.sh - Generate sitemap.xml for the website # ===================================================================== # This script generates a sitemap.xml file for the website # It should be run after any content updates # ===================================================================== set -e echo "Generating sitemap.xml..." # Directory containing the files BASE_DIR="$(pwd)" DOMAIN="http://localhost:8080" # Use localhost for local development and testing # Get current date in ISO 8601 format CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%S+00:00") # Create sitemap header cat > "$BASE_DIR/sitemap.xml" << EOF EOF # Find all HTML files and add them to sitemap find "$BASE_DIR" -name "*.html" -type f | sort | while read -r html_file; do # Skip files in includes directory and template files if [[ "$html_file" == *"/includes/"* ]] || [[ "$html_file" == *"-with-includes.html" ]] || [[ "$html_file" == *"template"* ]]; then continue fi # Get relative path from base directory rel_path="${html_file#$BASE_DIR/}" # Skip csv-tool-output.html as it's dynamically generated if [[ "$rel_path" == "csv-tool-output.html" ]]; then continue fi # Create URL url="$DOMAIN/$rel_path" # Add URL to sitemap cat >> "$BASE_DIR/sitemap.xml" << EOF $url $CURRENT_DATE monthly 0.8 EOF done # Close sitemap cat >> "$BASE_DIR/sitemap.xml" << EOF EOF echo "Sitemap generated at $BASE_DIR/sitemap.xml" echo "Total URLs: $(grep -c "" "$BASE_DIR/sitemap.xml")"