dir=rtl on <html> for RTL page languages

This commit is contained in:
2026-09-03 03:06:34 +00:00
parent 87b7591bec
commit 3e72038ed2
2 changed files with 8 additions and 2 deletions
+4
View File
@@ -21,6 +21,10 @@ from pagerite.data import Data, Node, Patch, resolve
#: ancestor (up to the front page) sets one (Node.language, "" = inherit).
ORIGINAL_LANGUAGE = "en"
#: Languages written right-to-left; pages served in one get dir="rtl" on
#: <html> (views._layout).
RTL_LANGUAGES = frozenset({"ar", "fa", "he", "ur"})
def primary_lang(menu: dict[str, Node], path: str) -> str:
"""The primary language of the article at ``path``: its own
+4 -2
View File
@@ -339,12 +339,14 @@ def _layout(
``social`` maps meta keys to contents: ``og:*``/``article:*`` go out as
property attributes, everything else (description, twitter:*) as name.
``lang`` is the served language for <html lang>. ``canonical`` and
``lang`` is the served language for <html lang>; an RTL language (ar,
fa, ...) also puts dir="rtl" on <html> (the editor panel carries its own
lang="en" dir="ltr", so it is unaffected). ``canonical`` and
``alternates`` ((hreflang, href) pairs) are the page's language URLs
(see docs/localization.md), emitted right after the viewport and before
the social tags: canonical first, then the hreflang alternates.
"""
doc = Document(E.Title, lang=lang)
doc = Document(E.Title, lang=lang, dir="rtl" if lang in i18n.RTL_LANGUAGES else "ltr")
# Responsive layout (see the 48rem breakpoint in pagerite.css) needs
# the real device width, not the default 980px layout viewport.
doc.meta(name="viewport", content="width=device-width, initial-scale=1")