Skip to content

Commit 7082231

Browse files
Merge pull request #101 from PhilippSalvisberg/feature/issue-99-version-selector
Feature/issue 99 version selector
2 parents d32ae90 + f0a3efa commit 7082231

File tree

6 files changed

+78
-22
lines changed

6 files changed

+78
-22
lines changed

docker/Dockerfile

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
1-
FROM centos:8
1+
FROM oraclelinux:8
22

33
LABEL maintainer="philipp.salvisberg@trivadis.com"
44
LABEL description="Tools to generate HTML and PDF using Materials for MkDocs and wkhtmltopdf."
55
LABEL build.command="docker build . --tag trivadis/mktools:latest"
66

7-
# install python, not part of centos
8-
# see https://computingforgeeks.com/how-to-install-python-on-3-on-centos/
9-
RUN yum -y update
10-
RUN yum -y groupinstall "Development Tools"
11-
RUN yum -y install openssl-devel bzip2-devel libffi-devel
12-
RUN yum -y install wget
13-
RUN wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz
14-
RUN tar xvf Python-3.8.3.tgz
15-
RUN /bin/bash -c 'cd Python-3.8*/; ./configure --enable-optimizations; make altinstall'
7+
# install python
8+
RUN dnf -y update
9+
RUN dnf -y install python38 python38-pip
1610

1711
# install git
18-
RUN yum install -y git
19-
20-
# install python modules (most recent versions)
21-
RUN pip3.8 install --upgrade pip
22-
RUN pip3.8 install mkdocs \
23-
mkdocs-material \
24-
mkdocs-awesome-pages-plugin \
25-
pymdown-extensions \
26-
mike
12+
RUN dnf -y install git
13+
14+
# install python modules
15+
# using "--root" should suppress "WARNING: Running pip install with root privileges is generally not a good idea." in future releases
16+
RUN python3 -m pip install --upgrade pip --root /
17+
RUN python3 -m pip install --root / \
18+
'mkdocs==1.1.2' \
19+
'mkdocs-material==6.2.8' \
20+
'mkdocs-awesome-pages-plugin==2.5.0' \
21+
'pymdown-extensions==8.1.1' \
22+
'mike==0.5.5'
2723

2824
# install wkhtmltox 0.12.6
29-
RUN yum install -y https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.x86_64.rpm
25+
RUN dnf -y install https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.x86_64.rpm
3026

3127
# set environment
3228
ENV LANG=en_US.utf8

docs/css/version-select.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@media only screen and (max-width:76.1875em) {
2+
#version-selector {
3+
padding: .6rem .8rem;
4+
}
5+
}

docs/js/version-select.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
window.addEventListener("DOMContentLoaded", function() {
2+
// This is a bit hacky. Figure out the base URL from a known CSS file the
3+
// template refers to...
4+
var ex = new RegExp("/?css/version-select.css$");
5+
var sheet = document.querySelector('link[href$="version-select.css"]');
6+
7+
var ABS_BASE_URL = sheet.href.replace(ex, "");
8+
var CURRENT_VERSION = ABS_BASE_URL.split("/").pop();
9+
10+
function makeSelect(options, selected) {
11+
var select = document.createElement("select");
12+
select.classList.add("form-control");
13+
14+
options.forEach(function(i) {
15+
var option = new Option(i.text, i.value, undefined,
16+
i.value === selected);
17+
select.add(option);
18+
});
19+
20+
return select;
21+
}
22+
23+
var xhr = new XMLHttpRequest();
24+
xhr.open("GET", ABS_BASE_URL + "/../versions.json");
25+
xhr.onload = function() {
26+
var versions = JSON.parse(this.responseText);
27+
28+
var realVersion = versions.find(function(i) {
29+
return i.version === CURRENT_VERSION ||
30+
i.aliases.includes(CURRENT_VERSION);
31+
}).version;
32+
33+
var select = makeSelect(versions.map(function(i) {
34+
return {text: i.title, value: i.version};
35+
}), realVersion);
36+
select.addEventListener("change", function(event) {
37+
window.location.href = ABS_BASE_URL + "/../" + this.value;
38+
});
39+
40+
var container = document.createElement("div");
41+
container.id = "version-selector";
42+
container.className = "md-nav__item";
43+
container.appendChild(select);
44+
45+
var sidebar = document.querySelector(".md-nav--primary > .md-nav__list");
46+
sidebar.parentNode.insertBefore(container, sidebar);
47+
};
48+
xhr.send();
49+
});

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ theme:
1818

1919
extra_css:
2020
- 'stylesheets/extra.css'
21-
21+
- 'css/version-select.css'
2222
extra_javascript:
2323
- 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML'
24-
24+
- 'js/version-select.js'
2525
markdown_extensions:
2626
- admonition
2727
- pymdownx.highlight:

tools/serve-ghpages.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# serves local gh-pages - use to verify deployed sites with version selector before pushing gh-pages branch
4+
DATA_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
5+
docker run -v ${DATA_DIR}:/data -p 8000:8000 --rm -it trivadis/mktools bash -c "cd /data; mike serve -a 0.0.0.0:8000"

tools/serve.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
22

3+
# serves from temporary site directory - use during development for live preview of changes in docs directory
34
DATA_DIR="$(cd "$(dirname "${0}")/.." && pwd)"
45
docker run -v ${DATA_DIR}:/data -p 8000:8000 --rm -it trivadis/mktools bash -c "cd /data; mkdocs serve -a 0.0.0.0:8000"

0 commit comments

Comments
 (0)