#!/bin/sh

# Run this after updating files to regenerate sitemap and other file listings
# Can be run in any directory (works out where to apply changes)
# Public domain (or under the Unlicense, if desired)


SCRIPTS_DIR=$(dirname "$(realpath "$0")")
# Make sure to update this if location of this script changes:
BASE_DIR=$SCRIPTS_DIR/../..


# /sitemap/
cat > "$BASE_DIR"/sitemap/index.html << EOF
<!DOCTYPE html>
<html lang="en-GB">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Maia Woolf – Sitemap</title>
	<link rel="stylesheet" href="../style.css">
</head>
<body>
	<h1>Sitemap</h1>
	<p>This sitemap was generated by
	<a href="../files/gen">some scripts</a> which I run manually, so it may be 
	out of date if I have forgotten to run it.</p>

	<ul>
	<li><a href="../"><code>/</code></a>
	<!-- BEGIN SCRIPT-GENERATED SECTION -->
EOF
"$SCRIPTS_DIR"/create-listing "$BASE_DIR"/ ../ >> "$BASE_DIR"/sitemap/index.html
cat >> "$BASE_DIR"/sitemap/index.html << EOF
	<!-- END SCRIPT-GENERATED SECTION -->
	</li>
	</ul>

	<p>This sentence was last updated on 2026-04-15.</p>
</body>
</html>
EOF


# /files/
cat > "$BASE_DIR"/files/index.html << EOF
<!DOCTYPE html>
<html lang="en-GB">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Maia Woolf – Files</title>
	<link rel="stylesheet" href="../style.css">
</head>
<body>
	<h1>Files</h1>
	<p>You've found the listing of miscellaneous files that I keep on this 
	website!</p>
	<p>This listing was generated by 
	<a href="../files/gen">some scripts</a> which I run manually, so it may be 
	out of date if I have forgotten to run it.</p>

	<!-- BEGIN SCRIPT-GENERATED SECTION -->
EOF
"$SCRIPTS_DIR"/create-listing "$BASE_DIR"/files/ >> "$BASE_DIR"/files/index.html
cat >> "$BASE_DIR"/files/index.html << EOF
	<!-- END SCRIPT-GENERATED SECTION -->

	<p>This sentence was last updated on 2026-04-15.</p>
</body>
</html>
EOF


# /files/gen/ (website generation scripts)
cat > "$BASE_DIR"/files/gen/index.html << EOF
<!DOCTYPE html>
<html lang="en-GB">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Maia Woolf – Listing generation scripts</title>
	<link rel="stylesheet" href="../../style.css">
</head>
<body>
	<h1>Listing generation scripts</h1>
	<p>You've found the listing of scripts that I use to generate file listings 
	on this website.</p>
	<p>This listing was generated by these scripts, which I run manually, so 
	it may be out of date if I have forgotten to run it.</p>

	<!-- BEGIN SCRIPT-GENERATED SECTION -->
EOF
"$SCRIPTS_DIR"/create-listing "$BASE_DIR"/files/gen/ \
	>> "$BASE_DIR"/files/gen/index.html
cat >> "$BASE_DIR"/files/gen/index.html << EOF
	<!-- END SCRIPT-GENERATED SECTION -->

	<p>This sentence was last updated on 2026-04-15.</p>
</body>
</html>
EOF
