mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2025-06-10 18:54:08 +00:00
add dynamic direction decision for each paragraph
This commit is contained in:
parent
9405c4c3d7
commit
aa0eab9362
8
assets/language-direction.js
Normal file
8
assets/language-direction.js
Normal file
@ -0,0 +1,8 @@
|
||||
document.querySelectorAll('.book-article p').forEach(articleElement => {
|
||||
const text = articleElement.textContent.trim();
|
||||
if (/[\u0590-\u05FF]/.test(text)) {
|
||||
articleElement.setAttribute("dir", "rtl");
|
||||
} else {
|
||||
articleElement.setAttribute("dir", "ltr");
|
||||
}
|
||||
});
|
@ -6,7 +6,7 @@
|
||||
<meta name="color-scheme" content="light dark">
|
||||
|
||||
{{- with .Page.Params.BookHref -}}
|
||||
<meta http-equiv="Refresh" content="0; url='{{ . }}'" />
|
||||
<meta http-equiv="Refresh" content="0; url='{{ . }}'" />
|
||||
{{- end -}}
|
||||
|
||||
{{- template "_internal/opengraph.html" . -}}
|
||||
@ -19,29 +19,39 @@
|
||||
<link rel="canonical" href="{{ .Permalink }}">
|
||||
|
||||
{{- range .Translations }}
|
||||
<link rel="alternate" hreflang="{{ default .Site.LanguageCode .Language.Lang }}" href="{{ .Permalink }}" title="{{ partial "docs/title" . }}">
|
||||
<link rel="alternate" hreflang="{{ default .Site.LanguageCode .Language.Lang }}" href="{{ .Permalink }}"
|
||||
title="{{ partial " docs/title" . }}">
|
||||
{{- end -}}
|
||||
|
||||
<!-- Theme stylesheet, you can customize scss by creating `assets/custom.scss` in your website -->
|
||||
{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }}
|
||||
{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify |
|
||||
resources.Fingerprint }}
|
||||
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" {{ template "integrity" $styles }}>
|
||||
{{- if default true .Site.Params.BookSearch -}}
|
||||
{{- $searchJSFile := printf "%s.search.js" .Language.Lang }}
|
||||
{{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify | resources.Fingerprint }}
|
||||
<script defer src="{{ "fuse.min.js" | relURL }}"></script>
|
||||
<script defer src="{{ $searchJS.RelPermalink }}" {{ template "integrity" $searchJS }}></script>
|
||||
{{- $searchJSFile := printf "%s.search.js" .Language.Lang }}
|
||||
{{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify |
|
||||
resources.Fingerprint }}
|
||||
<script defer src="{{ " fuse.min.js" | relURL }}"></script>
|
||||
<script defer src="{{ $searchJS.RelPermalink }}" {{ template "integrity" $searchJS }}></script>
|
||||
{{ end -}}
|
||||
|
||||
{{- $directionJSFile := printf "%s.language-direction.js" .Language.Lang }}
|
||||
{{- $directionJS := resources.Get "language-direction.js" | resources.ExecuteAsTemplate $directionJSFile . |
|
||||
resources.Minify | resources.Fingerprint }}
|
||||
<script defer src="{{ $directionJS.RelPermalink }}" {{ template "integrity" $directionJS }}></script>
|
||||
|
||||
{{- if .Site.Params.BookServiceWorker -}}
|
||||
{{- $swJS := resources.Get "sw-register.js" | resources.ExecuteAsTemplate "sw.js" . | resources.Minify | resources.Fingerprint }}
|
||||
<script defer src="{{ $swJS.RelPermalink }}" {{ template "integrity" $swJS }}></script>
|
||||
{{- $swJS := resources.Get "sw-register.js" | resources.ExecuteAsTemplate "sw.js" . | resources.Minify |
|
||||
resources.Fingerprint }}
|
||||
<script defer src="{{ $swJS.RelPermalink }}" {{ template "integrity" $swJS }}></script>
|
||||
{{ end -}}
|
||||
|
||||
{{- template "_internal/google_analytics.html" . -}}
|
||||
|
||||
<!-- RSS -->
|
||||
{{- with .OutputFormats.Get "rss" -}}
|
||||
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
|
||||
{{ printf `
|
||||
<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
|
||||
{{ end -}}
|
||||
|
||||
{{ "<!--" | safeHTML }}
|
||||
@ -50,7 +60,7 @@ https://github.com/alex-shpak/hugo-book
|
||||
{{ "-->" | safeHTML }}
|
||||
|
||||
{{- define "integrity" -}}
|
||||
{{- if (urls.Parse .Permalink).Host -}}
|
||||
integrity="{{ .Data.Integrity }}" crossorigin="anonymous"
|
||||
{{- end -}}
|
||||
{{- if (urls.Parse .Permalink).Host -}}
|
||||
integrity="{{ .Data.Integrity }}" crossorigin="anonymous"
|
||||
{{- end -}}
|
||||
{{- end -}}
|
Loading…
Reference in New Issue
Block a user