From d1d1cccdade052e2dbfd232172fb5644072a3d13 Mon Sep 17 00:00:00 2001 From: Jorge Maldonado Ventura Date: Thu, 5 Jul 2018 00:26:50 +0200 Subject: [PATCH] Add hreflang attribute to default themes --- pelican/tests/output/basic/category/misc.html | 2 +- pelican/tests/output/basic/index.html | 2 +- pelican/tests/output/basic/second-article-fr.html | 4 +++- pelican/tests/output/basic/second-article.html | 4 +++- pelican/tests/output/basic/tag/bar.html | 2 +- pelican/tests/output/basic/tag/foo.html | 2 +- .../tests/output/custom/author/alexis-metaireau.html | 2 +- .../tests/output/custom/author/alexis-metaireau2.html | 2 +- pelican/tests/output/custom/category/bar.html | 2 +- pelican/tests/output/custom/category/misc.html | 2 +- pelican/tests/output/custom/index.html | 2 +- pelican/tests/output/custom/index2.html | 2 +- pelican/tests/output/custom/oh-yeah-fr.html | 4 +++- pelican/tests/output/custom/oh-yeah.html | 4 +++- pelican/tests/output/custom/second-article-fr.html | 4 +++- pelican/tests/output/custom/second-article.html | 4 +++- pelican/tests/output/custom/tag/bar.html | 4 ++-- pelican/tests/output/custom/tag/foo.html | 2 +- pelican/tests/output/custom/tag/yeah.html | 2 +- .../output/custom_locale/author/alexis-metaireau.html | 2 +- .../custom_locale/author/alexis-metaireau2.html | 2 +- pelican/tests/output/custom_locale/category/bar.html | 2 +- pelican/tests/output/custom_locale/category/misc.html | 2 +- pelican/tests/output/custom_locale/index.html | 2 +- pelican/tests/output/custom_locale/index2.html | 2 +- pelican/tests/output/custom_locale/oh-yeah-fr.html | 4 +++- .../posts/2010/octobre/20/oh-yeah/index.html | 4 +++- .../posts/2012/février/29/second-article/index.html | 4 +++- .../tests/output/custom_locale/second-article-fr.html | 4 +++- pelican/tests/output/custom_locale/tag/bar.html | 4 ++-- pelican/tests/output/custom_locale/tag/foo.html | 2 +- pelican/tests/output/custom_locale/tag/yeah.html | 2 +- pelican/themes/notmyidea/templates/article.html | 8 ++++++++ pelican/themes/notmyidea/templates/base.html | 1 + pelican/themes/notmyidea/templates/page.html | 8 ++++++++ pelican/themes/notmyidea/templates/translations.html | 10 +++++++++- pelican/themes/simple/templates/article.html | 6 ++++++ pelican/themes/simple/templates/page.html | 9 +++++++++ pelican/themes/simple/templates/translations.html | 11 +++++++++-- 39 files changed, 104 insertions(+), 37 deletions(-) diff --git a/pelican/tests/output/basic/category/misc.html b/pelican/tests/output/basic/category/misc.html index 9012cedc..0542dba1 100644 --- a/pelican/tests/output/basic/category/misc.html +++ b/pelican/tests/output/basic/category/misc.html @@ -53,7 +53,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/basic/index.html b/pelican/tests/output/basic/index.html index ed1356ed..8fa23f79 100644 --- a/pelican/tests/output/basic/index.html +++ b/pelican/tests/output/basic/index.html @@ -53,7 +53,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/basic/second-article-fr.html b/pelican/tests/output/basic/second-article-fr.html index 8b21ea5d..1e5f1ef9 100644 --- a/pelican/tests/output/basic/second-article-fr.html +++ b/pelican/tests/output/basic/second-article-fr.html @@ -5,6 +5,8 @@ Deuxième article + + @@ -36,7 +38,7 @@

In misc.

tags: foo bar baz

Translations: - en + en

Ceci est un article, en français.

