#!/usr/bin/env python3 """Build the Ferese homepage and redirect former handbook URLs to the wiki.""" from html import escape import importlib.util import json from pathlib import Path import shutil ROOT = Path(__file__).resolve().parent.parent OUTPUT = ROOT / 'build/site' spec = importlib.util.spec_from_file_location('wiki', ROOT / 'scripts/build-wiki.py') wiki = importlib.util.module_from_spec(spec) spec.loader.exec_module(wiki) def redirect_page(destination): return f''' Ferese documentation

This guide is on the Ferese wiki.

''' def main(): if OUTPUT.exists(): shutil.rmtree(OUTPUT) OUTPUT.mkdir(parents=True) for name in ('index.html', 'home.css', 'home.js', 'styles.css'): shutil.copy2(ROOT / 'site' / name, OUTPUT / name) (OUTPUT / 'assets').mkdir(exist_ok=True) shutil.copytree(ROOT / 'site/assets', OUTPUT / 'assets', dirs_exist_ok=True) shutil.copytree(ROOT / 'docs/images', OUTPUT / 'assets', dirs_exist_ok=True) shutil.copytree(ROOT / 'assets/branding', OUTPUT / 'assets/branding') (OUTPUT / '.nojekyll').touch() handbook = OUTPUT / 'docs' handbook.mkdir() (handbook / 'index.html').write_text(redirect_page(wiki.WIKI)) for source in wiki.guide_sources(): if not source.is_relative_to(ROOT / 'docs') or source.stem == 'README': continue destination = wiki.WIKI + '/' + wiki.page_name(source) output = handbook / source.relative_to(ROOT / 'docs').with_suffix('.html') output.parent.mkdir(parents=True, exist_ok=True) output.write_text(redirect_page(destination)) print(f'Built homepage and documentation redirects at {OUTPUT}') if __name__ == '__main__': main()