Skip to content

Commit

Permalink
[Docs] automatic CNAME generator #200
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebotu committed Aug 19, 2024
1 parent 66b5981 commit 197f0e5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions docs/hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
import shutil
from textwrap import dedent

log = logging.getLogger("mkdocs")

Expand All @@ -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")
Expand All @@ -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")
shutil.move("README_backup.md", "README.md")

log.info("Removing CNAME file")
if os.path.exists("CNAME"):
os.remove("CNAME")

0 comments on commit 197f0e5

Please sign in to comment.