Skip to content
Permalink
Browse files
Merge pull request #2778 from getnikola/taxonomy-lang-refs
First shot on #993 for taxonomies, in particular archives.
  • Loading branch information
Kwpolska committed Jun 11, 2017
2 parents 4e6c32c + 15e9a9a commit afe6799770f7d23fc0dd93d2faef2d0d233179e8
Showing with 840 additions and 369 deletions.
  1. +6 −0 CHANGES.txt
  2. +56 −43 docs/template-variables.rst
  3. +33 −0 nikola/conf.py.in
  4. +3 −2 nikola/data/themes/base-jinja/templates/archiveindex.tmpl
  5. +3 −3 nikola/data/themes/base-jinja/templates/author.tmpl
  6. +2 −2 nikola/data/themes/base-jinja/templates/authorindex.tmpl
  7. +3 −3 nikola/data/themes/base-jinja/templates/base_helper.tmpl
  8. +23 −1 nikola/data/themes/base-jinja/templates/{feed_helper.tmpl → feeds_translations_helper.tmpl}
  9. +4 −1 nikola/data/themes/base-jinja/templates/index.tmpl
  10. +2 −0 nikola/data/themes/base-jinja/templates/list.tmpl
  11. +2 −0 nikola/data/themes/base-jinja/templates/list_post.tmpl
  12. +3 −3 nikola/data/themes/base-jinja/templates/sectionindex.tmpl
  13. +4 −3 nikola/data/themes/base-jinja/templates/tag.tmpl
  14. +3 −2 nikola/data/themes/base-jinja/templates/tagindex.tmpl
  15. +8 −5 nikola/data/themes/base/assets/css/theme.css
  16. +3 −2 nikola/data/themes/base/templates/archiveindex.tmpl
  17. +3 −3 nikola/data/themes/base/templates/author.tmpl
  18. +2 −2 nikola/data/themes/base/templates/authorindex.tmpl
  19. +3 −3 nikola/data/themes/base/templates/base_helper.tmpl
  20. +23 −1 nikola/data/themes/base/templates/{feed_helper.tmpl → feeds_translations_helper.tmpl}
  21. +4 −1 nikola/data/themes/base/templates/index.tmpl
  22. +2 −0 nikola/data/themes/base/templates/list.tmpl
  23. +2 −0 nikola/data/themes/base/templates/list_post.tmpl
  24. +3 −3 nikola/data/themes/base/templates/sectionindex.tmpl
  25. +4 −3 nikola/data/themes/base/templates/tag.tmpl
  26. +3 −2 nikola/data/themes/base/templates/tagindex.tmpl
  27. +8 −5 nikola/data/themes/bootstrap3-jinja/assets/css/theme.css
  28. +3 −3 nikola/data/themes/bootstrap3-jinja/templates/base_helper.tmpl
  29. +8 −5 nikola/data/themes/bootstrap3/assets/css/theme.css
  30. +3 −3 nikola/data/themes/bootstrap3/templates/base_helper.tmpl
  31. +275 −0 nikola/hierarchy_utils.py
  32. +15 −5 nikola/nikola.py
  33. +27 −5 nikola/plugin_categories.py
  34. +3 −3 nikola/plugins/command/import_wordpress.py
  35. +4 −4 nikola/plugins/misc/taxonomies_classifier.py
  36. +8 −3 nikola/plugins/task/archive.py
  37. +21 −14 nikola/plugins/task/authors.py
  38. +24 −12 nikola/plugins/task/categories.py
  39. +18 −11 nikola/plugins/task/sections.py
  40. +15 −6 nikola/plugins/task/tags.py
  41. +80 −21 nikola/plugins/task/taxonomies.py
  42. +121 −181 nikola/utils.py
@@ -4,6 +4,12 @@ New in master
Features
--------

