The old Makefile was a single 'run' target (hugo server + pagefind --serve). Replace it with documented targets: build hugo --gc -> public/ index build + pagefind --site public -> public/pagefind/ serve / run index + pagefind's own server on 127.0.0.1:1414 (local) serve-lan static-serve public/ on 0.0.0.0:8090 for other machines link-check offline internal-link scan (lychee --scheme file) -> JSON link-fix comment out confirmed-dead internal links, then rebuild external-check network scan of external links (report-only) clean / all Add scripts/: serve_lan.py stdlib static server rooted at public/ (prints LAN IP) fix_dead_links.py idempotent internal dead-link comment-out check_external_links.py external link report (drives the daily cron job) .gitignore: add linkcheck/, resources/_gen/ (regenerable Hugo asset cache), __pycache__/, and .hermes/.
46 lines
1.4 KiB
Python
Executable File
46 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Serve the built site (public/) on all interfaces so other machines on the
|
|
same LAN can reach it. Usage: python3 serve_lan.py [port] (default 8090)
|
|
|
|
The site must be built first: make build index
|
|
Then start this: python3 serve_lan.py
|
|
Address to open from ANOTHER machine on the same network:
|
|
http://<THIS-MACHINE-LAN-IP>:8090/
|
|
where the LAN IP is printed at startup (and is also hostname -I | head -1).
|
|
"""
|
|
import functools
|
|
import http.server
|
|
import socket
|
|
import subprocess
|
|
import sys
|
|
|
|
PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8090
|
|
|
|
# Serve the built site (public/), NOT the repo root.
|
|
handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory="public")
|
|
server = http.server.ThreadingHTTPServer(("0.0.0.0", PORT), handler)
|
|
|
|
|
|
def lan_ip() -> str:
|
|
try:
|
|
return subprocess.check_output(["hostname", "-I"], text=True).split()[0]
|
|
except Exception:
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
try:
|
|
s.connect(("8.8.8.8", 80))
|
|
return s.getsockname()[0]
|
|
finally:
|
|
s.close()
|
|
|
|
|
|
ip = lan_ip()
|
|
print(f"Serving public/ -> http://0.0.0.0:{PORT}/", flush=True)
|
|
print(f"LAN address -> http://{ip}:{PORT}/ (open this from another machine)", flush=True)
|
|
print("Press Ctrl+C to stop.", flush=True)
|
|
try:
|
|
server.serve_forever()
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
server.server_close()
|