diff --git a/pelican/tests/output/basic/second-article.html b/pelican/tests/output/basic/second-article.html index a68a1a6f..4485e9f8 100644 --- a/pelican/tests/output/basic/second-article.html +++ b/pelican/tests/output/basic/second-article.html @@ -5,6 +5,8 @@ Second article + + @@ -36,7 +38,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/basic/tag/bar.html b/pelican/tests/output/basic/tag/bar.html index b699a45d..b8905a5b 100644 --- a/pelican/tests/output/basic/tag/bar.html +++ b/pelican/tests/output/basic/tag/bar.html @@ -31,7 +31,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/basic/tag/foo.html b/pelican/tests/output/basic/tag/foo.html index 348efcc0..aad78781 100644 --- a/pelican/tests/output/basic/tag/foo.html +++ b/pelican/tests/output/basic/tag/foo.html @@ -31,7 +31,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom/author/alexis-metaireau.html b/pelican/tests/output/custom/author/alexis-metaireau.html index 045c4d94..ea7b44ad 100644 --- a/pelican/tests/output/custom/author/alexis-metaireau.html +++ b/pelican/tests/output/custom/author/alexis-metaireau.html @@ -63,7 +63,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom/author/alexis-metaireau2.html b/pelican/tests/output/custom/author/alexis-metaireau2.html index 7c28bad8..52570882 100644 --- a/pelican/tests/output/custom/author/alexis-metaireau2.html +++ b/pelican/tests/output/custom/author/alexis-metaireau2.html @@ -118,7 +118,7 @@ as well as inline markup.

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom/category/bar.html b/pelican/tests/output/custom/category/bar.html index fa9e49df..eaddbb76 100644 --- a/pelican/tests/output/custom/category/bar.html +++ b/pelican/tests/output/custom/category/bar.html @@ -38,7 +38,7 @@

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom/category/misc.html b/pelican/tests/output/custom/category/misc.html index 339f3316..c0af7513 100644 --- a/pelican/tests/output/custom/category/misc.html +++ b/pelican/tests/output/custom/category/misc.html @@ -63,7 +63,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom/index.html b/pelican/tests/output/custom/index.html index d78b001f..465d4414 100644 --- a/pelican/tests/output/custom/index.html +++ b/pelican/tests/output/custom/index.html @@ -63,7 +63,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom/index2.html b/pelican/tests/output/custom/index2.html index 434d8596..f52583ce 100644 --- a/pelican/tests/output/custom/index2.html +++ b/pelican/tests/output/custom/index2.html @@ -118,7 +118,7 @@ as well as inline markup.

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom/oh-yeah-fr.html b/pelican/tests/output/custom/oh-yeah-fr.html index a4ec6936..9d1a317d 100644 --- a/pelican/tests/output/custom/oh-yeah-fr.html +++ b/pelican/tests/output/custom/oh-yeah-fr.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In misc.

Translations: - en + en

Et voila du contenu en français

diff --git a/pelican/tests/output/custom/oh-yeah.html b/pelican/tests/output/custom/oh-yeah.html index f73a1ea7..1bdf4791 100644 --- a/pelican/tests/output/custom/oh-yeah.html +++ b/pelican/tests/output/custom/oh-yeah.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom/second-article-fr.html b/pelican/tests/output/custom/second-article-fr.html index 2a2ff9ad..16273abd 100644 --- a/pelican/tests/output/custom/second-article-fr.html +++ b/pelican/tests/output/custom/second-article-fr.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In misc.

tags: foo bar baz

Translations: - en + en

Ceci est un article, en français.

diff --git a/pelican/tests/output/custom/second-article.html b/pelican/tests/output/custom/second-article.html index 1bff301a..68a814f4 100644 --- a/pelican/tests/output/custom/second-article.html +++ b/pelican/tests/output/custom/second-article.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom/tag/bar.html b/pelican/tests/output/custom/tag/bar.html index 048df1d3..2723cef9 100644 --- a/pelican/tests/output/custom/tag/bar.html +++ b/pelican/tests/output/custom/tag/bar.html @@ -38,7 +38,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

There are comments.

@@ -93,7 +93,7 @@ as well as inline markup.

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom/tag/foo.html b/pelican/tests/output/custom/tag/foo.html index 0aa4c524..9c117c9e 100644 --- a/pelican/tests/output/custom/tag/foo.html +++ b/pelican/tests/output/custom/tag/foo.html @@ -38,7 +38,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

There are comments.

