Skip to content

Commit

Permalink
Merge pull request #141 from ketikai/master
Browse files Browse the repository at this point in the history
fixed a timeago display bug
  • Loading branch information
timvink authored Aug 17, 2024
2 parents 66b952c + b5beb20 commit 10fee7e
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
// Script to ensure timeago keeps working when
// used with mkdocs-material's instant loading feature
// Script to ensure timeago keeps working when
// used with mkdocs-material's instant loading feature

function getLocale(element) {
var raw_locale = element.getAttribute('locale');
var locale = {
bn: 'bn_IN',
en: 'en_US',
hi: 'hi_IN',
id: 'id_ID',
nb: 'nb_NO',
nn: 'nn_NO',
pt: 'pt_BR',
zh: 'zh_CN'
}[raw_locale];
return locale ? locale : raw_locale;
}

if (typeof document$ !== "undefined") {
document$.subscribe(function() {
var nodes = document.querySelectorAll('.timeago');
if (nodes.length > 0) {
var locale = nodes[0].getAttribute('locale');
timeago.render(nodes, locale);
var locale = getLocale(nodes[0]);
timeago.render(nodes, locale);
}
})
} else {
var nodes = document.querySelectorAll('.timeago');
if (nodes.length > 0) {
var locale = nodes[0].getAttribute('locale');
timeago.render(nodes, locale);
var locale = getLocale(nodes[0]);
timeago.render(nodes, locale);
}
}

0 comments on commit 10fee7e

Please sign in to comment.