Create scripts for generating category gophermaps with ASCII art headers and a blog index gophermap. Also includes root gophermap template with "FROM THE WEB" section for blog integration.
146 lines
6.2 KiB
Python
146 lines
6.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Update the root gophermap to include blog section.
|
|
|
|
This script generates a complete root gophermap with the new "FROM THE WEB"
|
|
section while preserving the existing structure (phlogs, conference notes, etc).
|
|
|
|
Usage:
|
|
python scripts/gopher/update_root_gophermap.py
|
|
python scripts/gopher/update_root_gophermap.py --output gopher_build/
|
|
"""
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
# Paths
|
|
SCRIPT_DIR = Path(__file__).parent
|
|
PROJECT_ROOT = SCRIPT_DIR.parent.parent
|
|
DEFAULT_OUTPUT = PROJECT_ROOT / "gopher_build"
|
|
|
|
# Gophermap formatting
|
|
TAB = "\t"
|
|
FAKE_ENTRY = f"{TAB}fake{TAB}(NULL){TAB}0"
|
|
|
|
|
|
def info_line(text: str = "") -> str:
|
|
"""Generate an info (i) line for gophermap."""
|
|
return f"i{text}{FAKE_ENTRY}"
|
|
|
|
|
|
def file_link(label: str, path: str) -> str:
|
|
"""Generate a text file (0) link."""
|
|
return f"0{label}{TAB}{path}"
|
|
|
|
|
|
def dir_link(label: str, path: str) -> str:
|
|
"""Generate a directory (1) link."""
|
|
return f"1{label}{TAB}{path}"
|
|
|
|
|
|
def echo_directive(command: str) -> str:
|
|
"""Generate a dynamic =echo directive."""
|
|
return f"=echo \"{command}\""
|
|
|
|
|
|
# Root gophermap template with blog section integrated
|
|
ROOT_GOPHERMAP_TEMPLATE = """\
|
|
i \tfake\t(NULL)\t0
|
|
i ''~`` \tfake\t(NULL)\t0
|
|
i ( o o ) \tfake\t(NULL)\t0
|
|
i+-------------------.oooO--(_)--Oooo.---------------+\tfake\t(NULL)\t0
|
|
i| |\tfake\t(NULL)\t0
|
|
i| THE DOUBLE LUNCH DISPATCH |\tfake\t(NULL)\t0
|
|
i| mnw @ sdf |\tfake\t(NULL)\t0
|
|
i| |\tfake\t(NULL)\t0
|
|
i+---------------------------------------------------+\tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
imnw(at)sdf.org | SDF VOIP Ext. 1908 \tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i DAILY PHLOGS \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
1Daily Journal\tjournal/
|
|
=echo "0Latest Entry\tjournal/`ls -t journal/ | grep -v gophermap | head -1`"
|
|
1Historical Phlogs (2018-2019)\tolder/
|
|
i \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i FROM THE WEB \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
iPosts from mnw.sdf.org \tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
1Blog Categories\tblog/
|
|
=echo "0Latest Blog Post\t`find ~/gopher/blog -name '*.txt' -type f -printf '%T@ %p\\n' 2>/dev/null | sort -rn | head -1 | awk '{print $2}' | sed 's|.*/gopher/||'`"
|
|
i \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i CONFERENCE NOTES \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
iPhlogs from conferences (rough notes) \tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
1HOPE 2024\thope_2024/
|
|
1FOSSY 2024\tfossy_2024/
|
|
1LISA 2019\tLISA19/
|
|
1SeaGL 2019\tseagl_2019/
|
|
1Texas Linux Fest 2019\ttxlf_2019/
|
|
1HOPE 2018\thope_2018/
|
|
1SeaGL 2018\tseagl_2018/
|
|
i \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i OTHER THINGS \tfake\t(NULL)\t0
|
|
i===================================================\tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
1Comedy\tcomedy/
|
|
1Short Stories\tstories/
|
|
i \tfake\t(NULL)\t0
|
|
i .oooO \tfake\t(NULL)\t0
|
|
i ( ) Oooo. \tfake\t(NULL)\t0
|
|
i+-------------------\\ (----( )-----------------+ \tfake\t(NULL)\t0
|
|
i \\_) ) / \tfake\t(NULL)\t0
|
|
i (_/ \tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
iMy SDF User Info \tfake\t(NULL)\t0
|
|
=echo "`/usr/pkg/bin/uinfo mnw | tr -d '\\-=><'`"
|
|
i \tfake\t(NULL)\t0
|
|
i __^__ __^__\tfake\t(NULL)\t0
|
|
i( ___ )--------------------------------------------( ___ )\tfake\t(NULL)\t0
|
|
i | / | This gopher space proudly hosted by SDF | \\ |\tfake\t(NULL)\t0
|
|
i | / | mnw on pixelfed.social and tilde.zone | \\ |\tfake\t(NULL)\t0
|
|
i |___| Web: mnw.sdf.org |___|\tfake\t(NULL)\t0
|
|
i(_____)--------------------------------------------(_____)\tfake\t(NULL)\t0
|
|
i \tfake\t(NULL)\t0
|
|
iThanks for reading! Enjoy an SDF oneliner: \tfake\t(NULL)\t0
|
|
=echo "`/usr/pkg/bin/oneliner | tr -d '\\-=><'`"
|
|
"""
|
|
|
|
|
|
def generate_root_gophermap(output_dir: Path = None) -> Path:
|
|
"""Generate the updated root gophermap."""
|
|
output_dir = output_dir or DEFAULT_OUTPUT
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
gophermap_path = output_dir / "gophermap"
|
|
gophermap_path.write_text(ROOT_GOPHERMAP_TEMPLATE)
|
|
|
|
return gophermap_path
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Generate updated root gophermap with blog section"
|
|
)
|
|
parser.add_argument("--output", "-o", type=Path, help="Output directory")
|
|
args = parser.parse_args()
|
|
|
|
output = args.output or DEFAULT_OUTPUT
|
|
path = generate_root_gophermap(output)
|
|
print(f"Generated: {path}")
|
|
print("\nTo deploy, run:")
|
|
print(f" scp {path} mnw@sdf.org:~/gopher/gophermap")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|