diff --git a/pelican/tests/output/custom/tag/yeah.html b/pelican/tests/output/custom/tag/yeah.html index f4d149e6..d73e6adb 100644 --- a/pelican/tests/output/custom/tag/yeah.html +++ b/pelican/tests/output/custom/tag/yeah.html @@ -38,7 +38,7 @@

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom_locale/author/alexis-metaireau.html b/pelican/tests/output/custom_locale/author/alexis-metaireau.html index 2fbaced4..c21a11ee 100644 --- a/pelican/tests/output/custom_locale/author/alexis-metaireau.html +++ b/pelican/tests/output/custom_locale/author/alexis-metaireau.html @@ -63,7 +63,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom_locale/author/alexis-metaireau2.html b/pelican/tests/output/custom_locale/author/alexis-metaireau2.html index 23621487..5ec65bac 100644 --- a/pelican/tests/output/custom_locale/author/alexis-metaireau2.html +++ b/pelican/tests/output/custom_locale/author/alexis-metaireau2.html @@ -118,7 +118,7 @@ as well as inline markup.

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom_locale/category/bar.html b/pelican/tests/output/custom_locale/category/bar.html index a0ba9741..d2cc2214 100644 --- a/pelican/tests/output/custom_locale/category/bar.html +++ b/pelican/tests/output/custom_locale/category/bar.html @@ -38,7 +38,7 @@

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom_locale/category/misc.html b/pelican/tests/output/custom_locale/category/misc.html index d37f588e..4e31e817 100644 --- a/pelican/tests/output/custom_locale/category/misc.html +++ b/pelican/tests/output/custom_locale/category/misc.html @@ -63,7 +63,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom_locale/index.html b/pelican/tests/output/custom_locale/index.html index a0172665..b56a6b8c 100644 --- a/pelican/tests/output/custom_locale/index.html +++ b/pelican/tests/output/custom_locale/index.html @@ -63,7 +63,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom_locale/index2.html b/pelican/tests/output/custom_locale/index2.html index bb5e036f..0fde251d 100644 --- a/pelican/tests/output/custom_locale/index2.html +++ b/pelican/tests/output/custom_locale/index2.html @@ -118,7 +118,7 @@ as well as inline markup.

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom_locale/oh-yeah-fr.html b/pelican/tests/output/custom_locale/oh-yeah-fr.html index 4d550682..1ecd77b6 100644 --- a/pelican/tests/output/custom_locale/oh-yeah-fr.html +++ b/pelican/tests/output/custom_locale/oh-yeah-fr.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In misc.

Translations: - en + en

Et voila du contenu en français

diff --git a/pelican/tests/output/custom_locale/posts/2010/octobre/20/oh-yeah/index.html b/pelican/tests/output/custom_locale/posts/2010/octobre/20/oh-yeah/index.html index deb2b9f6..91acf1a8 100644 --- a/pelican/tests/output/custom_locale/posts/2010/octobre/20/oh-yeah/index.html +++ b/pelican/tests/output/custom_locale/posts/2010/octobre/20/oh-yeah/index.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom_locale/posts/2012/février/29/second-article/index.html b/pelican/tests/output/custom_locale/posts/2012/février/29/second-article/index.html index c02722ad..c5790ae2 100644 --- a/pelican/tests/output/custom_locale/posts/2012/février/29/second-article/index.html +++ b/pelican/tests/output/custom_locale/posts/2012/février/29/second-article/index.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

diff --git a/pelican/tests/output/custom_locale/second-article-fr.html b/pelican/tests/output/custom_locale/second-article-fr.html index fb7f5e23..33e10b19 100644 --- a/pelican/tests/output/custom_locale/second-article-fr.html +++ b/pelican/tests/output/custom_locale/second-article-fr.html @@ -6,6 +6,8 @@ + + @@ -43,7 +45,7 @@

In misc.

tags: foo bar baz

Translations: - en + en

Ceci est un article, en français.

diff --git a/pelican/tests/output/custom_locale/tag/bar.html b/pelican/tests/output/custom_locale/tag/bar.html index e0dd328d..0d49090f 100644 --- a/pelican/tests/output/custom_locale/tag/bar.html +++ b/pelican/tests/output/custom_locale/tag/bar.html @@ -38,7 +38,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

There are comments.

@@ -93,7 +93,7 @@ as well as inline markup.

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/tests/output/custom_locale/tag/foo.html b/pelican/tests/output/custom_locale/tag/foo.html index 7d4f2b86..f85ae34d 100644 --- a/pelican/tests/output/custom_locale/tag/foo.html +++ b/pelican/tests/output/custom_locale/tag/foo.html @@ -38,7 +38,7 @@

In misc.

tags: foo bar baz

Translations: - fr + fr

This is some article, in english

There are comments.

diff --git a/pelican/tests/output/custom_locale/tag/yeah.html b/pelican/tests/output/custom_locale/tag/yeah.html index 43a29971..fb0f2eb1 100644 --- a/pelican/tests/output/custom_locale/tag/yeah.html +++ b/pelican/tests/output/custom_locale/tag/yeah.html @@ -38,7 +38,7 @@

