Initial Commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
index.html*
|
||||
/mirrors
|
||||
29
add_mirror.sh
Executable file
29
add_mirror.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE="/srv/www"
|
||||
URL_LIST="$BASE/mirrors.txt"
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: $0 URL [slug]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
url="$1"
|
||||
if [ $# -ge 2 ]; then
|
||||
slug="$2"
|
||||
else
|
||||
# crude slugify: strip scheme, replace non alnum with underscores
|
||||
slug="$(echo "$url" | sed 's#https\?://##; s#[^a-zA-Z0-9._-]#_#g')"
|
||||
fi
|
||||
|
||||
# Check if URL already exists
|
||||
if grep -q " $url\$" "$URL_LIST" 2>/dev/null; then
|
||||
echo "URL already in list. Not adding again."
|
||||
else
|
||||
echo "$slug $url" >> "$URL_LIST"
|
||||
echo "Added: $slug $url"
|
||||
fi
|
||||
|
||||
# Run update for just this slug
|
||||
"$BASE/update_mirrors.sh" "$slug"
|
||||
61
generate_index.py
Executable file
61
generate_index.py
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
import pathlib
|
||||
import html
|
||||
|
||||
BASE = pathlib.Path("/srv/www")
|
||||
URL_LIST = BASE / "mirrors.txt"
|
||||
OUTDIR = BASE / "mirrors"
|
||||
INDEX = BASE / "index.html"
|
||||
|
||||
entries = []
|
||||
|
||||
if URL_LIST.exists():
|
||||
for line in URL_LIST.read_text(encoding="utf-8").splitlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
parts = line.split(None, 1)
|
||||
if len(parts) != 2:
|
||||
continue
|
||||
slug, url = parts
|
||||
mirror_dir = OUTDIR / slug
|
||||
if not mirror_dir.exists():
|
||||
# not mirrored yet, but still list it
|
||||
status = " (not downloaded yet)"
|
||||
else:
|
||||
status = ""
|
||||
entries.append((slug, url, status))
|
||||
|
||||
items_html = []
|
||||
for slug, url, status in entries:
|
||||
slug_esc = html.escape(slug)
|
||||
url_esc = html.escape(url)
|
||||
status_esc = html.escape(status)
|
||||
# Link goes to the directory; nginx autoindex or an index file will handle it
|
||||
items_html.append(
|
||||
f'<li><a href="mirrors/{slug_esc}/">{slug_esc}</a>'
|
||||
f' – <code>{url_esc}</code>{status_esc}</li>'
|
||||
)
|
||||
|
||||
html_doc = f"""<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>My Tutorial Mirrors</title>
|
||||
<style>
|
||||
body {{ font-family: sans-serif; max-width: 800px; margin: 2rem auto; }}
|
||||
h1 {{ margin-bottom: 0.5rem; }}
|
||||
code {{ font-size: 0.9em; }}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Nytegear Mirrors</h1>
|
||||
<p>This page is generated automatically from <code>mirrors.txt</code>.</p>
|
||||
<ul>
|
||||
{''.join(items_html)}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
INDEX.write_text(html_doc, encoding="utf-8")
|
||||
2
mirrors.txt
Normal file
2
mirrors.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
# Slug URL
|
||||
wgpu-tutorial https://sotrh.github.io/learn-wgpu/
|
||||
43
update_mirrors.sh
Executable file
43
update_mirrors.sh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BASE="/srv/www"
|
||||
URL_LIST="$BASE/mirrors.txt"
|
||||
OUTDIR="$BASE/mirrors"
|
||||
|
||||
mkdir -p "$OUTDIR"
|
||||
|
||||
# If a slug is passed as an argument, only update that one.
|
||||
ONLY_SLUG="${1:-}"
|
||||
|
||||
while read -r slug url; do
|
||||
# skip empty lines & comments
|
||||
[ -z "${slug:-}" ] && continue
|
||||
[[ "$slug" =~ ^# ]] && continue
|
||||
|
||||
if [ -n "$ONLY_SLUG" ] && [ "$slug" != "$ONLY_SLUG" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "=== Mirroring $slug ($url) ==="
|
||||
|
||||
# Each mirror in its own directory
|
||||
TARGET_DIR="$OUTDIR/$slug"
|
||||
mkdir -p "$TARGET_DIR"
|
||||
cd "$TARGET_DIR"
|
||||
|
||||
# Mirror site
|
||||
wget \
|
||||
--mirror \
|
||||
--convert-links \
|
||||
--adjust-extension \
|
||||
--page-requisites \
|
||||
--no-parent \
|
||||
"$url"
|
||||
|
||||
echo "=== Done $slug ==="
|
||||
done < "$URL_LIST"
|
||||
|
||||
# Regenerate index page
|
||||
cd "$BASE"
|
||||
python3 "$BASE/generate_index.py"
|
||||
Reference in New Issue
Block a user