From f3750ac486f6e40a0173a0ebf654946f00442b66 Mon Sep 17 00:00:00 2001 From: danibene <34680344+danibene@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:23:53 -0400 Subject: [PATCH] specify path to postprocess html --- .readthedocs.yml | 2 +- docs/postprocess.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 5fc2480..a33a517 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -22,7 +22,7 @@ build: python: "3.10" jobs: post_build: - - python docs/postprocess.py + - python docs/postprocess.py --path "$READTHEDOCS_OUTPUT/html" python: install: diff --git a/docs/postprocess.py b/docs/postprocess.py index b579286..cad1e54 100644 --- a/docs/postprocess.py +++ b/docs/postprocess.py @@ -1,11 +1,10 @@ +import argparse # Import the argparse module import re from pathlib import Path from typing import Match, Union from bs4 import BeautifulSoup, Tag -# Install from https://github.com/carpedm20/emoji/ -# with pip install emoji try: from emoji import emojize except ImportError: @@ -35,23 +34,31 @@ def process_html_file(html_file: Union[str, Path]) -> None: with open(html_file, "r", encoding="utf-8") as file: content = file.read() - # Convert emojis in the entire HTML content content = emojize_all(content) - soup = BeautifulSoup(content, "html.parser") - - # Update all tags with src starting with "utils/" update_image_paths(soup) - # Write the changes back to the HTML file with open(html_file, "w", encoding="utf-8") as file: file.write(str(soup)) if __name__ == "__main__": - # Specify the pattern to match the HTML files you want to postprocess - __location__: Path = Path(__file__).parent - html_files: list[Path] = list((__location__ / "_build" / "html").glob("*.html")) + parser = argparse.ArgumentParser(description="Process HTML files.") + parser.add_argument( + "--path", + type=str, + help="Path to the directory containing HTML files to process.", + ) + + args = parser.parse_args() + + if args.path: + base_path = Path(args.path) + else: + __location__: Path = Path(__file__).parent + base_path = __location__ / "_build" / "html" + + html_files: list[Path] = list(base_path.glob("*.html")) for html_file in html_files: process_html_file(html_file)