From 197f0e5f2f8a307a47861a2ffcb0d93f6b577786 Mon Sep 17 00:00:00 2001 From: Federico Berto Date: Mon, 19 Aug 2024 19:26:13 +0900 Subject: [PATCH] [Docs] automatic CNAME generator #200 --- docs/hooks.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/hooks.py b/docs/hooks.py index 24d6640b..f4516b6a 100644 --- a/docs/hooks.py +++ b/docs/hooks.py @@ -1,7 +1,6 @@ import logging import os import shutil -from textwrap import dedent log = logging.getLogger("mkdocs") @@ -22,25 +21,31 @@ def on_startup(*args, **kwargs): # huge trick: we save a backup of README.md and append CSS content to hide some elements log.info("Saving backup of README.md and appending CSS content") shutil.copyfile("README.md", "README_backup.md") + # warning: don't touch any of the following. you have been warned :) def append_tricks_to_readme(file_path): # read the tricks from docs/overrides/fancylogo.txt # and put them at the beginning of the file - with open("docs/overrides/fancylogo.txt", 'r') as fancylogo: + with open("docs/overrides/fancylogo.txt", "r") as fancylogo: tricks = fancylogo.read() if not os.path.exists(file_path): print(f"Error: The file {file_path} does not exist.") - return - with open(file_path, 'r') as original: + return + with open(file_path, "r") as original: data = original.read() # remove first 33 lines. yeah, it's a hack to remove unneded stuff lol - data = '\n'.join(data.split('\n')[33:]) - with open(file_path, 'w') as modified: + data = "\n".join(data.split("\n")[33:]) + with open(file_path, "w") as modified: modified.write(tricks + data) print(f"CSS content has been appended to {file_path}") append_tricks_to_readme("README.md") + # Create CNAME file with content "rl4.co" + log.info("Creating CNAME file with content 'rl4.co'") + with open("CNAME", "w") as f: + f.write("rl4.co") + def on_shutdown(*args, **kwargs): log.info(f"Removing {len(created_files)} created __init__.py files") @@ -49,4 +54,8 @@ def on_shutdown(*args, **kwargs): os.remove(file_path) log.info("Replace README.md with README_backup.md") - shutil.move("README_backup.md", "README.md") \ No newline at end of file + shutil.move("README_backup.md", "README.md") + + log.info("Removing CNAME file") + if os.path.exists("CNAME"): + os.remove("CNAME")