* Providing infrastructure for taxonomies for classification pages to
link to related classifications in other languages
* Added alternate links (visible and header) for archives and authors
(Issue #993)
* Added options to add alternative links (visible and header) for
tags, sections and categories.
* New METADATA_FORMAT option to choose preferred metadata format
(Nikola/YAML/TOML/Pelican) (Part of Issue #2801)
* Extract metadata from HTML meta and title tags like Pelican (Issue #1923)
@@ -247,14 +247,16 @@ Classification pages (lists)

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

============== ============== ===========================================================
Name Type Description
============== ============== ===========================================================
``items`` list? List of items for ``list.tmpl`` *(title, permalink, None)*
``posts`` list<Post>? List of items for other templates
``kind`` str The classification name
``permalink`` str Permanent link to page
============== ============== ===========================================================
=================== ============== =============================================================
Name Type Description
=================== ============== =============================================================
``kind`` str The classification name
``items`` list? List of items for ``list.tmpl`` *(title, permalink, None)*
``posts`` list<Post>? List of items for other templates
``kind`` str The classification name
``permalink`` str Permanent link to page
``other_languages`` list<tuple> List of triples ``(other_lang, other_classification, title)``
=================== ============== =============================================================

Index-style classification pages have ``kind`` in addtion to the usual index variables.

@@ -263,12 +265,13 @@ Subclassification page

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

============== ====== =======================
Name Type Description
============== ====== =======================
``items`` list? List of items
``permalink`` str Permanent link to page
============== ====== =======================
=================== =========== =============================================================
Name Type Description
=================== =========== =============================================================
``items`` list? List of items
``permalink`` str Permanent link to page
``other_languages`` list<tuple> List of triples ``(other_lang, other_classification, title)``
=================== =========== =============================================================

Hierarchical lists
~~~~~~~~~~~~~~~~~~
@@ -300,10 +303,11 @@ The archive navigation variables are available only if ``create_archive_navigati

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

============================== ============== ===============================================
============================== ============== ========================================================================
Name Type Description
============================== ============== ===============================================
``archive_name`` str? Name of the archive
============================== ============== ========================================================================
``kind`` str Always ``"archive"``
``archive_name`` str? Name of the archive (only if using indexes)
``create_archive_navigation`` bool ``CREATE_ARCHIVE_NAVIGATION`` setting
``has_archive_navigation`` bool Whether or not archive navigation is available
``up_archive`` str? Link to the archive one level up
@@ -313,36 +317,41 @@ Name Type Description
``next_archive`` str? Link to the next archive
``next_archive_name`` str? Name of the next archive
``archive_nodelevel`` int? Level of the archive
============================== ============== ===============================================
``other_languages`` list List of tuples ``(lang, path, name)`` of same archive in other languages
============================== ============== ========================================================================


Variables available in author pages
-----------------------------------

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

============== ====== ============================
Name Type Description
============== ====== ============================
``author`` str Author name
``rss_link`` str Link to RSS (HTML fragment)
============== ====== ============================
=================== =========== =========================================================================
Name Type Description
=================== =========== =========================================================================
``kind`` str Always ``"author"``
``author`` str Author name
``rss_link`` str Link to RSS (HTML fragment)
``other_languages`` list<tuple> List of tuples ``(lang, author, name)`` of same author in other languages
=================== =========== =========================================================================


Variables available in category pages
-------------------------------------

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

================== ========== =====================================================
Name Type Description
================== ========== =====================================================
``category`` str Category name
``category_path`` list<str> Category hierarchy
``rss_link`` str? Link to RSS (HTML fragment, only if using indexes)
``subcategories`` list List of subcategories (contains *name, link* tuples)
``tag`` str Friendly category name
================== ========== =====================================================
=================== =========== =============================================================================
Name Type Description
=================== =========== =============================================================================
``kind`` str Always ``"category"``
``category`` str Category name
``category_path`` list<str> Category hierarchy
``rss_link`` str? Link to RSS (HTML fragment, only if using indexes)
``subcategories`` list List of subcategories (contains *name, link* tuples)
``tag`` str Friendly category name
``other_languages`` list<tuple> List of tuples ``(lang, category, name)`` of same category in other languages
=================== =========== =============================================================================

Variables available in galleries
--------------------------------
@@ -383,22 +392,26 @@ Variables available in sections

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

=========== ===== ========================
Name Type Description
=========== ===== ========================
``section`` str Section name (internal)
=========== ===== ========================
=================== =========== ===========================================================================
Name Type Description
=================== =========== ===========================================================================
``section`` str Section name (internal)
``kind`` str Always ``"section"``
``other_languages`` list<tuple> List of tuples ``(lang, section, name)`` of same section in other languages
=================== =========== ===========================================================================

Variables available in tag pages
--------------------------------

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

========= ===== =================
Name Type Description
========= ===== =================
``tag`` str Tag name
========= ===== =================
=================== =========== ===================================================================
Name Type Description
=================== =========== ===================================================================
``kind`` str Always ``"tag"``
``tag`` str Tag name
``other_languages`` list<tuple> List of tuples ``(lang, tag, name)`` of same tag in other languages
=================== =========== ===================================================================

Variables available in the “Tags and categories” page (``tags.tmpl``)
---------------------------------------------------------------------
@@ -299,6 +299,19 @@ POSTS_SECTIONS = True
# },
# }

# A list of dictionaries specifying sections which translate to each other.
# For example:
# [
# {'en': 'private', 'de': 'Privat'},
# {'en': 'work', 'fr': 'travail', 'de': 'Arbeit'},
# ]
# POSTS_SECTION_TRANSLATIONS = []

# If set to True, a section in a language will be treated as a translation
# of the literally same section in all other languages. Enable this if you
# do not translate sections, for example.
# POSTS_SECTION_TRANSLATIONS_ADD_DEFAULTS = True

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

@@ -350,6 +363,16 @@ HIDDEN_TAGS = ['mathjax']
# However, more obscure tags can be hidden from the tag index page.
# TAGLIST_MINIMUM_POSTS = 1

# A list of dictionaries specifying tags which translate to each other.
# Format: a list of dicts {language: translation, language2: translation2, …}
# See POSTS_SECTION_TRANSLATIONS example above.
# TAG_TRANSLATIONS = []

# If set to True, a tag in a language will be treated as a translation
# of the literally same tag in all other languages. Enable this if you
# do not translate tags, for example.
# TAG_TRANSLATIONS_ADD_DEFAULTS = True

# Final locations are:
# output / TRANSLATION[lang] / CATEGORY_PATH / index.html (list of categories)
# output / TRANSLATION[lang] / CATEGORY_PATH / CATEGORY_PREFIX category.html (list of posts for a category)
@@ -403,6 +426,16 @@ CATEGORY_OUTPUT_FLAT_HIERARCHY = ${CATEGORY_OUTPUT_FLAT_HIERARCHY}
# Category pages will still be generated.
HIDDEN_CATEGORIES = []

# A list of dictionaries specifying categories which translate to each other.
# Format: a list of dicts {language: translation, language2: translation2, …}
# See POSTS_SECTION_TRANSLATIONS example above.
# CATEGORY_TRANSLATIONS = []

# If set to True, a category in a language will be treated as a translation
# of the literally same category in all other languages. Enable this if you
# do not translate categories, for example.
# CATEGORY_TRANSLATIONS_ADD_DEFAULTS = True

# If ENABLE_AUTHOR_PAGES is set to True and there is more than one
# author, author pages are generated.
# ENABLE_AUTHOR_PAGES = True
@@ -1,13 +1,14 @@
{# -*- coding: utf-8 -*- #}
{% extends 'index.tmpl' %}
{% import 'archive_navigation_helper.tmpl' as archive_nav with context %}
{% import 'feed_helper.tmpl' as feed with context %}
{% import 'feeds_translations_helper.tmpl' as feeds_translations with context %}

{% block extra_head %}
{{ super() }}
{{ feed.head(archive_name) }}
{{ feeds_translations.head(archive_name) }}
{% endblock %}

{% block content_header %}
{{ archive_nav.archive_navigation() }}
{{ parent.content_header() }}
{% endblock %}
@@ -1,10 +1,10 @@
{# -*- coding: utf-8 -*- #}
{% extends 'list_post.tmpl' %}
{% import 'feed_helper.tmpl' as feed with context %}
{% import 'feeds_translations_helper.tmpl' as feeds_translations with context %}

{% block extra_head %}
{{ super() }}
{{ feed.head(author) }}
{{ feeds_translations.head(author) }}
{% endblock %}


@@ -16,7 +16,7 @@
<p>{{ description }}</p>
{% endif %}
<div class="metadata">
{{ feed.link(author) }}
{{ feeds_translations.feed_link(author) }}
</div>
</header>
{% if posts %}
@@ -1,8 +1,8 @@
{# -*- coding: utf-8 -*- #}
{% extends 'index.tmpl' %}
{% import 'feed_helper.tmpl' as feed with context %}
{% import 'feeds_translations_helper.tmpl' as feeds_translations with context %}

{% block extra_head %}
{{ super() }}
{{ feed.head(author) }}
{{ feeds_translations.head(author) }}
{% endblock %}
@@ -1,5 +1,5 @@
{# -*- coding: utf-8 -*- #}
{% import 'feed_helper.tmpl' as feed with context %}
{% import 'feeds_translations_helper.tmpl' as feeds_translations with context %}

{% macro html_headstart() %}
<!DOCTYPE html>
@@ -42,7 +42,7 @@ lang="{{ lang }}">
{% if meta_generator_tag %}
<meta name="generator" content="Nikola (getnikola.com)">
{% endif %}
{{ feed.head() }}
{{ feeds_translations.head() }}
<link rel="canonical" href="{{ abs_link(permalink) }}">

{% if favicons %}
@@ -100,7 +100,7 @@ lang="{{ lang }}">

{# This function is deprecated; use feed_helper directly. #}
{% macro html_feedlinks() %}
{{ feed.head() }}
{{ feeds_translations.head() }}
{% endmacro %}

{% macro html_translations() %}
@@ -1,4 +1,6 @@
{# -*- coding: utf-8 -*- #}

{# Handles both feeds and translations #}
{% macro head(classification=None) %}
{% if rss_link %}
{{ rss_link }}
@@ -38,9 +40,14 @@
{% endif %}
{% endif %}
{% endif %}
{% if has_other_languages and other_languages %}
{% for language, classification, _ in other_languages %}
<link rel="alternate" hreflang="{{ language }}" href="{{ _link(kind, classification, language) }}">
{% endfor %}
{% endif %}
{% endmacro %}

{% macro link(classification) %}
{% macro feed_link(classification) %}
{% if translations|length > 1 %}
{% for language in translations|sort %}
{% if generate_atom or generate_rss %}
@@ -67,3 +74,18 @@
{% endif %}
{% endif %}
{% endmacro %}

{% macro translation_link() %}
{% if has_other_languages and other_languages %}
<div class="translationslist translations">
<h3 class="translationslist-intro">{{ messages("Also available in:") }}</h3>
{% for language, classification, name in other_languages %}
<p><a href="{{ _link(kind, classification, language) }}" rel="alternate">{{ messages("LANGUAGE", language) }}
{% if kind != 'archive' %}
({{ name|e }})
{% endif %}
</a></p>
{% endfor %}
</div>
{% endif %}
{% endmacro %}
@@ -3,6 +3,7 @@
{% import 'math_helper.tmpl' as math with context %}
{% import 'comments_helper.tmpl' as comments with context %}
{% import 'pagination_helper.tmpl' as pagination with context %}
{% import 'feeds_translations_helper.tmpl' as feeds_translations with context %}
{% extends 'base.tmpl' %}

{% block extra_head %}
@@ -14,7 +15,9 @@
{% endblock %}

{% block content %}
{% block content_header %}{% endblock %}
{% block content_header %}
{{ feeds_translations.translation_link() }}
{% endblock %}
{% if 'main_index' in pagekind %}
{{ front_index_header }}
{% endif %}
@@ -1,13 +1,15 @@
{# -*- coding: utf-8 -*- #}
{% extends 'base.tmpl' %}
{% import 'archive_navigation_helper.tmpl' as archive_nav with context %}
{% import 'feeds_translations_helper.tmpl' as feeds_translations with context %}

{% block content %}
<article class="listpage">
<header>
<h1>{{ title|e }}</h1>
</header>
{{ archive_nav.archive_navigation() }}
{{ feeds_translations.translation_link() }}
{% if items %}
<ul class="postlist">
{% for text, link, count in items %}
@@ -1,13 +1,15 @@
{# -*- coding: utf-8 -*- #}
{% extends 'base.tmpl' %}
{% import 'archive_navigation_helper.tmpl' as archive_nav with context %}
{% import 'feeds_translations_helper.tmpl' as feeds_translations with context %}

{% block content %}
<article class="listpage">
<header>
<h1>{{ title|e }}</h1>
</header>
{{ archive_nav.archive_navigation() }}
{{ feeds_translations.translation_link() }}
{% if posts %}
<ul class="postlist">
{% for post in posts %}

0 comments on commit afe6799

Please sign in to comment.