Skip to content

Commit

Permalink
Fix #1962 -- add (TAG|CATEGORY)_PAGES_TITLES
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Aug 22, 2015
1 parent b6dcebf commit 0c7b362
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,12 @@
New in master
=============

Features
--------

* New ``TAG_PAGES_TITLES`` and ``CATEGORY_PAGES_TITLES`` options
(Issue #1962)

New in v7.6.4
=============

Expand Down
15 changes: 15 additions & 0 deletions nikola/conf.py.in
Expand Up @@ -231,6 +231,13 @@ WRITE_TAG_CLOUD = True
# },
# }

# Set special titles for tag pages. The default is "Posts about TAG".
# TAG_PAGES_TITLES = {
# DEFAULT_LANG: {
# "blogging": "Meta-posts about blogging",
# "open source": "Posts about open source software"
# },
# }

# If you do not want to display a tag publicly, you can mark it as hidden.
# The tag will not be displayed on the tag list page, the tag cloud and posts.
Expand Down Expand Up @@ -274,6 +281,14 @@ CATEGORY_OUTPUT_FLAT_HIERARCHY = ${CATEGORY_OUTPUT_FLAT_HIERARCHY}
# },
# }

# Set special titles for category pages. The default is "Posts about CATEGORY".
# CATEGORY_PAGES_TITLES = {
# DEFAULT_LANG: {
# "blogging": "Meta-posts about blogging",
# "open source": "Posts about open source software"
# },
# }

# If you do not want to display a category publicly, you can mark it as hidden.
# The category will not be displayed on the category list page.
# Category pages will still be generated.
Expand Down
2 changes: 2 additions & 0 deletions nikola/nikola.py
Expand Up @@ -343,6 +343,7 @@ def __init__(self, **config):
'CATEGORY_PATH': None, # None means: same as TAG_PATH
'CATEGORY_PAGES_ARE_INDEXES': None, # None means: same as TAG_PAGES_ARE_INDEXES
'CATEGORY_PAGES_DESCRIPTIONS': {},
'CATEGORY_PAGES_TITLES': {},
'CATEGORY_PREFIX': 'cat_',
'CATEGORY_ALLOW_HIERARCHIES': False,
'CATEGORY_OUTPUT_FLAT_HIERARCHY': False,
Expand Down Expand Up @@ -447,6 +448,7 @@ def __init__(self, **config):
'TAG_PATH': 'categories',
'TAG_PAGES_ARE_INDEXES': False,
'TAG_PAGES_DESCRIPTIONS': {},
'TAG_PAGES_TITLES': {},
'TAGLIST_MINIMUM_POSTS': 1,
'TEMPLATE_FILTERS': {},
'THEME': 'bootstrap3',
Expand Down
12 changes: 10 additions & 2 deletions nikola/plugins/task/tags.py
Expand Up @@ -84,6 +84,10 @@ def gen_tasks(self):
"pretty_urls": self.site.config['PRETTY_URLS'],
"strip_indexes": self.site.config['STRIP_INDEXES'],
"index_file": self.site.config['INDEX_FILE'],
"category_pages_descriptions": self.site.config['CATEGORY_PAGES_DESCRIPTIONS'],
"category_pages_titles": self.site.config['CATEGORY_PAGES_TITLES'],
"tag_pages_descriptions": self.site.config['TAG_PAGES_DESCRIPTIONS'],
"tag_pages_titles": self.site.config['TAG_PAGES_TITLES'],
}

self.site.scan_posts()
Expand Down Expand Up @@ -251,6 +255,10 @@ def _get_title(self, tag, is_category):
else:
return tag

def _get_indexes_title(self, tag, is_category, lang, messages):
titles = self.site.config['CATEGORY_PAGES_TITLES'] if is_category else self.site.config['TAG_PAGES_TITLES']
return titles[lang][tag] if lang in titles and tag in titles[lang] else messages[lang]["Posts about %s"] % tag

def _get_description(self, tag, is_category, lang):
descriptions = self.site.config['CATEGORY_PAGES_DESCRIPTIONS'] if is_category else self.site.config['TAG_PAGES_DESCRIPTIONS']
return descriptions[lang][tag] if lang in descriptions and tag in descriptions[lang] else None
Expand Down Expand Up @@ -284,7 +292,7 @@ def page_path(i, displayed_i, num_pages, force_addition, extension=None):
context_source["category"] = tag
context_source["category_path"] = self.site.parse_category_name(tag)
context_source["tag"] = title
indexes_title = kw["messages"][lang]["Posts about %s"] % title
indexes_title = self._get_indexes_title(title, is_category, lang, kw["messages"])
context_source["description"] = self._get_description(tag, is_category, lang)
if is_category:
context_source["subcategories"] = self._get_subcategories(tag)
Expand All @@ -306,7 +314,7 @@ def tag_page_as_list(self, tag, lang, post_list, kw, is_category):
context["category"] = tag
context["category_path"] = self.site.parse_category_name(tag)
context["tag"] = title
context["title"] = kw["messages"][lang]["Posts about %s"] % title
context["title"] = self._get_indexes_title(title, is_category, lang, kw["messages"])
context["posts"] = post_list
context["permalink"] = self.site.link(kind, tag, lang)
context["kind"] = kind
Expand Down

0 comments on commit 0c7b362

Please sign in to comment.