Add a workroud for localized dates on the website (#1770)
* Add a workroud for localized dates on the website * Remove options passed to toLocaleDateString * fixes #1748
This commit is contained in:
parent
346c3b2289
commit
efb545ae65
@ -155,5 +155,12 @@ module.exports = {
|
||||
showLastUpdateTime: true,
|
||||
}
|
||||
]
|
||||
],
|
||||
scripts: [
|
||||
{
|
||||
src: '/js/localizeLastUpdatedDate.js',
|
||||
async: true,
|
||||
defer: true
|
||||
}
|
||||
]
|
||||
};
|
||||
|
@ -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"
|
||||
},
|
||||
|
39
website/static/js/localizeLastUpdatedDate.js
Normal file
39
website/static/js/localizeLastUpdatedDate.js
Normal 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);
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue
Block a user