Merge branch 'master' into inheritdependencies

This commit is contained in:
Hannes Harnisch 2021-12-11 23:15:53 +01:00 committed by GitHub
commit 03cdefcce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 2 deletions

View File

@ -155,5 +155,12 @@ module.exports = {
showLastUpdateTime: true,
}
]
],
scripts: [
{
src: '/js/localizeLastUpdatedDate.js',
async: true,
defer: true
}
]
};

View File

@ -12,8 +12,8 @@
"clear": "docusaurus clear"
},
"dependencies": {
"@docusaurus/core": "2.0.0-beta.6",
"@docusaurus/preset-classic": "2.0.0-beta.6",
"@docusaurus/core": "2.0.0-beta.9",
"@docusaurus/preset-classic": "2.0.0-beta.9",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},

View File

@ -0,0 +1,39 @@
function waitForElementToChange(selector) {
return new Promise(resolve => {
const observer = new MutationObserver(() => {
const element = document.querySelector(selector)
if (element) {
resolve(element);
observer.disconnect();
}
});
observer.observe(document.body, {
characterData: true,
childList: true,
subtree: true
});
});
}
function localizeTimeElement(element) {
if (element instanceof HTMLTimeElement && element.hasAttribute('datetime')) {
const iso8601 = element.getAttribute('datetime');
const date = new Date(iso8601);
element.textContent = date.toLocaleDateString();
}
}
(async() => {
while(true) {
const selector = '.theme-last-updated time';
// if it exists then take it
let timeElement = document.querySelector(selector);
localizeTimeElement(timeElement);
// wait for element to change (or appear if it didn't exist)
timeElement = await waitForElementToChange(selector);
localizeTimeElement(timeElement);
}
})();