diff --git a/mkdocs_nype/plugins/nype_tweaks/utils.py b/mkdocs_nype/plugins/nype_tweaks/utils.py index 461fb66..d11abda 100644 --- a/mkdocs_nype/plugins/nype_tweaks/utils.py +++ b/mkdocs_nype/plugins/nype_tweaks/utils.py @@ -45,6 +45,14 @@ def is_hex_string(text: str): def obfuscate(text: str): """Turn plain text into base64 and obfuscate it as hex""" + if not isinstance(text, str): + raise ValueError( + f"HEX obfuscation is only avaialble for text strings not {type(text)}({text})" + ) + + # side-effect, but we want consistent results + text = text.strip() + if is_hex_string(text): return text diff --git a/mkdocs_nype/templates/nype-base.html b/mkdocs_nype/templates/nype-base.html index 109a1e4..10d0476 100644 --- a/mkdocs_nype/templates/nype-base.html +++ b/mkdocs_nype/templates/nype-base.html @@ -109,14 +109,13 @@ {% endif -%} {#- Obfuscate values that should not be in plain text in the HTML -#} - {% if page_nype_config.obfuscate_keys %} - {% for name, value in page_nype_config.js.items() %} - {% if name in page_nype_config.obfuscate_keys %} - {% set value = (value | obfuscate) %} - {% endif %} - {%- set _ = page_nype_config.js.update({ name: value })-%} - {% endfor %} - {% endif %} + + {% for name, value in page_nype_config.js.items() %} + {% if name.endswith("_hex") %} + {% set value = (value | obfuscate) %} + {% endif %} + {%- set _ = page_nype_config.js.update({ name: value })-%} + {% endfor %}