Skip to content

Commit

Permalink
Rename POSTS_CATEGORY to POSTS_SECTION
Browse files Browse the repository at this point in the history
  • Loading branch information
da2x committed Aug 28, 2015
1 parent f288de1 commit f15c6c3
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 124 deletions.
16 changes: 8 additions & 8 deletions CHANGES.txt
Expand Up @@ -8,15 +8,15 @@ Features
(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 categories by deault
* New ``POSTS`` output subfolders now generate sections by deault
(Issue #1980)
* New ``POSTS_CATEGORIES`` and ``POSTS_CATEGORY_*`` options for
configuring the new category pages (Issue #1980)
* For themers: Each ``post`` are now asssociated with category_color,
category_link, and category_name (Issue #1980)
* Each new category page has a auto-assigned color based on shifting
the hue of ``THEME_COLOR`` based on a hash of the category name,
can be overwritten with ``POSTS_CATEGORY_COLORS`` option (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)

Expand Down
18 changes: 9 additions & 9 deletions docs/theming.txt
Expand Up @@ -193,20 +193,20 @@ 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 category colors
--------------------------------------------------------------
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 category has an assigned color that is either set by the user or auto
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.category_color(lang)``. The function that
generates the colors from strings and any given color (by category name and
theme color for categories) is expoed through the
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 category color can be
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
Expand Down Expand Up @@ -271,12 +271,12 @@ List of page kinds provided by default plugins:
* index, archive_page
* index, author_page
* index, main_index
* index, posts_category_page
* index, section_page
* index, tag_page
* list
* list, archive_page
* list, author_page
* list, posts_category_page
* list, section_page
* list, tag_page
* list, tags_page
* post_page
Expand Down
36 changes: 18 additions & 18 deletions nikola/conf.py.in
Expand Up @@ -90,7 +90,7 @@ NAVIGATION_LINKS = ${NAVIGATION_LINKS}
THEME = ${THEME}

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

##############################################
Expand Down Expand Up @@ -212,52 +212,52 @@ COMPILERS = ${COMPILERS}
# Warning: this option will change its default value to False in v8!
WRITE_TAG_CLOUD = True

# Generate pages for categories. The site must have at least two categories
# for this option to take effect. It wouldn't build for just one category.
POSTS_CATEGORIES = True
# Generate pages for each section. The site must have at least two categories
# 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_CATEGORY_ARE_INDEXES = True
# POSTS_SECTIONS_ARE_INDEXES = True

# Each post and category page will have an associated color that can be used
# 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 category based on shifting the hue of your THEME_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_CATEGORY_COLORS = {
# POSTS_SECTION_COLORS = {
# DEFAULT_LANG: {
# 'posts': '#49b11bf',
# 'reviews': '#ffe200',
# },
# }

# Associate a description with a category. For use in meta description on
# category index pages or elsewhere in themes.
# POSTS_CATEGORY_DESCRIPTIONS = {
# 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.',
# },
# }

# Categories are determined by their output directory set in POSTS by default,
# Sections are determined by their output directory as set in POSTS by default,
# but can alternatively be determined from file metadata instead.
# POSTS_CATEGORY_FROM_META = False
# 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_CATEGORY_NAME = {
# POSTS_SECTION_NAME = {
# DEFAULT_LANG: {
# 'posts': 'Blog Posts',
# 'uncategorized': 'Odds and Ends',
# },
# }

# Titles for per-category index pages. Can be either one string where "%s"
# is substituted or the POSTS_CATEGORY_NAME, or a dict of categories. Note
# that the INDEX_PAGES option is also applied to category page titles.
# POSTS_CATEGORY_TITLE = {
# Titles for per-section index pages. Can be either one string where "%s"
# 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',
# },
Expand Down
21 changes: 0 additions & 21 deletions nikola/data/themes/base-jinja/templates/categoryindex.tmpl

This file was deleted.

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 %}
Expand Up @@ -4,16 +4,16 @@
<%block name="extra_head">
${parent.extra_head()}
% if generate_atom:
<link rel="alternate" type="application/atom+xml" title="Atom for the ${posts[0].category_name()} section" href="/FIXME">
<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="categoryindex">
<div class="sectionindex">
<header>
<h2><a href="${posts[0].category_link()}">${title}</a></h2>
<h2><a href="${posts[0].section_link()}">${title}</a></h2>
% if generate_atom:
<p class="feedlink"><a href="${_link('cat_index_atom', posts[0].category_slug())}" type="application/atom+xml">${messages('Updates')}</a></p>
<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()}
Expand Down
20 changes: 10 additions & 10 deletions nikola/nikola.py
Expand Up @@ -418,12 +418,12 @@ def __init__(self, **config):
'OLD_THEME_SUPPORT': True,
'OUTPUT_FOLDER': 'output',
'POSTS': (("posts/*.txt", "posts", "post.tmpl"),),
'POSTS_CATEGORIES': True,
'POSTS_CATEGORY_ARE_INDEXES': True,
'POSTS_CATEGORY_DESCRIPTIONS': "",
'POSTS_CATEGORY_FROM_META': False,
'POSTS_CATEGORY_NAME': "",
'POSTS_CATEGORY_TITLE': "%s",
'POSTS_SECTIONS': True,
'POSTS_SECTION_ARE_INDEXES': True,
'POSTS_SECTION_DESCRIPTIONS': "",
'POSTS_SECTION_FROM_META': False,
'POSTS_SECTION_NAME': "",
'POSTS_SECTION_TITLE': "%s",
'PAGES': (("stories/*.txt", "stories", "story.tmpl"),),
'PANDOC_OPTIONS': [],
'PRETTY_URLS': False,
Expand Down Expand Up @@ -521,10 +521,10 @@ def __init__(self, **config):
'INDEX_READ_MORE_LINK',
'RSS_READ_MORE_LINK',
'INDEXES_TITLE',
'POSTS_CATEGORY_COLORS',
'POSTS_CATEGORY_DESCRIPTIONS',
'POSTS_CATEGORY_NAME',
'POSTS_CATEGORY_TITLE',
'POSTS_SECTION_COLORS',
'POSTS_SECTION_DESCRIPTIONS',
'POSTS_SECTION_NAME',
'POSTS_SECTION_TITLE',
'INDEXES_PAGES',
'INDEXES_PRETTY_PAGE_URL',)

Expand Down
74 changes: 37 additions & 37 deletions nikola/plugins/task/indexes.py
Expand Up @@ -48,8 +48,8 @@ def set_site(self, site):
"""Set Nikola site."""
site.register_path_handler('index', self.index_path)
site.register_path_handler('index_atom', self.index_atom_path)
site.register_path_handler('cat_index', self.index_cat_path)
site.register_path_handler('cat_index_atom', self.index_cat_atom_path)
site.register_path_handler('section_index', self.index_section_path)
site.register_path_handler('section_index_atom', self.index_section_atom_path)
return super(Indexes, self).set_site(site)

def gen_tasks(self):
Expand All @@ -74,7 +74,7 @@ def gen_tasks(self):
template_name = "index.tmpl"
posts = self.site.posts
self.number_of_pages = dict()
self.number_of_pages_cat = dict()
self.number_of_pages_section = dict()
for lang in kw["translations"]:
def page_link(i, displayed_i, num_pages, force_addition, extension=None):
feed = "_atom" if extension == ".atom" else ""
Expand All @@ -99,62 +99,62 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):

