mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2023-12-21 10:22:58 +01:00
20 lines
519 B
TypeScript
20 lines
519 B
TypeScript
function formatDate(date: string | null) {
|
|
if (!date) return date;
|
|
return new Intl.DateTimeFormat(process.env.lang_code, {
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
}).format(new Date(date));
|
|
}
|
|
|
|
if ('Intl' in window) {
|
|
window.addEventListener('load', () => {
|
|
for(const span of [...document.querySelectorAll('.localizable-date')]) {
|
|
const localizedDate = formatDate(span.getAttribute('title'));
|
|
if (localizedDate) {
|
|
span.innerHTML = localizedDate;
|
|
}
|
|
}
|
|
});
|
|
}
|