mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2023-12-21 10:22:58 +01:00
localize post dates
This commit is contained in:
parent
d3d90be8a4
commit
59b35084c6
21
assets/js/datelocale.ts
Normal file
21
assets/js/datelocale.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
function formatDate(date: string | null) {
|
||||||
|
if (!date) return date;
|
||||||
|
return new Intl.DateTimeFormat(process.env.lang_code, {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
// hour:'2-digit',
|
||||||
|
// minute: '2-digit',
|
||||||
|
}).format(new Date(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('Intl' in window) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
for(const span of [...document.querySelectorAll('.localizable-date')]) {
|
||||||
|
var persianDate = formatDate(span.getAttribute('title'));
|
||||||
|
if (persianDate) {
|
||||||
|
span.innerHTML = persianDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -89,6 +89,19 @@
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- /* localize dates */}}
|
||||||
|
{{- if (not site.Params.disableDateLocalization) }}
|
||||||
|
{{ $defines := dict "process.env.lang_code" (printf `"%s"` site.LanguageCode) }}
|
||||||
|
{{ $opts := dict "targetPath" "datelocale.ts" "defines" $defines }}
|
||||||
|
{{- if not site.Params.assets.disableFingerprinting }}
|
||||||
|
{{ $built := resources.Get "js/datelocale.ts" | js.Build $opts | fingerprint }}
|
||||||
|
<script defer crossorigin="anonymous" src="{{ $built.Permalink }}" integrity="{{ $built.Data.Integrity }}"></script>
|
||||||
|
{{- else }}
|
||||||
|
{{ $built := resources.Get "js/datelocale.js" | js.Build $opts }}
|
||||||
|
<script defer crossorigin="anonymous" src="{{ $built.Permalink }}"></script>
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
{{- /* Highlight.js */}}
|
{{- /* Highlight.js */}}
|
||||||
{{- $isHLJSdisabled := (site.Params.assets.disableHLJS | default .Params.disableHLJS ) }}
|
{{- $isHLJSdisabled := (site.Params.assets.disableHLJS | default .Params.disableHLJS ) }}
|
||||||
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}
|
{{- if (and (eq .Kind "page") (ne .Layout "archives") (ne .Layout "search") (not $isHLJSdisabled)) }}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{{- $scratch := newScratch }}
|
{{- $scratch := newScratch }}
|
||||||
|
|
||||||
{{- if not .Date.IsZero -}}
|
{{- if not .Date.IsZero -}}
|
||||||
{{- $scratch.Add "meta" (slice (printf "<span title='%s'>%s</span>" (.Date) (.Date | time.Format (default "January 2, 2006" site.Params.DateFormat)))) }}
|
{{- $scratch.Add "meta" (slice (printf "<span class='localizable-date' title='%s'>%s</span>" (.Date) (.Date | time.Format (default "January 2, 2006" site.Params.DateFormat)))) }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
{{- if (.Param "ShowReadingTime") -}}
|
{{- if (.Param "ShowReadingTime") -}}
|
||||||
|
Loading…
Reference in New Issue
Block a user