Skip to content
Permalink
Browse files

Fix #1962 -- add (TAG|CATEGORY)_PAGES_TITLES

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Aug 22, 2015
1 parent b6dcebf commit 0c7b3628323552c87e5ac8ae6c4859a99e642a51
Showing with 36 additions and 2 deletions.
  1. +9 −0 CHANGES.txt
  2. +15 −0 nikola/conf.py.in
  3. +2 −0 nikola/nikola.py
  4. +10 −2 nikola/plugins/task/tags.py
@@ -1,3 +1,12 @@
New in master
=============

Features
--------

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

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

@@ -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.
@@ -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.
@@ -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,
@@ -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',
@@ -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()
@@ -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
@@ -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)
@@ -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

0 comments on commit 0c7b362

Please sign in to comment.