yield self.site.generic_index_renderer(lang, filtered_posts, indexes_title, template_name, context, kw, 'render_indexes', page_link, page_path)

if self.site.config['POSTS_CATEGORIES']:
if self.site.config['POSTS_SECTIONS']:

kw["posts_category_are_indexes"] = self.site.config['POSTS_CATEGORY_ARE_INDEXES']
kw["posts_section_are_indexes"] = self.site.config['POSTS_SECTION_ARE_INDEXES']
index_len = len(kw['index_file'])

groups = defaultdict(list)
for p in filtered_posts:
groups[p.category_slug(lang)].append(p)
groups[p.section_slug(lang)].append(p)

# don't build categories when there is only one, aka. default setups
# don't build sections when there is only one, aka. default setups
if not len(groups.items()) > 1:
continue

for category_slug, post_list in groups.items():
if lang not in self.number_of_pages_cat:
self.number_of_pages_cat[lang] = dict()
self.number_of_pages_cat[lang][category_slug] = (len(post_list) + kw['index_display_post_count'] - 1) // kw['index_display_post_count']
for section_slug, post_list in groups.items():
if lang not in self.number_of_pages_section:
self.number_of_pages_section[lang] = dict()
self.number_of_pages_section[lang][section_slug] = (len(post_list) + kw['index_display_post_count'] - 1) // kw['index_display_post_count']