In bar.

tags: oh bar yeah

Translations: - fr + fr

Why not ?

diff --git a/pelican/themes/notmyidea/templates/article.html b/pelican/themes/notmyidea/templates/article.html index 390a89bb..98c91bbc 100644 --- a/pelican/themes/notmyidea/templates/article.html +++ b/pelican/themes/notmyidea/templates/article.html @@ -1,6 +1,14 @@ {% extends "base.html" %} {% block html_lang %}{{ article.lang }}{% endblock %} {% block title %}{{ article.title|striptags }}{% endblock %} + +{% block extra_head %} +{% import 'translations.html' as translations with context %} +{% if translations.entry_hreflang(article) %} + {{ translations.entry_hreflang(article) }} +{% endif %} +{% endblock %} + {% block content %}
diff --git a/pelican/themes/notmyidea/templates/base.html b/pelican/themes/notmyidea/templates/base.html index e97c3ea7..2de43b46 100644 --- a/pelican/themes/notmyidea/templates/base.html +++ b/pelican/themes/notmyidea/templates/base.html @@ -10,6 +10,7 @@ {% if FEED_ALL_RSS %} {% endif %} + {% block extra_head %}{% endblock extra_head %} diff --git a/pelican/themes/notmyidea/templates/page.html b/pelican/themes/notmyidea/templates/page.html index 00c20834..7e50c1f6 100644 --- a/pelican/themes/notmyidea/templates/page.html +++ b/pelican/themes/notmyidea/templates/page.html @@ -1,6 +1,14 @@ {% extends "base.html" %} {% block html_lang %}{{ page.lang }}{% endblock %} {% block title %}{{ page.title }}{% endblock %} + +{% block extra_head %} +{% import 'translations.html' as translations with context %} +{% if translations.entry_hreflang(page) %} + {{ translations.entry_hreflang(page) }} +{% endif %} +{% endblock %} + {% block content %}

{{ page.title }}

diff --git a/pelican/themes/notmyidea/templates/translations.html b/pelican/themes/notmyidea/templates/translations.html index 7894bb07..1eec7c43 100644 --- a/pelican/themes/notmyidea/templates/translations.html +++ b/pelican/themes/notmyidea/templates/translations.html @@ -2,7 +2,15 @@ {% if article.translations %} Translations: {% for translation in article.translations %} - {{ translation.lang }} + {{ translation.lang }} {% endfor %} {% endif %} {% endmacro %} + +{% macro entry_hreflang(entry) %} +{% if entry.translations %} + {% for translation in entry.translations %} + + {% endfor %} +{% endif %} +{% endmacro %} diff --git a/pelican/themes/simple/templates/article.html b/pelican/themes/simple/templates/article.html index e02596f4..04b9a758 100644 --- a/pelican/themes/simple/templates/article.html +++ b/pelican/themes/simple/templates/article.html @@ -5,6 +5,12 @@ {% block head %} {{ super() }} + + {% import 'translations.html' as translations with context %} + {% if translations.entry_hreflang(article) %} + {{ translations.entry_hreflang(article) }} + {% endif %} + {% if article.description %} {% endif %} diff --git a/pelican/themes/simple/templates/page.html b/pelican/themes/simple/templates/page.html index e420c89a..7150d420 100644 --- a/pelican/themes/simple/templates/page.html +++ b/pelican/themes/simple/templates/page.html @@ -3,6 +3,15 @@ {% block title %}{{ SITENAME }} - {{ page.title }}{%endblock%} +{% block head %} + {{ super() }} + + {% import 'translations.html' as translations with context %} + {% if translations.entry_hreflang(page) %} + {{ translations.entry_hreflang(page) }} + {% endif %} +{% endblock %} + {% block content %}

{{ page.title }}

{% import 'translations.html' as translations with context %} diff --git a/pelican/themes/simple/templates/translations.html b/pelican/themes/simple/templates/translations.html index db8c372d..f0e2478d 100644 --- a/pelican/themes/simple/templates/translations.html +++ b/pelican/themes/simple/templates/translations.html @@ -1,9 +1,16 @@ {% macro translations_for(article) %} {% if article.translations %} -Translations: +Translations: {% for translation in article.translations %} -{{ translation.lang }} +{{ translation.lang }} {% endfor %} {% endif %} {% endmacro %} +{% macro entry_hreflang(entry) %} +{% if entry.translations %} + {% for translation in entry.translations %} + + {% endfor %} +{% endif %} +{% endmacro %}