Skip to content

Commit

Permalink
Improvements to generate_docs.py (#156)
Browse files Browse the repository at this point in the history
- Added file case insensitive support, for readme and screenshot.
- Added tags taxonomies as an optional metadata in theme.toml, for possible future implementation to search by tags quickly.
  • Loading branch information
harrymkt authored Dec 3, 2024
1 parent 2ead940 commit ed77920
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

MD_ANCHOR_LINKS = r"\[(.+)\]\(#.+\)"

def find_file(directory, filename):
"""Find a file in the given directory regardless of case."""
lower_filename = filename.lower()
for file in os.listdir(directory):
if file.lower() == lower_filename:
return file # Return the correctly-cased filename
return None # File not found

def slugify(s):
"""
Expand Down Expand Up @@ -46,7 +53,7 @@ def __init__(self, name, path):
return # exit the constructor early


with open(os.path.join(self.path, "README.md")) as f:
with open(os.path.join(self.path, find_file(self.path, "README.md"))) as f:
self.readme = f.read()
self.readme = self.readme.replace("{{", "{{/*").replace("}}", "*/}}").replace("{%", "{%/*").replace("%}", "*/%}")
self.readme = re.sub(MD_ANCHOR_LINKS, r"\1", self.readme)
Expand Down Expand Up @@ -76,7 +83,7 @@ def get_commit_dates(self):

def to_zola_content(self):
"""
Returns the page content for Gutenberg
Returns the page content for Zola
"""
return """
+++
Expand All @@ -85,6 +92,9 @@ def to_zola_content(self):
template = "theme.html"
date = {updated}
[taxonomies]
tags = {tags}
[extra]
created = {created}
updated = {updated}
Expand All @@ -109,6 +119,7 @@ def to_zola_content(self):
homepage=self.metadata.get("homepage", self.repository),
min_version=self.metadata["min_version"],
license=self.metadata["license"],
tags=self.metadata.get("tags", "[]"),
author_name=self.metadata["author"]["name"],
author_homepage=self.metadata["author"].get("homepage", ""),
demo=self.metadata.get("demo", ""),
Expand All @@ -128,7 +139,7 @@ def to_zola_folder(self, container):
f.write(self.to_zola_content())

shutil.copyfile(
os.path.join(self.path, "screenshot.png"),
os.path.join(self.path, find_file(self.path, "screenshot.png")),
os.path.join(page_dir, "screenshot.png"),
)

Expand All @@ -145,12 +156,12 @@ def read_themes():
if item.startswith(".") or not os.path.isdir(full_path) or item == "themes":
continue

if not os.path.exists(os.path.join(full_path, "README.md")):
if find_file(full_path, "README.md") == None:
error_message = f"Theme '{item}' is missing README.md."
errors.append(error_message)
continue

if not os.path.exists(os.path.join(full_path, "screenshot.png")):
if find_file(full_path, "screenshot.png") == None:
error_message = f"Theme '{item}' is missing screenshot.png."
errors.append(error_message)
continue
Expand Down

0 comments on commit ed77920

Please sign in to comment.