Skip to content

Commit

Permalink
Add support for hidden versions in the built-in themes; resolves #187
Browse files Browse the repository at this point in the history
  • Loading branch information
jimporter committed Nov 1, 2023
1 parent c69d11f commit 367fbd0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### New features

- Add support for applying arbitrary properties to documentation versions
- Add support for hiding specific versions from the selector when using the
default themes
- Deploy aliases using symbolic links by default; this can be configured via
`--alias-type` on the command line or `alias_type` in the `mike` MkDocs plugin
- Avoid creating empty commits by default; if you want empty commits, pass
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ is handled.
Each version of your documentation can have any arbitrary properties assigned to
it that you like. You can use these properties to hold extra metadata, and then
your documentation theme can consult those properties to do whatever you like.
When using the built-in MkDocs themes, mike supports one property: `hidden`.
When this is `true`, that version will be hidden from the version selector
(unless it's the current version).

You can get properties via `props` command:

```sh
Expand Down
13 changes: 8 additions & 5 deletions mike/themes/mkdocs/js/version-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ window.addEventListener("DOMContentLoaded", function() {
var ABS_BASE_URL = expandPath(base_url);
var CURRENT_VERSION = ABS_BASE_URL.match(/\/([^\/]+)\/$/)[1];

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

options.forEach(function(i) {
var option = new Option(i.text, i.value, undefined,
i.value === selected);
i.selected);
select.add(option);
});

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

var select = makeSelect(versions.map(function(i) {
return {text: i.title, value: i.version};
}), realVersion);
var select = makeSelect(versions.filter(function(i) {
return i.version === realVersion || !i.properties || !i.properties.hidden;
}).map(function(i) {
return {text: i.title, value: i.version,
selected: i.version === realVersion};
}));
select.addEventListener("change", function(event) {
window.location.href = ABS_BASE_URL + "../" + this.value + "/";
});
Expand Down
13 changes: 8 additions & 5 deletions mike/themes/readthedocs/js/version-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ window.addEventListener("DOMContentLoaded", function() {
var ABS_BASE_URL = expandPath(base_url);
var CURRENT_VERSION = ABS_BASE_URL.match(/\/([^\/]+)\/$/)[1];

function makeSelect(options, selected) {
function makeSelect(options) {
var select = document.createElement("select");

options.forEach(function(i) {
var option = new Option(i.text, i.value, undefined,
i.value === selected);
i.selected);
select.add(option);
});

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

var select = makeSelect(versions.map(function(i) {
return {text: i.title, value: i.version};
}), realVersion);
var select = makeSelect(versions.filter(function(i) {
return i.version === realVersion || !i.properties || !i.properties.hidden;
}).map(function(i) {
return {text: i.title, value: i.version,
selected: i.version === realVersion};
}));
select.id = "version-selector";
select.addEventListener("change", function(event) {
window.location.href = ABS_BASE_URL + "../" + this.value + "/";
Expand Down

0 comments on commit 367fbd0

Please sign in to comment.