def cat_link(i, displayed_i, num_pages, force_addition, extension=None):
feed = "_atom" if extension == ".atom" else ""
return utils.adjust_name_for_index_link(self.site.link("cat_index" + feed, category_slug, lang), i, displayed_i,
return utils.adjust_name_for_index_link(self.site.link("section_index" + feed, section_slug, lang), i, displayed_i,
lang, self.site, force_addition, extension)

def cat_path(i, displayed_i, num_pages, force_addition, extension=None):
feed = "_atom" if extension == ".atom" else ""
return utils.adjust_name_for_index_path(self.site.path("cat_index" + feed, category_slug, lang), i, displayed_i,
return utils.adjust_name_for_index_path(self.site.path("section_index" + feed, section_slug, lang), i, displayed_i,
lang, self.site, force_addition, extension)

context = {}

short_destination = os.path.join(category_slug, kw['index_file'])
short_destination = os.path.join(section_slug, kw['index_file'])
link = short_destination.replace('\\', '/')
if kw['strip_indexes'] and link[-(1 + index_len):] == '/' + kw['index_file']:
link = link[:-index_len]
context["permalink"] = link
context["pagekind"] = ["posts_category_page"]
context["description"] = self.site.config['POSTS_CATEGORY_DESCRIPTIONS'](lang)[category_slug] if category_slug in self.site.config['POSTS_CATEGORY_DESCRIPTIONS'](lang) else ""
context["pagekind"] = ["section_page"]
context["description"] = self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang)[section_slug] if section_slug in self.site.config['POSTS_SECTION_DESCRIPTIONS'](lang) else ""

if kw["posts_category_are_indexes"]:
if kw["posts_section_are_indexes"]:
context["pagekind"].append("index")
kw["posts_category_title"] = self.site.config['POSTS_CATEGORY_TITLE'](lang)

category_title = None
if type(kw["posts_category_title"]) is dict:
if category_slug in kw["posts_category_title"]:
category_title = kw["posts_category_title"][category_slug]
elif type(kw["posts_category_title"]) is str:
category_title = kw["posts_category_title"]
if not category_title:
category_title = post_list[0].category_name(lang)
category_title = category_title.format(post_list[0].category_name(lang))

task = self.site.generic_index_renderer(lang, post_list, category_title, "categoryindex.tmpl", context, kw, self.name, cat_link, cat_path)
kw["posts_section_title"] = self.site.config['POSTS_SECTION_TITLE'](lang)

section_title = None
if type(kw["posts_section_title"]) is dict:
if section_slug in kw["posts_section_title"]:
section_title = kw["posts_section_title"][section_slug]
elif type(kw["posts_section_title"]) is str:
section_title = kw["posts_section_title"]
if not section_title:
section_title = post_list[0].section_name(lang)
section_title = section_title.format(post_list[0].section_name(lang))

task = self.site.generic_index_renderer(lang, post_list, section_title, "sectionindex.tmpl", context, kw, self.name, cat_link, cat_path)
else:
context["pagekind"].append("list")
output_name = os.path.join(kw['output_folder'], category_slug, kw['index_file'])
output_name = os.path.join(kw['output_folder'], section_slug, kw['index_file'])
task = self.site.generic_post_list_renderer(lang, post_list, output_name, "list.tmpl", kw['filters'], context)
task['uptodate'] = [utils.config_changed(kw, 'nikola.plugins.task.indexes')]
task['basename'] = self.name
Expand Down Expand Up @@ -233,8 +233,8 @@ def index_path(self, name, lang, is_feed=False):
self.site,
extension=extension)

def index_cat_path(self, name, lang, is_feed=False):
"""Return path to an index."""
def index_section_path(self, name, lang, is_feed=False):
"""Return path to an index for sections."""
extension = None

if is_feed:
Expand All @@ -246,7 +246,7 @@ def index_cat_path(self, name, lang, is_feed=False):
name,
index_file] if _f],
None,
utils.get_displayed_page_number(None, self.number_of_pages_cat[lang][name], self.site),
utils.get_displayed_page_number(None, self.number_of_pages_section[lang][name], self.site),
lang,
self.site,
extension=extension)
Expand All @@ -255,6 +255,6 @@ def index_atom_path(self, name, lang):
"""Return path to an Atom index."""
return self.index_path(name, lang, is_feed=True)

def index_cat_atom_path(self, name, lang):
"""Return path to an Atom index for categories."""
return self.index_cat_path(name, lang, is_feed=True)
def index_section_atom_path(self, name, lang):
"""Return path to an Atom index for sections."""
return self.index_section_path(name, lang, is_feed=True)

0 comments on commit f15c6c3

Please sign in to comment.