From c42a2f99271e44090d7f85d5467d644a947538d9 Mon Sep 17 00:00:00 2001 From: Trent Palmer Date: Sat, 19 Nov 2022 22:34:55 -0800 Subject: [PATCH] fix min_ver in multiple locations in themes.toml https://github.com/TrentSPalmer/hugo_themes_report/issues/1 --- rank_hugo_themes.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/rank_hugo_themes.py b/rank_hugo_themes.py index ee04352..4fd4892 100755 --- a/rank_hugo_themes.py +++ b/rank_hugo_themes.py @@ -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")