Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1981 from getnikola/posts-categories
Add Sections and related color functionality for theme authors
  • Loading branch information
da2x committed Aug 31, 2015
2 parents 083ce3c + b67410c commit 0b24500
Show file tree
Hide file tree
Showing 16 changed files with 341 additions and 2 deletions.
15 changes: 15 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,12 +4,27 @@ New in master
Features
--------

* New ``THEME_COLOR`` option for customizing themes from a primary color
(Issue #1980)
* New ``color_hsl_adjust_hex`` and ``colorize_str_from_base_color``
functions available in themes (Issue #1980)
* New ``POSTS`` output subfolders now generate sections by deault
(Issue #1980)
* New ``POSTS_SECTIONS`` and ``POSTS_SECTION_*`` options for
configuring the section pages (Issue #1980)
* For themers: Each ``post`` are now asssociated with section_color,
section_link, and section_name (Issue #1980)
* Each new section page has a auto-assigned color based on shifting
the hue of ``THEME_COLOR`` based on a hash of the section name,
can be overwritten with ``POSTS_SECTION_COLORS`` option (Issue #1980)
* New ``TAG_PAGES_TITLES`` and ``CATEGORY_PAGES_TITLES`` options
(Issue #1962)

Bugfixes
--------

* ``pagekind["main_index"]`` set on the main indexes to differentiate
them from all the other indexes.
* Add dependency on metadata file for 2-file posts (Issue #1968)
* Set UTF-8 charset in Content-Type or text/* and *+xml (Issue #1966)

Expand Down
26 changes: 26 additions & 0 deletions docs/theming.txt
Expand Up @@ -193,6 +193,29 @@ require whatever data you want.
Also, you can specify a custom template to be used by a post or page via the ``template`` metadata,
and custom templates can be added in the ``templates/`` folder of your site.

Customizing themes to user color preferece and section colors
-------------------------------------------------------------

The user’s preference for theme color is exposed in templates as
``theme_color`` set in the ``THEME_COLOR`` option.

Each section has an assigned color that is either set by the user or auto
selected by adjusting the hue of the user’s ``THEME_COLOR``. The color is
exposed in templates through ``post.section_color(lang)``. The function that
generates the colors from strings and any given color (by section name and
theme color for sections) is expoed through the
``colorize_str_from_base_color(string, hex_color)`` function

Hex color values, like that returned by the theme or section color can be
altered in the HSL colorspace through the function
``color_hsl_adjust_hex(hex_string, adjust_h, adjust_s, adjust_l)``.
Adjustments are given in values between 1.0 and -1.0. For example, the theme
color can be made lighter using:

.. code:: html+mako

<span style="color:${color_hsl_adjust_hex(theme_color, adjust_l=0.05)}">

Identifying and customizing different kinds of pages with a shared template
---------------------------------------------------------------------------

Expand Down Expand Up @@ -247,10 +270,13 @@ List of page kinds provided by default plugins:
* index
* index, archive_page
* index, author_page
* index, main_index
* index, section_page
* index, tag_page
* list
* list, archive_page
* list, author_page
* list, section_page
* list, tag_page
* list, tags_page
* post_page
Expand Down
55 changes: 55 additions & 0 deletions nikola/conf.py.in
Expand Up @@ -89,6 +89,10 @@ NAVIGATION_LINKS = ${NAVIGATION_LINKS}
# Name of the theme to use.
THEME = ${THEME}

# Primary color of your theme. This will be used to customize your theme and
# auto-generate related colors in POSTS_SECTION_COLORS. Must be a HEX value.
THEME_COLOR = '#5670d4'

##############################################
# Below this point, everything is optional
##############################################
Expand Down Expand Up @@ -208,6 +212,57 @@ COMPILERS = ${COMPILERS}
# Warning: this option will change its default value to False in v8!
WRITE_TAG_CLOUD = True

# Generate pages for each section. The site must have at least two sections
# for this option to take effect. It wouldn't build for just one section.
POSTS_SECTIONS = True

# Setting this to False generates a list page instead of an index. Indexes
# are the default and will apply GENERATE_ATOM if set.
# POSTS_SECTIONS_ARE_INDEXES = True

# Each post and section page will have an associated color that can be used
# to style them with a recognizable color detail across your site. A color
# is assigned to each section based on shifting the hue of your THEME_COLOR
# at least 7.5 % while leaving the lightness and saturation untouched in the
# HUSL colorspace. You can overwrite colors by assigning them colors in HEX.
# POSTS_SECTION_COLORS = {
# DEFAULT_LANG: {
# 'posts': '#49b11bf',
# 'reviews': '#ffe200',
# },
# }

# Associate a description with a section. For use in meta description on
# section index pages or elsewhere in themes.
# POSTS_SECTION_DESCRIPTIONS = {
# DEFAULT_LANG: {
# 'how-to': 'Learn how-to things properly with these amazing tutorials.',
# },
# }

# Sections are determined by their output directory as set in POSTS by default,
# but can alternatively be determined from file metadata instead.
# POSTS_SECTION_FROM_META = False

# Names are determined from the output directory name automatically or the
# metadata label. Unless overwritten below, names will use title cased and
# hyphens replaced by spaces.
# POSTS_SECTION_NAME = {
# DEFAULT_LANG: {
# 'posts': 'Blog Posts',
# 'uncategorized': 'Odds and Ends',
# },
# }

# Titles for per-section index pages. Can be either one string where "{name}"
# is substituted or the POSTS_SECTION_NAME, or a dict of sections. Note
# that the INDEX_PAGES option is also applied to section page titles.
# POSTS_SECTION_TITLE = {
# DEFAULT_LANG: {
# 'how-to': 'How-to and Tutorials',
# },
# }

# Paths for different autogenerated bits. These are combined with the
# translation paths.

Expand Down
1 change: 1 addition & 0 deletions nikola/data/themes/base-jinja/templates/base_helper.tmpl
Expand Up @@ -33,6 +33,7 @@ lang="{{ lang }}">
{% endif %}

{{ html_stylesheets() }}
<meta content="{{ theme_color }}" name="theme-color">
{{ html_feedlinks() }}
<link rel="canonical" href="{{ abs_link(permalink) }}">

Expand Down
21 changes: 21 additions & 0 deletions nikola/data/themes/base-jinja/templates/sectionindex.tmpl
@@ -0,0 +1,21 @@
{# -*- coding: utf-8 -*- #}
{% extends 'index.tmpl' %}

{% block extra_head %}
{{ super() }}
{% if generate_atom %}
<link rel="alternate" type="application/atom+xml" title="Atom for the {{ posts[0].section_name() }} section" href="${_link('section_index_atom', posts[0].section_slug())}">
{% endif %}
{% endblock %}

{% block content %}
<div class="sectionindex">
<header>
<h2><a href="{{ posts[0].section_link() }}">{{ title }}</a></h2>
{% if generate_atom %}
<p class="feedlink"><a href="{{ _link('section_index_atom', posts[0].section_slug()) }}" type="application/atom+xml">{{ messages('Updates') }}</a></p>
{% endif %}
</header>
{{ parent.content() }}
</article>
{% endblock %}
2 changes: 2 additions & 0 deletions nikola/data/themes/base/messages/messages_en.py
Expand Up @@ -36,4 +36,6 @@
"Write your post here.": "Write your post here.",
"old posts, page %d": "old posts, page %d",
"page %d": "page %d",
"Uncategorized": "Uncategorized",
"Updates": "Updates"
}
1 change: 1 addition & 0 deletions nikola/data/themes/base/templates/base_helper.tmpl
Expand Up @@ -33,6 +33,7 @@ lang="${lang}">
%endif

${html_stylesheets()}
<meta content="${theme_color}" name="theme-color">
${html_feedlinks()}
<link rel="canonical" href="${abs_link(permalink)}">

Expand Down
21 changes: 21 additions & 0 deletions nikola/data/themes/base/templates/sectionindex.tmpl
@@ -0,0 +1,21 @@
## -*- coding: utf-8 -*-
<%inherit file="index.tmpl"/>

<%block name="extra_head">
${parent.extra_head()}
% if generate_atom:
<link rel="alternate" type="application/atom+xml" title="Atom for the ${posts[0].section_name()} section" href="${_link('section_index_atom', posts[0].section_slug())}">
% endif
</%block>

<%block name="content">
<div class="sectionindex">
<header>
<h2><a href="${posts[0].section_link()}">${title}</a></h2>
% if generate_atom:
<p class="feedlink"><a href="${_link('section_index_atom', posts[0].section_slug())}" type="application/atom+xml">${messages('Updates')}</a></p>
% endif
</header>
${parent.content()}
</article>
</%block>
Expand Up @@ -38,6 +38,7 @@ lang="{{ lang }}">
{% endif %}

{{ html_stylesheets() }}
<meta content="{{ theme_color }}" name="theme-color">
{{ html_feedlinks() }}
<link rel="canonical" href="{{ abs_link(permalink) }}">

Expand Down
1 change: 1 addition & 0 deletions nikola/data/themes/bootstrap3/templates/base_helper.tmpl
Expand Up @@ -38,6 +38,7 @@ lang="${lang}">
%endif

${html_stylesheets()}
<meta content="${theme_color}" name="theme-color">
${html_feedlinks()}
<link rel="canonical" href="${abs_link(permalink)}">

Expand Down
15 changes: 14 additions & 1 deletion nikola/nikola.py
Expand Up @@ -418,6 +418,12 @@ def __init__(self, **config):
'OLD_THEME_SUPPORT': True,
'OUTPUT_FOLDER': 'output',
'POSTS': (("posts/*.txt", "posts", "post.tmpl"),),
'POSTS_SECTIONS': True,
'POSTS_SECTION_ARE_INDEXES': True,
'POSTS_SECTION_DESCRIPTIONS': "",
'POSTS_SECTION_FROM_META': False,
'POSTS_SECTION_NAME': "",
'POSTS_SECTION_TITLE': "{name}",
'PAGES': (("stories/*.txt", "stories", "story.tmpl"),),
'PANDOC_OPTIONS': [],
'PRETTY_URLS': False,
Expand Down Expand Up @@ -452,6 +458,7 @@ def __init__(self, **config):
'TAGLIST_MINIMUM_POSTS': 1,
'TEMPLATE_FILTERS': {},
'THEME': 'bootstrap3',
'THEME_COLOR': '#5670d4', # light "corporate blue"
'THEME_REVEAL_CONFIG_SUBTHEME': 'sky',
'THEME_REVEAL_CONFIG_TRANSITION': 'cube',
'THUMBNAIL_SIZE': 180,
Expand Down Expand Up @@ -514,6 +521,10 @@ def __init__(self, **config):
'INDEX_READ_MORE_LINK',
'RSS_READ_MORE_LINK',
'INDEXES_TITLE',
'POSTS_SECTION_COLORS',
'POSTS_SECTION_DESCRIPTIONS',
'POSTS_SECTION_NAME',
'POSTS_SECTION_TITLE',
'INDEXES_PAGES',
'INDEXES_PRETTY_PAGE_URL',)

Expand Down Expand Up @@ -837,13 +848,16 @@ def _set_global_context(self):
self._GLOBAL_CONTEXT['index_file'] = self.config['INDEX_FILE']
self._GLOBAL_CONTEXT['use_bundles'] = self.config['USE_BUNDLES']
self._GLOBAL_CONTEXT['use_cdn'] = self.config.get("USE_CDN")
self._GLOBAL_CONTEXT['theme_color'] = self.config.get("THEME_COLOR")
self._GLOBAL_CONTEXT['favicons'] = self.config['FAVICONS']
self._GLOBAL_CONTEXT['date_format'] = self.config.get('DATE_FORMAT')
self._GLOBAL_CONTEXT['blog_author'] = self.config.get('BLOG_AUTHOR')
self._GLOBAL_CONTEXT['blog_title'] = self.config.get('BLOG_TITLE')
self._GLOBAL_CONTEXT['show_blog_title'] = self.config.get('SHOW_BLOG_TITLE')
self._GLOBAL_CONTEXT['logo_url'] = self.config.get('LOGO_URL')
self._GLOBAL_CONTEXT['blog_description'] = self.config.get('BLOG_DESCRIPTION')
self._GLOBAL_CONTEXT['color_hsl_adjust_hex'] = utils.color_hsl_adjust_hex
self._GLOBAL_CONTEXT['colorize_str_from_base_color'] = utils.colorize_str_from_base_color

# TODO: remove in v8
self._GLOBAL_CONTEXT['blog_desc'] = self.config.get('BLOG_DESCRIPTION')
Expand Down Expand Up @@ -1310,7 +1324,6 @@ def path(self, kind, name, lang=None, is_link=False):
try:
path = self.path_handlers[kind](name, lang)
path = [os.path.normpath(p) for p in path if p != '.'] # Fix Issue #1028

if is_link:
link = '/' + ('/'.join(path))
index_len = len(self.config['INDEX_FILE'])
Expand Down

0 comments on commit 0b24500

Please sign in to comment.