Skip to content
Permalink
Browse files
Add utils.colorize_str (replaces/generalizes section colors)
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 2, 2018
1 parent 652e3b4 commit 5209155fecf4217f2d345f9ea2fb847a689a6315
Showing with 9 additions and 0 deletions.
  1. +1 −0 docs/template-variables.rst
  2. +1 −0 nikola/nikola.py
  3. +7 −0 nikola/utils.py
@@ -97,6 +97,7 @@ Name Type Descript
``social_buttons_code`` TranslatableSetting<str> ``SOCIAL_BUTTONS_CODE`` setting
``sort_posts`` function ``utils.sort_posts`` function
``smartjoin`` function ``utils.smartjoin`` function
``colorize_str`` function ``utils.colorize_str`` function
``template_hooks`` dict<str, TemplateHookRegistry> Template hooks registered by plugins
``theme_color`` str ``THEME_COLOR`` setting
``timezone`` tzinfo Timezone object (represents the configured timezone)
@@ -1177,6 +1177,7 @@ def _set_global_context_from_config(self):
self._GLOBAL_CONTEXT['url_replacer'] = self.url_replacer
self._GLOBAL_CONTEXT['sort_posts'] = utils.sort_posts
self._GLOBAL_CONTEXT['smartjoin'] = utils.smartjoin
self._GLOBAL_CONTEXT['colorize_str'] = utils.colorize_str
self._GLOBAL_CONTEXT['meta_generator_tag'] = self.config.get('META_GENERATOR_TAG')

self._GLOBAL_CONTEXT.update(self.config.get('GLOBAL_CONTEXT', {}))
@@ -1767,6 +1767,13 @@ def degreediff(dega, degb):
return husl.husl_to_hex(h, s, l)


def colorize_str(string: str, base_color: str, presets: dict):
"""Colorize a string by using a presets dict or generate one based on base_color."""
if string in presets:
return presets[string]
return colorize_str_from_base_color(string, base_color)


def color_hsl_adjust_hex(hexstr, adjust_h=None, adjust_s=None, adjust_l=None):
"""Adjust a hex color using HSL arguments, adjustments in percentages 1.0 to -1.0. Returns a hex color."""
h, s, l = husl.hex_to_husl(hexstr)

0 comments on commit 5209155

Please sign in to comment.