-
Notifications
You must be signed in to change notification settings - Fork 345
Add warning for stale version of documentation #2012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,32 @@ if (!isEmbedded) { | |
isCurrentVersion: node.version === currentVersion | ||
})) | ||
|
||
versionsContainer.innerHTML = versionsDropdownTemplate({ nodes }) | ||
const latestVersionNode = versionNodes.find(node => node.latest) | ||
const latestVersion = latestVersionNode?.version !== currentVersion ? latestVersionNode?.url : null | ||
|
||
qs(VERSIONS_DROPDOWN_SELECTOR).addEventListener('change', handleVersionSelected) | ||
versionsContainer.innerHTML = versionsDropdownTemplate({ nodes, latestVersion}) | ||
|
||
const select = qs(VERSIONS_DROPDOWN_SELECTOR) | ||
select.addEventListener('change', handleVersionSelected) | ||
adjustWidth(select) | ||
} | ||
} | ||
|
||
// Function to adjust the width of the select element | ||
function adjustWidth (select) { | ||
// Create a temporary element to measure the width | ||
const temp = document.createElement('span') | ||
temp.style.visibility = 'hidden' | ||
temp.style.position = 'absolute' | ||
temp.style.whiteSpace = 'nowrap' | ||
temp.style.font = window.getComputedStyle(select).font | ||
temp.textContent = select.options[select.selectedIndex].text | ||
|
||
document.body.appendChild(temp) | ||
select.style.width = `${temp.offsetWidth + 20}px` | ||
document.body.removeChild(temp) | ||
} | ||
|
||
function handleVersionSelected (event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it'd be nice for "Go to latest" to work similarly, preserve relative path. I'm not very well versed in JS but this is a PoC (copy pasting the implementation with minor changes) for this functionality: diff --git a/assets/js/sidebar/sidebar-version-select.js b/assets/js/sidebar/sidebar-version-select.js
index 48968c88..de80813f 100644
--- a/assets/js/sidebar/sidebar-version-select.js
+++ b/assets/js/sidebar/sidebar-version-select.js
@@ -34,6 +34,9 @@ if (!isEmbedded) {
const select = qs(VERSIONS_DROPDOWN_SELECTOR)
select.addEventListener('change', handleVersionSelected)
adjustWidth(select)
+
+ const versionsGoToLatest = qs(".sidebar-staleVersion a")
+ versionsGoToLatest.addEventListener('click', handleGoToLatestClicked)
}
}
@@ -67,6 +70,22 @@ function handleVersionSelected (event) {
})
}
+function handleGoToLatestClicked (event) {
+ const url = this.href
+ const pathSuffix = window.location.pathname.split('/').pop() + window.location.hash
+ const otherVersionWithPath = `${url}/${pathSuffix}`
+ event.preventDefault();
+
+ checkUrlExists(otherVersionWithPath)
+ .then(exists => {
+ if (exists) {
+ window.location.href = otherVersionWithPath
+ } else {
+ window.location.href = url
+ }
+ })
+} @alisinabh if this piques your interest perhaps you could send another PR? |
||
const url = event.target.value | ||
const pathSuffix = window.location.pathname.split('/').pop() + window.location.hash | ||
|
Uh oh!
There was an error while loading. Please reload this page.