-
Notifications
You must be signed in to change notification settings - Fork 334
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
Add warning for stale version of documentation #2012
Conversation
{{#if latestVersion}} | ||
<i class="ri-alert-line sidebar-staleIcon" aria-hidden="true"></i> | ||
{{/if}} | ||
<select class="sidebar-projectVersionsDropdown{{#if latestVersion}} sidebar-staleVersion{{/if}}"{{#if latestVersion}} title="This version is not the latest version of the package."{{/if}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this should be both more SR friendly and mobile friendly with the use of a popover. I am thinking:
{{#if latestVersion}} | |
<i class="ri-alert-line sidebar-staleIcon" aria-hidden="true"></i> | |
{{/if}} | |
<select class="sidebar-projectVersionsDropdown{{#if latestVersion}} sidebar-staleVersion{{/if}}"{{#if latestVersion}} title="This version is not the latest version of the package."{{/if}}> | |
{{#if latestVersion}} | |
<i class="ri-alert-line sidebar-staleIcon" aria-hidden=true popovertarget="staleVersion"></i> | |
<span class="sr-only">This is not the latest version of this package.</span> | |
<div id="staleVersion" popover>This is not the latest version of this package.</div> | |
{{/if}} | |
<select class="sidebar-projectVersionsDropdown{{# if latestVersion}} sidebar-staleVersion{{/if}}"> |
I’m not sure if this will work, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since popover works with clicks and not hover, this won't work as clicking on the icon will open the version selector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SR text addressed in da05c1d
📦 Docs artifacts are ready: https://github.com/elixir-lang/ex_doc/actions/runs/12696202796/artifacts/2408936173 |
You mean something like this? <div class="sidebar-projectVersion" translate="no">
<form autocomplete="off">
<label>
<span class="sidebar-projectVersionsDropdownCaret" aria-hidden="true">▼</span>
<span class="sr-only">Project version</span>
<select class="sidebar-projectVersionsDropdown">
<option translate="no" value="https://hexdocs.pm/elixir/1.18.1">v1.18.1</option>
<option translate="no" value="https://hexdocs.pm/elixir/1.18.0">v1.18.0</option>
<option translate="no" value="https://hexdocs.pm/elixir/1.18.0-rc.0">v1.18.0-rc.0</option>
<option translate="no" value="https://hexdocs.pm/elixir/1.17.3">v1.17.3</option>
</select>
</label>
</form>
<div style="display: inline;padding-left: 8px;color: hsl(30, 90%, 40%);">
<i aria-hidden="true" class="ri-alert-line"></i> <span>Go to latest</span>
</div>
</div> |
Unfortunately it needs to after the version dropdown, otherwise will break the logo positioning in several designs. |
I understand the issue. The width of the
But I didn't try it. We could run this before we inject the select. |
I tested it on iOS and it worked well, so we are good with going this route. However I have found two bugs:
|
1c9f7c5
to
a1abbec
Compare
@josevalim Sorry I was testing my solution and realized it does not work on Safari (needs two clicks since safari does not allow showPicker in some conditions). Tried what you posted and it worked better also the logic is more simple. Can you please test again? |
a1abbec
to
c77a62f
Compare
@alisinabh I have dropped two last comments and this is good to go! Please rebase the PR and submit it so it doesn't contain changes the |
Co-Authored-By: Philip Davies <philip.davies@thekeysupport.com> Rename latestVersion to isStale and use boolean Co-Authored-By: Austin Ziegler <austin@zieglers.ca> Revert "Rename latestVersion to isStale and use boolean" This reverts commit 8ef47f0. Use "Go to latest" link Use actual URL for Go to latest link Adjust select width Fix openVersionSelect function Revert "Adjust select width" This reverts commit 5835e2e. Use width calculation select width Update assets/css/sidebar.css Co-authored-by: José Valim <jose.valim@gmail.com> Update assets/css/sidebar.css Co-authored-by: José Valim <jose.valim@gmail.com>
db42bd3
to
5dd3ff6
Compare
@josevalim Thank you. Rebased and ready to go. @halostatue Thanks for your help and input :) Final screenshots |
💚 💙 💜 💛 ❤️ |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
handleVersionSelected
makes sure that when we are on, say, https://hexdocs.pm/elixir/1.18.0/Task.html and from version selector we choose v1.18.1, we'll end up at https://hexdocs.pm/elixir/1.18.1/Task.html.
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?
Continuation of #1918 (could not push to the same branch since I'm not a maintainer)
Based on feedback in #1918 here is the revised version of warning color and icon added when an outdated version is detected.
@halostatue I tried yellow but I could not make it work on Light mode. It would end-up look green-ish when lightness was reduced.
Screenshots
NOTE: Initially I wanted to put the icon after the version, but the
<select>
HTML element width is set to the largest possible item. This will create an unwanted padding that looks ugly in projects which have versions like1.2.3-RC0
.