Skip to content

Commit

Permalink
fixed script
Browse files Browse the repository at this point in the history
  • Loading branch information
lorossi committed May 24, 2024
1 parent eacf51b commit 655407e
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions check_titles.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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"<title>(.*?)</title>", 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")
Expand All @@ -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__":
Expand Down

0 comments on commit 655407e

Please sign in to comment.