Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test generate_readme.py #46

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions generate_readme.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#!/usr/bin/env python3
"""
This script generates a Markdown table for the README.md file based on the JSON data.
"""

#!/bin/env python3
# pylint: disable=invalid-name
""""This is a script to generate a Markdown table for the README.md file"""
import json

# Load JSON data from file
with open('hyde-themes.json', 'r', encoding='utf-8') as file:
with open("hyde-themes.json", "r", encoding="utf-8") as file:
data = json.load(file)

# Sort the data list based on theme name
data.sort(key=lambda theme: theme.get("THEME", "N/A"))
# data.sort(key=lambda theme: theme.get("THEME", "N/A"))
# Sort the data list based on the first element of COLORSCHEME
data.sort(key=lambda theme: theme.get("COLORSCHEME", ["#000000"])[0])

# Initialize the Markdown table
MARKDOWN_TABLE = "| Theme | Description | Author |\n"
MARKDOWN_TABLE += "| --- | --- | --- |\n"
MD_TABLE = "| Theme | Description | Author |\n"
MD_TABLE += "| --- | --- | --- |\n"

# Iterate through the sorted JSON data and populate the table
for theme in data:
theme_name = theme.get("THEME", "N/A")
description = theme.get("DESCRIPTION", "N/A")
author = theme.get("OWNER", "N/A").split('/')[-1]
author = theme.get("OWNER", "N/A").split("/")[-1]
link = theme.get("LINK", "#")
colorscheme = theme.get("COLORSCHEME", ["#000000", "#FFFFFF"])

Expand All @@ -29,14 +29,14 @@
colorscheme[1][1:]}?text={theme_name.replace(' ', '+')}&font=Oswald"

# Add the row to the table
MARKDOWN_TABLE += f"| [![{theme_name}]({image_link})]({link}) | {
MD_TABLE += f"| [![{theme_name}]({image_link})]({link}) | {
description} | [{author}]({theme.get('OWNER', '#')}) |\n"

# Add the footer note and end marker
MARKDOWN_TABLE += "\n<!-- TABLE_END -->"
MD_TABLE += "\n<!-- TABLE_END -->"

# Read the contents of README.md
with open('README.md', 'r', encoding='utf-8') as readme_file:
with open("README.md", "r", encoding="utf-8") as readme_file:
readme_content = readme_file.read()

# Define the markers where the table content will be inserted
Expand All @@ -47,13 +47,18 @@
if START_MARK in readme_content and END_MARK in readme_content:
before_table = readme_content.split(START_MARK)[0] + START_MARK
after_table = readme_content.split(END_MARK)[1]
updated_readme_content = before_table + "\n" + MARKDOWN_TABLE + after_table
updated_readme_content = before_table + "\n" + MD_TABLE + after_table
else:
updated_readme_content = readme_content + "\n" + \
"# Theme Gallery\n" + "<!-- TABLE_START -->\n" + MARKDOWN_TABLE
updated_readme_content = (
readme_content
+ "\n"
+ "# Theme Gallery\n"
+ "<!-- TABLE_START -->\n"
+ MD_TABLE
)

# Write the updated content back to README.md
with open('README.md', 'w', encoding='utf-8') as readme_file:
with open("README.md", "w", encoding="utf-8") as readme_file:
readme_file.write(updated_readme_content)

print("README.md has been updated with the generated Markdown table.")