From 96e27afe281369dc36c349a50d162682d0cc5d42 Mon Sep 17 00:00:00 2001 From: Philipp Salvisberg Date: Sun, 7 Feb 2021 02:38:19 +0100 Subject: [PATCH 1/5] use oraclelinux:8 as base image, update python modules mktools-3.0 image is build based on this docker file. Python modules do not use latest version anymore. This allows to build a compatible docker image anytime locally- --- docker/Dockerfile | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 53396e49..609b8b3a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,32 +1,28 @@ -FROM centos:8 +FROM oraclelinux:8 LABEL maintainer="philipp.salvisberg@trivadis.com" LABEL description="Tools to generate HTML and PDF using Materials for MkDocs and wkhtmltopdf." LABEL build.command="docker build . --tag trivadis/mktools:latest" -# install python, not part of centos -# see https://computingforgeeks.com/how-to-install-python-on-3-on-centos/ -RUN yum -y update -RUN yum -y groupinstall "Development Tools" -RUN yum -y install openssl-devel bzip2-devel libffi-devel -RUN yum -y install wget -RUN wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz -RUN tar xvf Python-3.8.3.tgz -RUN /bin/bash -c 'cd Python-3.8*/; ./configure --enable-optimizations; make altinstall' +# install python +RUN dnf -y update +RUN dnf -y install python38 python38-pip # install git -RUN yum install -y git - -# install python modules (most recent versions) -RUN pip3.8 install --upgrade pip -RUN pip3.8 install mkdocs \ - mkdocs-material \ - mkdocs-awesome-pages-plugin \ - pymdown-extensions \ - mike +RUN dnf -y install git + +# install python modules +# using "--root" should suppress "WARNING: Running pip install with root privileges is generally not a good idea." in future releases +RUN python3 -m pip install --upgrade pip --root / +RUN python3 -m pip install --root / \ + 'mkdocs==1.1.2' \ + 'mkdocs-material==6.2.8' \ + 'mkdocs-awesome-pages-plugin==2.5.0' \ + 'pymdown-extensions==8.1.1' \ + 'mike==0.5.5' # install wkhtmltox 0.12.6 -RUN yum install -y https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.x86_64.rpm +RUN dnf -y install https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos8.x86_64.rpm # set environment ENV LANG=en_US.utf8 From 1aaebbed8bde178988c8a27ad9ee4f0cb4bb82a5 Mon Sep 17 00:00:00 2001 From: Philipp Salvisberg Date: Sun, 7 Feb 2021 02:42:01 +0100 Subject: [PATCH 2/5] changes via "mike install-extras" using mike 0.5.5 --- docs/css/version-select.css | 5 ++++ docs/js/version-select.js | 49 +++++++++++++++++++++++++++++++++++++ mkdocs.yml | 4 +-- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 docs/css/version-select.css create mode 100644 docs/js/version-select.js diff --git a/docs/css/version-select.css b/docs/css/version-select.css new file mode 100644 index 00000000..49079bf4 --- /dev/null +++ b/docs/css/version-select.css @@ -0,0 +1,5 @@ +@media only screen and (max-width:76.1875em) { + #version-selector { + padding: .6rem .8rem; + } +} diff --git a/docs/js/version-select.js b/docs/js/version-select.js new file mode 100644 index 00000000..794b5cc8 --- /dev/null +++ b/docs/js/version-select.js @@ -0,0 +1,49 @@ +window.addEventListener("DOMContentLoaded", function() { + // This is a bit hacky. Figure out the base URL from a known CSS file the + // template refers to... + var ex = new RegExp("/?css/version-select.css$"); + var sheet = document.querySelector('link[href$="version-select.css"]'); + + var ABS_BASE_URL = sheet.href.replace(ex, ""); + var CURRENT_VERSION = ABS_BASE_URL.split("/").pop(); + + function makeSelect(options, selected) { + 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); + select.add(option); + }); + + return select; + } + + var xhr = new XMLHttpRequest(); + xhr.open("GET", ABS_BASE_URL + "/../versions.json"); + xhr.onload = function() { + var versions = JSON.parse(this.responseText); + + var realVersion = versions.find(function(i) { + return i.version === CURRENT_VERSION || + i.aliases.includes(CURRENT_VERSION); + }).version; + + var select = makeSelect(versions.map(function(i) { + return {text: i.title, value: i.version}; + }), realVersion); + select.addEventListener("change", function(event) { + window.location.href = ABS_BASE_URL + "/../" + this.value; + }); + + var container = document.createElement("div"); + container.id = "version-selector"; + container.className = "md-nav__item"; + container.appendChild(select); + + var sidebar = document.querySelector(".md-nav--primary > .md-nav__list"); + sidebar.parentNode.insertBefore(container, sidebar); + }; + xhr.send(); +}); diff --git a/mkdocs.yml b/mkdocs.yml index c7d0bdfe..d69eab77 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -18,10 +18,10 @@ theme: extra_css: - 'stylesheets/extra.css' - + - 'css/version-select.css' extra_javascript: - 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML' - + - 'js/version-select.js' markdown_extensions: - admonition - pymdownx.highlight: From 9c2c8f33f46536fe16ec532a21f688f85831ed1b Mon Sep 17 00:00:00 2001 From: Philipp Salvisberg Date: Sun, 7 Feb 2021 02:43:02 +0100 Subject: [PATCH 3/5] add comment to make clear that this command does not provide a version selector --- tools/serve.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/serve.sh b/tools/serve.sh index 70981d24..9498d8c1 100755 --- a/tools/serve.sh +++ b/tools/serve.sh @@ -1,4 +1,5 @@ #!/bin/bash +# serves from temporary site directory - use during development for live preview of changes in docs directory DATA_DIR="$(cd "$(dirname "${0}")/.." && pwd)" 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" \ No newline at end of file From 756cf664221cf3adb508225741857f20ceb2750f Mon Sep 17 00:00:00 2001 From: Philipp Salvisberg Date: Sun, 7 Feb 2021 02:45:06 +0100 Subject: [PATCH 4/5] convenience script to view sites deployed in local gh-pages branch with version selector --- tools/serve_ghpages.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 tools/serve_ghpages.sh diff --git a/tools/serve_ghpages.sh b/tools/serve_ghpages.sh new file mode 100755 index 00000000..8eac5cda --- /dev/null +++ b/tools/serve_ghpages.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# serves local gh-pages - use to verify deployed sites with version selector before pushing gh-pages branch +DATA_DIR="$(cd "$(dirname "${0}")/.." && pwd)" +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" From f0a3efa19be926dabbcc77ebc1951173a1ba84d2 Mon Sep 17 00:00:00 2001 From: Philipp Salvisberg Date: Sun, 7 Feb 2021 10:50:34 +0100 Subject: [PATCH 5/5] rename serve_ghpages.sh to serve-ghpages.sh --- tools/{serve_ghpages.sh => serve-ghpages.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tools/{serve_ghpages.sh => serve-ghpages.sh} (100%) diff --git a/tools/serve_ghpages.sh b/tools/serve-ghpages.sh similarity index 100% rename from tools/serve_ghpages.sh rename to tools/serve-ghpages.sh