Skip to content

Commit

Permalink
specify path to postprocess html
Browse files Browse the repository at this point in the history
  • Loading branch information
danibene committed Mar 14, 2024
1 parent 0cff207 commit f3750ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 17 additions & 10 deletions docs/postprocess.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 <img> 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)
Expand Down

0 comments on commit f3750ac

Please sign in to comment.