Skip to content

Commit

Permalink
Add RTL support using BSv5 (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalin committed May 16, 2024
1 parent 102892d commit 3674691
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 16 deletions.
5 changes: 4 additions & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
<html itemscope itemtype="http://schema.org/WebPage"
{{- with .Site.Language.LanguageDirection }} dir="{{ . }}" {{- end -}}
{{ with .Site.Language.Lang }} lang="{{ . }}" {{- end }} {{/**/ -}}
class="no-js">
<head>
{{ partial "head.html" . }}
</head>
Expand Down
5 changes: 4 additions & 1 deletion layouts/blog/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
<html itemscope itemtype="http://schema.org/WebPage"
{{- with .Site.Language.LanguageDirection }} dir="{{ . }}" {{- end -}}
{{ with .Site.Language.Lang }} lang="{{ . }}" {{- end }} {{/**/ -}}
class="no-js">
<head>
{{ partial "head.html" . }}
</head>
Expand Down
5 changes: 4 additions & 1 deletion layouts/blog/baseof.print.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
<html itemscope itemtype="http://schema.org/WebPage"
{{- with .Site.Language.LanguageDirection }} dir="{{ . }}" {{- end -}}
{{ with .Site.Language.Lang }} lang="{{ . }}" {{- end }} {{/**/ -}}
class="no-js">
<head>
{{ partial "head.html" . }}
</head>
Expand Down
5 changes: 4 additions & 1 deletion layouts/docs/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
<html itemscope itemtype="http://schema.org/WebPage"
{{- with .Site.Language.LanguageDirection }} dir="{{ . }}" {{- end -}}
{{ with .Site.Language.Lang }} lang="{{ . }}" {{- end }} {{/**/ -}}
class="no-js">
<head>
{{ partial "head.html" . }}
</head>
Expand Down
5 changes: 4 additions & 1 deletion layouts/docs/baseof.print.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
<html itemscope itemtype="http://schema.org/WebPage"
{{- with .Site.Language.LanguageDirection }} dir="{{ . }}" {{- end -}}
{{ with .Site.Language.Lang }} lang="{{ . }}" {{- end }} {{/**/ -}}
class="no-js">
<head>
{{ partial "head.html" . }}
</head>
Expand Down
34 changes: 25 additions & 9 deletions layouts/partials/head-css.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
{{ $scssMain := "scss/main.scss" -}}
{{ $css := resources.Get $scssMain
| toCSS (dict "enableSourceMap" (not hugo.IsProduction)) -}}
{{ $rtlCSS :=
cond (eq .Site.Language.LanguageDirection "rtl")
(resources.Get "vendor/bootstrap/dist/css/bootstrap.rtl.css")
nil -}}

{{ if hugo.IsProduction -}}
{{ with $rtlCSS -}}
{{ $rtlCSS = . | postCSS | minify | fingerprint -}}
{{ end -}}
{{ $css = $css | postCSS | minify | fingerprint -}}
<link rel="preload" href="{{ $css.RelPermalink }}" as="style">
{{- end -}}

{{/* NOTE: when not in production, we don't apply `postCSS`. This makes it
snappier to develop in Chrome, but makes it look sub-optimal in other browsers.
*/ -}}

{{ $scssMain := "scss/main.scss"}}
{{ if not hugo.IsProduction }}
{{/* Note the missing postCSS. This makes it snappier to develop in Chrome, but makes it look sub-optimal in other browsers. */}}
{{ $css := resources.Get $scssMain | toCSS (dict "enableSourceMap" true) }}
<link href="{{ $css.RelPermalink }}" rel="stylesheet">
{{ else }}
{{ $css := resources.Get $scssMain | toCSS (dict "enableSourceMap" false) | postCSS | minify | fingerprint }}
<link rel="preload" href="{{ $css.RelPermalink }}" as="style">
<link href="{{ $css.RelPermalink }}" rel="stylesheet" integrity="{{ $css.Data.integrity }}">
{{ end }}

{{ with $rtlCSS -}}
<link href="{{ $rtlCSS.RelPermalink }}" rel="stylesheet">
{{ end -}}

{{- /**/ -}}
2 changes: 1 addition & 1 deletion layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{{ template "_internal/opengraph.html" . -}}
{{ template "_internal/schema.html" . -}}
{{ template "_internal/twitter_cards.html" . -}}
{{ partialCached "head-css.html" . "asdf" -}}
{{ partialCached "head-css.html" . "head-css-cache-key" }}
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
Expand Down
5 changes: 4 additions & 1 deletion layouts/swagger/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
<html itemscope itemtype="http://schema.org/WebPage" lang="{{ .Site.Language.Lang }}" class="no-js">
<html itemscope itemtype="http://schema.org/WebPage"
{{- with .Site.Language.LanguageDirection }} dir="{{ . }}" {{- end -}}
{{ with .Site.Language.Lang }} lang="{{ . }}" {{- end }} {{/**/ -}}
class="no-js">
<head>
{{ partial "head.html" . }}
<title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} | {{ end }}{{ .Site.Title }}{{ end }}</title>
Expand Down

0 comments on commit 3674691

Please sign in to comment.