Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
POSTS_CATEGORY_TITLES for every preference
  • Loading branch information
da2x committed Aug 27, 2015
1 parent ea8738b commit bd27b76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions nikola/conf.py.in
Expand Up @@ -254,6 +254,15 @@ POSTS_CATEGORY_DESCRIPTIONS = {
# },
# }

# 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 = {
DEFAULT_LANG: {
'how-to': 'How-to and Tutorials',
},
}

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

Expand Down
14 changes: 10 additions & 4 deletions nikola/plugins/task/indexes.py
Expand Up @@ -102,8 +102,6 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
if self.site.config['POSTS_CATEGORIES']:

kw["posts_category_are_indexes"] = self.site.config['POSTS_CATEGORY_ARE_INDEXES']
kw["posts_category_title"] = self.site.config['POSTS_CATEGORY_TITLE'](lang)

index_len = len(kw['index_file'])

groups = defaultdict(list)
Expand All @@ -115,7 +113,6 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
continue

for dirname, 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][dirname] = (len(post_list) + kw['index_display_post_count'] - 1) // kw['index_display_post_count']
Expand All @@ -142,7 +139,16 @@ def cat_path(i, displayed_i, num_pages, force_addition, extension=None):

if kw["posts_category_are_indexes"]:
context["pagekind"].append("index")
indexes_title = post_list[0].category_name(lang) # all posts in the list share category name
kw["posts_category_title"] = self.site.config['POSTS_CATEGORY_TITLE'](lang)
if type(kw["posts_category_title"]) is dict:
if dirname in kw["posts_category_title"]:
indexes_title = kw["posts_category_title"][dirname]
elif type(kw["posts_category_title"]) is str:
indexes_title = kw["posts_category_title"]
if not indexes_title:
indexes_title = post_list[0].category_name(lang)
indexes_title = indexes_title.format(post_list[0].category_name(lang))

task = self.site.generic_index_renderer(lang, post_list, indexes_title, "categoryindex.tmpl", context, kw, self.name, cat_link, cat_path)
else:
context["pagekind"].append("list")
Expand Down

0 comments on commit bd27b76

Please sign in to comment.