Skip to content
Permalink
Browse files

flake8

  • Loading branch information
da2x committed Aug 27, 2015
1 parent b6f2eee commit 0b47d687caea8635acc10d41dd775d277d4f21f1
Showing with 12 additions and 9 deletions.
  1. +1 −3 nikola/plugins/task/indexes.py
  2. +5 −1 nikola/post.py
  3. +6 −5 nikola/utils.py
@@ -38,9 +38,7 @@
from nikola import utils



class Indexes(Task):

"""Render the blog indexes."""

name = "render_indexes"
@@ -117,7 +115,7 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):

for dirname, post_list in groups.items():

if not lang in self.number_of_pages_cat:
if lang not in self.number_of_pages_cat:
self.number_of_pages_cat[lang] = dict()
self.number_of_pages_cat[lang][dirname] = (len(post_list) + kw['index_display_post_count'] - 1) // kw['index_display_post_count']

@@ -746,21 +746,24 @@ def destination_path(self, lang=None, extension='.html', sep=os.sep):
return path

def category_color(self, lang=None):
""" Return the color of the post's category. """
slug = self.category_slug(lang)
if slug in self.config['POSTS_CATEGORY_COLORS'](lang):
return self.config['POSTS_CATEGORY_COLORS'](lang)[slug]
base = self.config['THEME_COLOR']
return utils.colorize_str_from_base_color(slug, base)

def category_link(self, lang=None):
""" Return the link to the post's category. """
slug = self.category_slug(lang)
if not self.pretty_urls:
link = urljoin('/'+ slug + '/', self.index_file)
link = urljoin('/' + slug + '/', self.index_file)
else:
link = '/' + slug + '/'
return link

def category_name(self, lang=None):
""" Return the name of the post's category. """
slug = self.category_slug(lang)
if slug in self.config['POSTS_CATEGORY_NAME'](lang):
name = self.config['POSTS_CATEGORY_NAME'](lang)[slug]
@@ -769,6 +772,7 @@ def category_name(self, lang=None):
return name

def category_slug(self, lang=None):
""" Return the slug for the post's category. """
if not self.config['POSTS_CATEGORY_FROM_META']:
dest = self.destination_path(lang)
if dest[-(1 + len(self.index_file)):] == '/' + self.index_file:
@@ -1678,24 +1678,25 @@ def colorize_str_from_base_color(string, base_color):
""" Find a perceptual similar color from a base color based on the hash of a sring.
Make up to 16 attempts (number of bytes returned by hashing) at picking a
hue for our color at least 27° away from the base color, leaving lightness
and saturation untouched using HUSL colorspace. """
hue for our color at least 27 deg removed from the base color, leaving
lightness and saturation untouched using HUSL colorspace.
"""
def hash_str(string, pos):
return hashlib.md5(string.encode('utf-8')).digest()[pos]

def degreediff(dega, degb):
return min(abs(dega - degb), abs((degb - dega) + 360))

def husl_similar_from_base(string, base_color):
h,s,l = husl.hex_to_husl(base_color)
h, s, l = husl.hex_to_husl(base_color)
old_h = h
idx = 0
while degreediff(old_h, h) < 27 and idx < 16:
print("%i: %f vs %f (diff %f)" % (idx, h, old_h, degreediff(old_h, h)))
h = 360.0 * (float(hash_str(string, idx)) / 255)
idx += 1
print(str(h) + husl.husl_to_hex(h,s,l))
return husl.husl_to_hex(h,s,l)
print(str(h) + husl.husl_to_hex(h, s, l))
return husl.husl_to_hex(h, s, l)

return husl_similar_from_base(string, base_color)

0 comments on commit 0b47d68

Please sign in to comment.
You can’t perform that action at this time.