Skip to content
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 links to jump to latest version of docs #1918

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions assets/css/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@
display: none;
}

.sidebar .sidebar-projectVersionsLatestLink {
border-left: var(--navTabBorderWidth) solid var(--sidebarLanguageAccentBar);
padding: 0 10px;
background-color: var(--sidebarAccentMain);
}

.sidebar .sidebar-projectVersionsLatestLink a {
color: var(--sidebarBackground);
font-weight: bold;
;
}

.sidebar .sidebar-listNav {
display: flex;
margin: 0;
Expand Down
5 changes: 5 additions & 0 deletions assets/js/handlebars/templates/versions-dropdown.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
</option>
{{/each}}
</select>
{{#if latestUrl }}
<br />
<span class="sidebar-projectVersionsLatestLink"><a href="{{latestUrl}}">View latest
({{latestVersion}})</a></span>
{{/if}}
</label>
</form>
12 changes: 8 additions & 4 deletions assets/js/sidebar/sidebar-version-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ export function initialize () {
const versionsContainer = qs(VERSIONS_CONTAINER_SELECTOR)
// Initially the container contains only text with the current version
const currentVersion = versionsContainer.textContent.trim()
const latestVersionNode = versionNodes.find(node => node.latest)
const latestVersion = latestVersionNode?.version !== currentVersion ? latestVersionNode?.version : null
const latestUrl = latestVersionNode?.version !== currentVersion ? latestVersionNode?.url : null

const nodes = decorateVersionNodes(versionNodes, currentVersion)

renderVersionsDropdown({ nodes })
renderVersionPicker(nodes, latestVersion, latestUrl)
}
}

function renderVersionsDropdown ({ nodes }) {
function renderVersionPicker (nodes, latestVersion, latestUrl) {
const versionsContainer = qs(VERSIONS_CONTAINER_SELECTOR)
const versionsDropdownHtml = Handlebars.templates['versions-dropdown']({ nodes })
versionsContainer.innerHTML = versionsDropdownHtml
const versionPickerHtml = Handlebars.templates['versions-dropdown']({ nodes, latestVersion, latestUrl })
versionsContainer.innerHTML = versionPickerHtml

qs(VERSIONS_DROPDOWN_SELECTOR).addEventListener('change', handleVersionSelected)
}
Expand Down