fix min_ver in multiple locations in themes.toml https://github.com/TrentSPalmer/hugo_themes_report/issues/1

This commit is contained in:
Trent Palmer 2022-11-19 22:34:55 -08:00
parent 8414ef5d42
commit c42a2f9927
1 changed files with 27 additions and 2 deletions

View File

@ -583,8 +583,10 @@ def parse_themes_toml_for_each_hugo_themes():
else:
if theme.theme_license is not None:
theme.theme_license = None
if "min_version" in theme_toml:
corrected_mv = get_corrected_min_ver(theme_toml["min_version"])
if theme_toml_has_min_ver(theme_toml):
corrected_mv = get_corrected_min_ver(
get_min_ver_from_theme_toml(theme_toml)
)
if theme.min_ver != corrected_mv:
theme.min_ver = corrected_mv
else:
@ -622,6 +624,29 @@ def parse_themes_toml_for_each_hugo_themes():
session.commit()
def get_min_ver_from_theme_toml(theme_toml):
if "min_version" in theme_toml:
return theme_toml["min_version"]
if "module" in theme_toml:
if "hugoVersion" in theme_toml["module"]:
if "min" in theme_toml["module"]["hugoVersion"]:
return theme_toml["module"]["hugoVersion"]["min"]
if "min_version" in theme_toml["module"]["hugoVersion"]:
return theme_toml["module"]["hugoVersion"]["min_version"]
def theme_toml_has_min_ver(theme_toml):
if "min_version" in theme_toml:
return True
if "module" in theme_toml:
if "hugoVersion" in theme_toml["module"]:
if "min" in theme_toml["module"]["hugoVersion"]:
return True
if "min_version" in theme_toml["module"]["hugoVersion"]:
return True
return False
def get_corrected_min_ver(x):
if "o" in str(x):
return x.replace("o", "0")