diff --git a/check_titles.py b/check_titles.py index 4b98e93..59dce04 100644 --- a/check_titles.py +++ b/check_titles.py @@ -1,5 +1,7 @@ """This script checks for titles and description in all the files called index.html.""" +import os +import re from glob import glob @@ -13,6 +15,14 @@ def check_default_content(content: str) -> bool: return 'content="TEMPLATE"' in content +def check_page_title(content: str, folder: str) -> bool: + """Check if the page title is consistent with the folder name.""" + clean_folder = folder.split("/")[-1].replace("-", " ").lower() + page_title = re.search(r"(.*?)", content).group(1) + clean_title = page_title.replace("-", " ").lower() + return clean_title in clean_folder, clean_folder, clean_title + + def list_files() -> list[str]: """List all the index.html files.""" return glob("animations/**/index.html") @@ -28,10 +38,23 @@ def main(): """Script entry point.""" for file in list_files(): content = open_file(file) - if check_default_title(content): - print(f"Title not changed in {file}") - if check_default_content(content): - print(f"Description not changed in {file}") + folder = os.path.dirname(file) + + default_title = check_default_title(content) + default_content = check_default_content(content) + title_valid, folder_title, page_title = check_page_title(content, folder) + + if any([default_title, default_content, not title_valid]): + print(f"{file}:") + if default_title: + print("\tTitle not changed") + if default_content: + print("\tDescription not changed") + if not title_valid and not (default_title or default_content): + print( + f"\tTitle not consistent with folder name: " + f"page title: {page_title}, folder title: {folder_title}" + ) if __name__ == "__main__":