getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.58k stars 1.81k forks source link

Set html lang attribute for each post according to its lang metadata #2212

Closed bingen13 closed 6 years ago

bingen13 commented 7 years ago

The lang attribute is set globally for the entire blog, taken from the DEFAULT_LANG setting. However, posts and pages may be written in different languages, which are indicated on their metadata through the Lang field. This should change the language for those posts when shown together, and for the post URL when shown alone.

justinmayer commented 7 years ago

Hi David. Is this something you would like to help implement?

ingwinlu commented 7 years ago

isn't that a theming problem? it should check if there is article language set and fallback to the global setting.. i think i have seen this approach in a number of themes already.

On 3 October 2017 at 18:11, Justin Mayer notifications@github.com wrote:

Hi David. Is this something you would like to help implement?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/getpelican/pelican/issues/2212#issuecomment-333892228, or mute the thread https://github.com/notifications/unsubscribe-auth/AEOv-rYZptGFNWvA09qZ-5NKrIHgY2NCks5solyagaJpZM4PaGhv .

ghost commented 7 years ago

Manage it in the pelican code would avoid problem with theme that don't manage it correctly.

avaris commented 7 years ago

How can pelican manage this? All the meta fields in the final HTML output is handled by the theme. Pelican only supplies the content as HTML.

jorgesumle commented 7 years ago

Here is the solution:

  1. Add the following code to the base.html of the theme:
<html lang="{% block html_lang %}{{ DEFAULT_LANG }}{% endblock %}">
  1. Add the following code to the file article.html:
{% block html_lang %}{{ article.lang }}{% endblock %}
  1. Add the following code the file page.html:
    {% block html_lang %}{{ page.lang }}{% endblock%}

@Postroutine, I think that changing three lines of code is not very difficult. You can submit a pull request to the theme you are using or just change it to fit your needs. With that said, I would vote to close this issue.

justinmayer commented 7 years ago

Is there any value in adding @jorgesumle's suggested changes to the default theme's base.html, article.html, and page.html?