Skip to content

Commit 367fbd0

Browse files
committed
Add support for hidden versions in the built-in themes; resolves #187
1 parent c69d11f commit 367fbd0

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### New features
66

77
- Add support for applying arbitrary properties to documentation versions
8+
- Add support for hiding specific versions from the selector when using the
9+
default themes
810
- Deploy aliases using symbolic links by default; this can be configured via
911
`--alias-type` on the command line or `alias_type` in the `mike` MkDocs plugin
1012
- Avoid creating empty commits by default; if you want empty commits, pass

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ is handled.
248248
Each version of your documentation can have any arbitrary properties assigned to
249249
it that you like. You can use these properties to hold extra metadata, and then
250250
your documentation theme can consult those properties to do whatever you like.
251+
When using the built-in MkDocs themes, mike supports one property: `hidden`.
252+
When this is `true`, that version will be hidden from the version selector
253+
(unless it's the current version).
254+
251255
You can get properties via `props` command:
252256

253257
```sh

mike/themes/mkdocs/js/version-select.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ window.addEventListener("DOMContentLoaded", function() {
3434
var ABS_BASE_URL = expandPath(base_url);
3535
var CURRENT_VERSION = ABS_BASE_URL.match(/\/([^\/]+)\/$/)[1];
3636

37-
function makeSelect(options, selected) {
37+
function makeSelect(options) {
3838
var select = document.createElement("select");
3939
select.classList.add("form-control");
4040

4141
options.forEach(function(i) {
4242
var option = new Option(i.text, i.value, undefined,
43-
i.value === selected);
43+
i.selected);
4444
select.add(option);
4545
});
4646

@@ -55,9 +55,12 @@ window.addEventListener("DOMContentLoaded", function() {
5555
i.aliases.includes(CURRENT_VERSION);
5656
}).version;
5757

58-
var select = makeSelect(versions.map(function(i) {
59-
return {text: i.title, value: i.version};
60-
}), realVersion);
58+
var select = makeSelect(versions.filter(function(i) {
59+
return i.version === realVersion || !i.properties || !i.properties.hidden;
60+
}).map(function(i) {
61+
return {text: i.title, value: i.version,
62+
selected: i.version === realVersion};
63+
}));
6164
select.addEventListener("change", function(event) {
6265
window.location.href = ABS_BASE_URL + "../" + this.value + "/";
6366
});

mike/themes/readthedocs/js/version-select.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ window.addEventListener("DOMContentLoaded", function() {
3434
var ABS_BASE_URL = expandPath(base_url);
3535
var CURRENT_VERSION = ABS_BASE_URL.match(/\/([^\/]+)\/$/)[1];
3636

37-
function makeSelect(options, selected) {
37+
function makeSelect(options) {
3838
var select = document.createElement("select");
3939

4040
options.forEach(function(i) {
4141
var option = new Option(i.text, i.value, undefined,
42-
i.value === selected);
42+
i.selected);
4343
select.add(option);
4444
});
4545

@@ -54,9 +54,12 @@ window.addEventListener("DOMContentLoaded", function() {
5454
i.aliases.includes(CURRENT_VERSION);
5555
}).version;
5656

57-
var select = makeSelect(versions.map(function(i) {
58-
return {text: i.title, value: i.version};
59-
}), realVersion);
57+
var select = makeSelect(versions.filter(function(i) {
58+
return i.version === realVersion || !i.properties || !i.properties.hidden;
59+
}).map(function(i) {
60+
return {text: i.title, value: i.version,
61+
selected: i.version === realVersion};
62+
}));
6063
select.id = "version-selector";
6164
select.addEventListener("change", function(event) {
6265
window.location.href = ABS_BASE_URL + "../" + this.value + "/";

0 commit comments

Comments
 (0)