Skip to content

Commit

Permalink
Merge pull request #2778 from getnikola/taxonomy-lang-refs
Browse files Browse the repository at this point in the history
First shot on #993 for taxonomies, in particular archives.
  • Loading branch information
Kwpolska committed Jun 11, 2017
2 parents 4e6c32c + 15e9a9a commit afe6799
Show file tree
Hide file tree
Showing 42 changed files with 840 additions and 369 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Expand Up @@ -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)
Expand Down
99 changes: 56 additions & 43 deletions docs/template-variables.rst
Expand Up @@ -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.

Expand All @@ -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
~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -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
Expand All @@ -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
--------------------------------
Expand Down Expand Up @@ -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``)
---------------------------------------------------------------------
Expand Down
33 changes: 33 additions & 0 deletions nikola/conf.py.in
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions nikola/data/themes/base-jinja/templates/archiveindex.tmpl
@@ -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 %}
6 changes: 3 additions & 3 deletions nikola/data/themes/base-jinja/templates/author.tmpl
@@ -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 %}


Expand All @@ -16,7 +16,7 @@
<p>{{ description }}</p>
{% endif %}
<div class="metadata">
{{ feed.link(author) }}
{{ feeds_translations.feed_link(author) }}
</div>
</header>
{% if posts %}
Expand Down
4 changes: 2 additions & 2 deletions nikola/data/themes/base-jinja/templates/authorindex.tmpl
@@ -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 %}
6 changes: 3 additions & 3 deletions nikola/data/themes/base-jinja/templates/base_helper.tmpl
@@ -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>
Expand Down Expand Up @@ -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 %}
Expand Down Expand Up @@ -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() %}
Expand Down
@@ -1,4 +1,6 @@
{# -*- coding: utf-8 -*- #}

{# Handles both feeds and translations #}
{% macro head(classification=None) %}
{% if rss_link %}
{{ rss_link }}
Expand Down Expand Up @@ -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 %}
Expand All @@ -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 %}
5 changes: 4 additions & 1 deletion nikola/data/themes/base-jinja/templates/index.tmpl
Expand Up @@ -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 %}
Expand All @@ -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 %}
Expand Down
2 changes: 2 additions & 0 deletions nikola/data/themes/base-jinja/templates/list.tmpl
@@ -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 %}
Expand Down
2 changes: 2 additions & 0 deletions nikola/data/themes/base-jinja/templates/list_post.tmpl
@@ -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 %}
Expand Down

0 comments on commit afe6799

Please sign in to comment.