fix possible theme.yaml instead of theme.toml

This commit is contained in:
Trent Palmer 2023-03-13 19:54:33 -07:00
parent 9fbb14a410
commit c310d64a56

View File

@ -9,6 +9,7 @@ from sys import argv as sys_argv
from time import strptime
import toml
import yaml
from jinja2 import Environment, FileSystemLoader
from requests import get
from sqlalchemy import TEXT, VARCHAR, Column, Integer, create_engine
@ -69,6 +70,7 @@ class Hugothemes(Base):
OLDTHEMESLISTREPO = "gohugoio/hugoThemes"
THEMESLISTREPO = "gohugoio/hugoThemesSiteBuilder"
THEMESLIST = []
THEMESYAMLTHEMES = ("AminZibayi/Corporio",)
def get_themes_name_list():
@ -394,17 +396,23 @@ def get_repo_info_for_hugo_themes_from_gitlab():
print(response.status_code, get_repo_info_for_hugo_themes_from_gitlab.__name__)
def get_theme_toml_file_name(theme_name):
if theme_name in THEMESYAMLTHEMES:
return "theme.yaml"
else:
return "theme.toml"
def get_theme_dot_toml_for_each_hugo_themes():
session = sessionmaker(bind=engine)()
theme_names_from_github = get_github_themes_name_list()
for hugo_theme in theme_names_from_github:
theme = session.query(Hugothemes).filter_by(name=hugo_theme).one()
theme_toml = "theme.toml"
theme_name = get_corrected_theme_name(theme.name)
if theme.name == "gcushen/hugo-academic":
theme_name = "wowchemy/starter-hugo-academic"
api_call_url = "https://api.github.com/repos/"
api_call_url += f"{theme_name}/contents/{theme_toml}"
api_call_url += f"{theme_name}/contents/{get_theme_toml_file_name(theme_name)}"
if theme.themes_toml_ETag is not None:
headers["If-None-Match"] = theme.themes_toml_ETag
@ -423,7 +431,8 @@ def get_theme_dot_toml_for_each_hugo_themes():
session.commit()
elif response.status_code == 403:
print(
response.status_code, get_theme_dot_toml_for_each_hugo_themes.__name__
response.status_code,
get_theme_dot_toml_for_each_hugo_themes.__name__,
)
quit()
elif response.status_code == 404:
@ -432,7 +441,9 @@ def get_theme_dot_toml_for_each_hugo_themes():
get_theme_dot_toml_for_each_hugo_themes.__name__,
hugo_theme,
)
print(response.status_code, get_theme_dot_toml_for_each_hugo_themes.__name__)
print(
response.status_code, get_theme_dot_toml_for_each_hugo_themes.__name__
)
def get_theme_dot_toml_for_each_hugo_themes_from_gitlab():
@ -527,6 +538,11 @@ def parse_themes_toml_for_each_hugo_themes():
# put quotes around any unquoted double-dotted version numbers
# (and add a newline afterwards)
# because python toml libraries will error out on those
theme_name = get_corrected_theme_name(theme.name)
print(theme_name)
if theme_name in THEMESYAMLTHEMES:
theme_toml = yaml.full_load(content)
else:
theme_toml = toml.loads(match.sub(r'"\1"\n', content))
if "tags" in theme_toml:
if len(theme_toml["tags"]) > 0: