Skip to content

Commit c642705

Browse files
committed
Add description to version selector in docs
Also, move version selector to the right
1 parent e1a1e5e commit c642705

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-34
lines changed

static/css/documentation.css

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
.documentation-header {
2+
position: relative;
3+
}
4+
5+
.version-selector {
6+
position: absolute;
7+
right: 20px;
8+
top: 0;
9+
}
10+
111
.docs-list {
212
display: flex;
313
flex-wrap: wrap;
@@ -41,12 +51,8 @@
4151
}
4252
}
4353

44-
.version-selector {
54+
.version-selector__select {
4555
font-size: 16px;
4656
border: solid 1px #333;
4757
background-color: #fff;
48-
width: 160px;
49-
text-align: center;
50-
text-align-last: center;
51-
visibility: hidden;
5258
}

themes/hugo-sustain/layouts/documentation/list.html

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,38 @@
55
<!-- Header -->
66
{{ partial "header" . }}
77
<div class="container">
8-
<h3>Documentation</h3>
9-
<select class="version-selector">
10-
{{ $latestDocs := .Site.Params.latestDocs }}
11-
{{ range (readDir "./content/documentation") }}
12-
{{ if ne .Name "_index.md"}}
13-
14-
{{ if eq .Name $latestDocs }}
15-
<option value={{ .Name }}>{{ .Name }} - latest</option>
16-
{{ else }}
17-
<option value={{ .Name }}>{{ .Name }}</option>
18-
{{ end }}
19-
20-
{{ end }}
21-
{{ end }}
22-
</select>
8+
<div class="documentation-header">
9+
<div class="version-selector">
10+
<select id="version-selector__select" class="version-selector__select" title="Choose a version">
11+
<option value="">check different version</option>
12+
{{ $latestDocs := .Site.Params.latestDocs }}
13+
{{ range (readDir "./content/documentation") }}
14+
{{ if ne .Name "_index.md"}}
15+
16+
{{ if eq .Name $latestDocs }}
17+
<option value={{ .Name }}>{{ .Name }} - latest</option>
18+
{{ else }}
19+
<option value={{ .Name }}>{{ .Name }}</option>
20+
{{ end }}
21+
22+
{{ end }}
23+
{{ end }}
24+
</select>
25+
</div>
26+
<h3>Documentation</h3>
27+
<h4 class="selected-version">
28+
version: <strong>{{ replace (replace .File.Dir "documentation" "") "/" ""}}</strong>
29+
</h4>
30+
</div>
2331
<div class="panel panel-default">
2432
<div class="docs-list">
2533
{{ range .Data.Pages }}
2634

2735
<a href="{{ .RelPermalink }}" class="doc-item">
28-
<div>
29-
<h5 class="doc-title">{{ .Title | markdownify }}</h5>
30-
<div class="doc-description">{{ .Description }}</div>
31-
</div>
36+
<div>
37+
<h5 class="doc-title">{{ .Title | markdownify }}</h5>
38+
<div class="doc-description">{{ .Description }}</div>
39+
</div>
3240
</a>
3341
{{ end }}
3442
</div>
@@ -37,18 +45,16 @@ <h5 class="doc-title">{{ .Title | markdownify }}</h5>
3745
</div>
3846
<!-- Footer -->
3947
{{ partial "footer" . }}
40-
<script >
41-
window.addEventListener('load', function() {
42-
var versionSelector = document.querySelector('.version-selector');
43-
var versionFromUrl = window.location.href.split('/').filter(part => !!part).reverse()[0];
44-
45-
versionSelector.value = versionFromUrl;
46-
versionSelector.style.visibility = 'visible';
48+
<script>
49+
window.addEventListener('load', function () {
50+
var versionSelector = document.querySelector('.version-selector__select');
4751

48-
versionSelector.addEventListener('change', function(e) {
52+
versionSelector.addEventListener('change', function (e) {
4953
var selectedVersion = e.target.value;
50-
51-
window.location.assign('/documentation/' + selectedVersion);
54+
55+
if(selectedVersion) {
56+
window.location.assign('/documentation/' + selectedVersion);
57+
}
5258
});
5359
});
5460
</script>

0 commit comments

Comments
 (0)