Skip to content

Commit

Permalink
Merge pull request #3585 from getnikola/fix-3584-category-tag-titles-…
Browse files Browse the repository at this point in the history
…descriptions-context

Include {CATEGORY,TAG},{TITLES,DESCRIPTIONS} in tags.tmpl context
  • Loading branch information
Kwpolska committed Nov 9, 2021
2 parents 334000e + 5ae1437 commit bad0fc3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Add ``category_titles``, ``category_descriptions``, ``tag_titles``,
``tag_descriptions`` to default context of tags page (Issue #3584)
* Add Maori translation
* Add Occitan translation
* New ``auto_command_starting`` signal when ``nikola auto`` is
Expand All @@ -19,6 +21,8 @@ Features
Bugfixes
--------

* Make ``CATEGORY_TITLES``, ``CATEGORY_DESCRIPTIONS``, ``TAG_TITLES``,
``TAG_DESCRIPTIONS`` translatable settings for consistency (Issue #3584)
* Fix bug with posts after the first one appearing shifted due to a
``<div>`` closed too early (Issue #3573, #3564)
* Fix support for files outside of site root directory on Windows
Expand Down
16 changes: 10 additions & 6 deletions docs/template-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,16 @@ Variables available in the “Tags and categories” page (``tags.tmpl``)

.. class:: table table-bordered table-striped

============== ====== ===========================================================================================================
Name Type Description
============== ====== ===========================================================================================================
``items`` list Tags *(name, link)*
``cat_items`` list Categories *(name, full name, path, link, indent levels, indent to change before, indent to change after)*
============== ====== ===========================================================================================================
======================== ====== ===========================================================================================================
Name Type Description
======================== ====== ===========================================================================================================
``items`` list Tags *(name, link)*
``cat_items`` list Categories *(name, full name, path, link, indent levels, indent to change before, indent to change after)*
``category_titles`` dict ``CATEGORY_TITLES`` setting (dict for the current language only)
``category_descriptions`` dict ``CATEGORY_DESCRIPTIONS`` setting (dict for the current language only)
``tag_titles`` dict ``TAG_TITLES`` setting (dict for the current language only)
``tag_descriptions`` dict ``TAG_DESCRIPTIONS`` setting (dict for the current language only)
======================== ====== ===========================================================================================================

For more details about hierarchies, see `Hierarchical lists`_

Expand Down
4 changes: 4 additions & 0 deletions nikola/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ COMPILERS = ${COMPILERS}
# Set descriptions for tag pages to make them more interesting. The
# default is no description. The value is used in the meta description
# and displayed underneath the tag list or index page’s title.
# (translatable)
# TAG_DESCRIPTIONS = {
# DEFAULT_LANG: {
# "blogging": "Meta-blog posts about blogging.",
Expand All @@ -325,6 +326,7 @@ COMPILERS = ${COMPILERS}
# }

# Set special titles for tag pages. The default is "Posts about TAG".
# (translatable)
# TAG_TITLES = {
# DEFAULT_LANG: {
# "blogging": "Meta-posts about blogging",
Expand Down Expand Up @@ -390,6 +392,7 @@ CATEGORY_OUTPUT_FLAT_HIERARCHY = ${CATEGORY_OUTPUT_FLAT_HIERARCHY}
# Set descriptions for category pages to make them more interesting. The
# default is no description. The value is used in the meta description
# and displayed underneath the category list or index page’s title.
# (translatable)
# CATEGORY_DESCRIPTIONS = {
# DEFAULT_LANG: {
# "blogging": "Meta-blog posts about blogging.",
Expand All @@ -398,6 +401,7 @@ CATEGORY_OUTPUT_FLAT_HIERARCHY = ${CATEGORY_OUTPUT_FLAT_HIERARCHY}
# }

# Set special titles for category pages. The default is "Posts about CATEGORY".
# (translatable)
# CATEGORY_TITLES = {
# DEFAULT_LANG: {
# "blogging": "Meta-posts about blogging",
Expand Down
4 changes: 4 additions & 0 deletions nikola/nikola.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ def __init__(self, **config):
'FEED_READ_MORE_LINK',
'INDEXES_TITLE',
'CATEGORY_DESTPATH_NAMES',
'CATEGORY_TITLES',
'CATEGORY_DESCRIPTIONS',
'TAG_TITLES',
'TAG_DESCRIPTIONS',
'INDEXES_PAGES',
'INDEXES_PRETTY_PAGE_URL',
'THEME_CONFIG',
Expand Down
6 changes: 4 additions & 2 deletions nikola/plugins/task/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def provide_overview_context_and_uptodate(self, lang):
"title": self.site.MESSAGES[lang]["Categories"],
"description": self.site.MESSAGES[lang]["Categories"],
"pagekind": ["list", "tags_page"],
"category_descriptions": self.site.config['CATEGORY_DESCRIPTIONS'](lang),
"category_titles": self.site.config['CATEGORY_TITLES'](lang),
}
kw.update(context)
return context, kw
Expand All @@ -209,8 +211,8 @@ def provide_context_and_uptodate(self, classification, lang, node=None):
subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang)) for child in children]
friendly_name = self.get_classification_friendly_name(classification, lang)
context = {
"title": self.site.config['CATEGORY_TITLES'].get(lang, {}).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),
"description": self.site.config['CATEGORY_DESCRIPTIONS'].get(lang, {}).get(classification),
"title": self.site.config['CATEGORY_TITLES'](lang).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),
"description": self.site.config['CATEGORY_DESCRIPTIONS'](lang).get(classification),
"pagekind": ["tag_page", "index" if self.show_list_as_index else "list"],
"tag": friendly_name,
"category": classification,
Expand Down
6 changes: 4 additions & 2 deletions nikola/plugins/task/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def provide_overview_context_and_uptodate(self, lang):
"title": self.site.MESSAGES[lang]["Tags"],
"description": self.site.MESSAGES[lang]["Tags"],
"pagekind": ["list", "tags_page"],
"tag_descriptions": self.site.config['TAG_DESCRIPTIONS'](lang),
"tag_titles": self.site.config['TAG_TITLES'](lang),
}
kw.update(context)
return context, kw
Expand All @@ -143,8 +145,8 @@ def provide_context_and_uptodate(self, classification, lang, node=None):
"tag_titles": self.site.config['TAG_TITLES'],
}
context = {
"title": self.site.config['TAG_TITLES'].get(lang, {}).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % classification),
"description": self.site.config['TAG_DESCRIPTIONS'].get(lang, {}).get(classification),
"title": self.site.config['TAG_TITLES'](lang).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % classification),
"description": self.site.config['TAG_DESCRIPTIONS'](lang).get(classification),
"pagekind": ["tag_page", "index" if self.show_list_as_index else "list"],
"tag": classification,
}
Expand Down

0 comments on commit bad0fc3

Please sign in to comment.