mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2026-08-06 13:57:42 +00:00
01c62bc636
The datetime attribute was missing from the time element, which is recommended for semantic HTML. Add it using the date_to_xmlschema Liquid filter to ensure proper ISO 8601 format.
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
/**
|
|
* Update month/day to locale datetime
|
|
*
|
|
* Requirement: <https://github.com/iamkun/dayjs>
|
|
*/
|
|
|
|
/* A tool for locale datetime */
|
|
class LocaleHelper {
|
|
static datetimeAttr = 'datetime';
|
|
|
|
static get locale() {
|
|
return document.documentElement.getAttribute('lang').substring(0, 2);
|
|
}
|
|
|
|
static getDatetime(elem) {
|
|
return elem.getAttribute(this.datetimeAttr);
|
|
}
|
|
}
|
|
|
|
export function initLocaleDatetime() {
|
|
dayjs.locale(LocaleHelper.locale);
|
|
dayjs.extend(window.dayjs_plugin_localizedFormat);
|
|
|
|
document
|
|
.querySelectorAll(`[${LocaleHelper.datetimeAttr}]`)
|
|
.forEach((elem) => {
|
|
const date = dayjs(LocaleHelper.getDatetime(elem));
|
|
elem.textContent = date.format(elem.dataset.df);
|
|
delete elem.dataset.df;
|
|
|
|
// setup tooltips
|
|
if ('bsToggle' in elem.dataset && elem.dataset.bsToggle === 'tooltip') {
|
|
// see: https://day.js.org/docs/en/display/format#list-of-localized-formats
|
|
const tooltipText = date.format('llll');
|
|
elem.dataset.bsTitle = tooltipText;
|
|
}
|
|
});
|
|
}
|