Skip to content

Commit

Permalink
Added support for Right-To-Left languages (theNewDynamic#532)
Browse files Browse the repository at this point in the history
* Added support for Right-To-Left languages

* Added language-direction partial
  • Loading branch information
MeirKriheli authored and tstephen committed Jun 9, 2022
1 parent 39c7061 commit f95ce73
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 16 deletions.
6 changes: 6 additions & 0 deletions assets/ananke/css/_hugo-internal-templates.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
font-size: .875rem;
margin-bottom: 2.5em;
}

[dir="rtl"] .pagination li {
margin-left: .375rem;
margin-right: 0;
}

.pagination li a {
padding: .5rem .625rem;
background-color: white;
Expand Down
1 change: 1 addition & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enableRobotsTXT = true
title = "Ananke"
weight = 1
contentDir = "content/en"
# languageDirection = 'rtl' for Right-To-Left languages
[languages.fr]
title = "Ananke Fr"
weight = 2
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="{{ $.Site.LanguageCode | default "en" }}">
<html lang="{{ $.Site.LanguageCode | default "en" }}" {{ partial "language-direction.html" . | safeHTMLAttr }}>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h1 class="f1 mt3 mb1 {{ $.Param "post_content_classes" | default "serif"}} {{
<span class="f6 mv2 dib tracked {{ $.Param "secondary_text_color" | default "near-black" }}"> - {{ i18n "wordCount" .WordCount }} </span>
{{ end }}
</header>
<div class="nested-copy-line-height lh-copy {{ $.Param "post_content_classes" | default "serif"}} f4 nested-links {{ $.Param "text_color" | default "mid-gray" }} pr4-l w-two-thirds-l">
<div class="nested-copy-line-height lh-copy {{ $.Param "post_content_classes" | default "serif"}} f4 nested-links {{ $.Param "text_color" | default "mid-gray" }} {{ cond (eq $.Site.Language.LanguageDirection "rtl") "pl4-l" "pr4-l" }} w-two-thirds-l">
{{- .Content -}}
{{- partial "tags.html" . -}}
<div class="mt6 instapaper_ignoref">
Expand Down
6 changes: 3 additions & 3 deletions layouts/_default/summary-with-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
{{ if $featured_image }}
{{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}}
{{ $featured_image := (trim $featured_image "/") | absURL }}
<div class="pr3-ns mb4 mb0-ns w-100 w-40-ns">
<div class="{{ cond (eq $.Site.Language.LanguageDirection "rtl") "pl3-ns" "pr3-ns" }} mb4 mb0-ns w-100 w-40-ns">
<a href="{{.RelPermalink}}" class="db grow">
<img src="{{ $featured_image }}" class="img" alt="image from {{ .Title }}">
</a>
</div>
{{ end }}
<div class="blah w-100{{ if $featured_image }} w-60-ns pl3-ns{{ end }}">
<h1 class="f3 fw1 mt0 lh-title {{ $.Param "body_classes" | default "serif"}} {{ $.Param "text_color" | default "near-black" }}">
<div class="blah w-100{{ if $featured_image }} w-60-ns {{ cond (eq $.Site.Language.LanguageDirection "rtl") "pr3-ns" "pl3-ns" }}{{ end }}">
<h1 class="f3 fw1 athelas mt0 lh-title">
<a href="{{.RelPermalink}}" class="color-inherit dim link">
{{ .Title }}
</a>
Expand Down
4 changes: 2 additions & 2 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ <h1 class="flex-none {{ $.Param "secondary_text_color" | default "near-black" }}
<h1 class="f3 {{ $.Param "text_color" | default "near-black" }}">{{ i18n "more" }}</h1>
{{/* Now, range through the next four after the initial $n_posts items. Nest the requirements, "after" then "first" on the outside */}}
{{ range (first 4 (after $n_posts $section)) }}
<h2 class="f5 fw4 mb4 dib mr3">
<a href="{{ .RelPermalink }}" class="link dim {{ $.Param "secondary_text_color" | default "black" }}">
<h2 class="f5 fw4 mb4 dib {{ cond (eq $.Site.Language.LanguageDirection "rtl") "ml3" "mr3" }}">
<a href="{{ .RelPermalink }}" class="link black dim">
{{ .Title }}
</a>
</h2>
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/i18nlist.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ if .IsTranslated }}
<h4>{{ i18n "translations" }}</h4>
<ul class="pl0 mr3">
<ul class="{{ cond (eq $.Site.Language.LanguageDirection "rtl") "pr0 ml3" "pl0 mr3" }}">
{{ range .Translations }}
<li class="list f5 f4-ns fw4 dib pr3">
<li class="list f5 f4-ns fw4 dib {{ cond (eq $.Site.Language.LanguageDirection "rtl") "pl3" "pr3" }}">
<a class="hover-white no-underline white-90" href="{{ .RelPermalink }}">{{ .Lang }}</a>
</li>
{{ end}}
Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/language-direction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- if ge hugo.Version "0.67.1" -}}
dir="{{ $.Site.Language.LanguageDirection | default "ltr" }}"
{{- end -}}
4 changes: 2 additions & 2 deletions layouts/partials/site-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<div class="flex-l items-center">
{{ partial "i18nlist.html" . }}
{{ if .Site.Menus.main }}
<ul class="pl0 mr3">
<ul class="{{ cond (eq $.Site.Language.LanguageDirection "rtl") "pr0 ml3" "pl0 mr3" }}">
{{ range .Site.Menus.main }}
<li class="list f5 f4-ns fw4 dib pr3">
<li class="list f5 f4-ns fw4 dib {{ cond (eq $.Site.Language.LanguageDirection "rtl") "pl3" "pr3" }}">
<a class="hover-white no-underline white-90" href="{{ .URL }}" title="{{ i18n "pageTitle" . }}">
{{ .Name }}
</a>
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/social-follow.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ $socials := partialCached "func/socials/Get" "socials/Get" }}
<div class="ananke-socials">
{{ range $socials }}
<a href="{{ .url }}" target="_blank" class="{{ .name }} ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l mr1" title="{{ .label }} link" rel="noopener" aria-label="follow on {{ .label }}——Opens in a new window">
<a href="{{ .url }}" target="_blank" class="{{ .name }} ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l {{ cond (eq $.Site.Language.LanguageDirection "rtl") "ml1" "mr1" }}" title="{{ .label }} link" rel="noopener" aria-label="follow on {{ .label }}——Opens in a new window">
{{ with .icon }}
<span class="icon">{{ . }}</span>
{{ else }}
Expand All @@ -10,4 +10,4 @@
{{- partial "new-window-icon.html" . -}}
</a>
{{ end }}
</div>
</div>
4 changes: 2 additions & 2 deletions layouts/partials/summary-with-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
{{ if $featured_image }}
{{/* Trimming the slash and adding absURL make sure the image works no matter where our site lives */}}
{{ $featured_image := (trim $featured_image "/") | absURL }}
<div class="pr3-ns mb4 mb0-ns w-100 w-40-ns">
<div class="{{ cond (eq $.Site.Language.LanguageDirection "rtl") "pl3-ns" "pr3-ns" }} mb4 mb0-ns w-100 w-40-ns">
<a href="{{.RelPermalink}}" class="db grow">
<img src="{{ $featured_image }}" class="img" alt="image from {{ .Title }}">
</a>
</div>
{{ end }}
<div class="blah w-100{{ if $featured_image }} w-60-ns pl3-ns{{ end }}">
<div class="blah w-100{{ if $featured_image }} w-60-ns {{ cond (eq $.Site.Language.LanguageDirection "rtl") "pr3-ns" "pl3-ns" }}{{ end }}">
<h1 class="f3 fw1 athelas mt0 lh-title">
<a href="{{.RelPermalink}}" class="color-inherit dim link">
{{ .Title }}
Expand Down

Large diffs are not rendered by default.

0 comments on commit f95ce73

Please sign in to comment.