From 059b7b3ff56a28a3cb4a938e333b840aac83a56f Mon Sep 17 00:00:00 2001 From: Jan Jansen Date: Sat, 18 Nov 2023 11:42:29 +0100 Subject: [PATCH] fix version handler for new mkdocs Signed-off-by: Jan Jansen (cherry picked from commit 020642ad74b48b9f27bd7995d3666e766445afe9) # Conflicts: # .github/workflows/ci-backend-cql-dummy.yml # .github/workflows/ci-backend-cql.yml # .github/workflows/ci-backend-hbase-dummy.yml # .github/workflows/ci-backend-hbase.yml # .github/workflows/ci-backend-scylla-dummy.yml # .github/workflows/ci-backend-scylla.yml # .github/workflows/ci-benchmark.yml # .github/workflows/ci-core-dummy.yml # .github/workflows/ci-core.yml # .github/workflows/ci-index-es-dummy.yml # .github/workflows/ci-index-es.yml # .github/workflows/ci-index-solr-dummy.yml # .github/workflows/ci-index-solr.yml # .github/workflows/ci-release.yml # codecov.yml # mkdocs.yml --- docs/theme/js/.gitkeep | 0 docs/theme/structor-menu.css | 10 -- docs/theme/structor-menu.js.gotmpl | 147 ++++++++--------------------- mkdocs.yml | 26 ++--- 4 files changed, 54 insertions(+), 129 deletions(-) create mode 100644 docs/theme/js/.gitkeep delete mode 100644 docs/theme/structor-menu.css diff --git a/docs/theme/js/.gitkeep b/docs/theme/js/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/theme/structor-menu.css b/docs/theme/structor-menu.css deleted file mode 100644 index ff4164c5a7..0000000000 --- a/docs/theme/structor-menu.css +++ /dev/null @@ -1,10 +0,0 @@ -@media only screen and (min-width:76.25em) { - .md-nav__item--version { - border-width: 0.09rem; - border-style: solid; - border-radius: .2rem; - padding-left: .625em !important; - padding-bottom: .425em !important; - margin-top: 1.875rem; - } -} \ No newline at end of file diff --git a/docs/theme/structor-menu.js.gotmpl b/docs/theme/structor-menu.js.gotmpl index ad8ee55872..cb9cf9fa10 100644 --- a/docs/theme/structor-menu.js.gotmpl +++ b/docs/theme/structor-menu.js.gotmpl @@ -9,117 +9,50 @@ const versions = [ {{- end}} ]; - // Material theme - function addMaterialMenu(elt, versions) { - const current = versions.find(function (value) { - return value.selected - }) - - const rootLi = document.createElement('li'); - rootLi.classList.add('md-nav__item'); - rootLi.classList.add('md-nav__item--version'); - rootLi.classList.add('md-nav__item--nested'); - - const input = document.createElement('input'); - input.classList.add('md-toggle'); - input.classList.add('md-nav__toggle'); - input.setAttribute('data-md-toggle', 'nav-10000000'); - input.id = "nav-10000000"; - input.type = 'checkbox'; - - rootLi.appendChild(input); - - const lbl01 = document.createElement('label') - lbl01.classList.add('md-nav__link'); - lbl01.setAttribute('for', 'nav-10000000'); - lbl01.textContent = current.text + " "; - - rootLi.appendChild(lbl01); - - const nav = document.createElement('nav') - nav.classList.add('md-nav'); - nav.setAttribute('data-md-component','collapsible'); - nav.setAttribute('data-md-level','1'); - - rootLi.appendChild(nav); - - const lbl02 = document.createElement('label') - lbl02.classList.add('md-nav__title'); - lbl02.setAttribute('for', 'nav-10000000'); - lbl02.textContent = current.text + " "; - - nav.appendChild(lbl02); - - const ul = document.createElement('ul') - ul.classList.add('md-nav__list'); - ul.setAttribute('data-md-scrollfix',''); - - nav.appendChild(ul); - - for (let i = 0; i < versions.length; i++) { - const li = document.createElement('li'); - li.classList.add('md-nav__item'); - - ul.appendChild(li); - - const a = document.createElement('a'); - a.classList.add('md-nav__link'); - if (versions[i].selected) { - a.classList.add('md-nav__link--active'); - } - a.href = window.location.protocol + "//" + window.location.host + "/"; - if (window.location.host.includes(".github.io")) { - a.href = a.href + window.location.pathname.split("/")[1] + "/"; + const current = versions.find(function (value) { + return value.selected + }) + const rootDiv = document.createElement('div'); + rootDiv.classList.add('md-version'); + + const rootLi = document.createElement('button'); + rootLi.classList.add('md-version__current'); + rootLi.textContent = current.text; + rootDiv.appendChild(rootLi) + const ul = document.createElement('ul') + ul.classList.add('md-version__list'); + + + for (let i = 0; i < versions.length; i++) { + const li = document.createElement('li'); + li.classList.add('md-version__item'); + + ul.appendChild(li); + + const a = document.createElement('a'); + a.classList.add('md-version__link'); + if (versions[i].selected) { + a.classList.add('md-nav__link--active'); + } + a.href = window.location.protocol + "//" + window.location.host + "/"; + if (window.location.host.includes(".github.io")) { + a.href = a.href + window.location.pathname.split("/")[1] + "/"; + } + if (versions[i].path) { + a.href = a.href + versions[i].path + "/" + } + a.title = versions[i].text; + a.text = versions[i].text; + + li.appendChild(a); } - if (versions[i].path) { - a.href = a.href + versions[i].path + "/" - } - a.title = versions[i].text; - a.text = versions[i].text; - - li.appendChild(a); - } - - elt.appendChild(rootLi); + rootDiv.appendChild(ul); + elt.appendChild(rootDiv); } -// United theme - -function addMenu(elt, versions){ - const li = document.createElement('li'); - li.classList.add('md-nav__item'); - li.style.cssText = 'padding-top: 1em;'; - - const select = document.createElement('select'); - select.classList.add('md-nav__link'); - select.style.cssText = 'background: white;border: none;color: #00BCD4;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;overflow: hidden;padding: 0.1em;' - select.setAttribute('onchange', 'location = this.options[this.selectedIndex].value;'); - - for (let i = 0; i < versions.length; i++) { - let opt = document.createElement('option'); - opt.value = window.location.protocol + "//" + window.location.host + "/"; - if (versions[i].path) { - opt.value = opt.value + versions[i].path + "/" - } - opt.text = versions[i].text; - opt.selected = versions[i].selected; - select.appendChild(opt); - } - - li.appendChild(select); - elt.appendChild(li); -} - - -const unitedSelector = 'div.navbar.navbar-default.navbar-fixed-top div.container div.navbar-collapse.collapse ul.nav.navbar-nav.navbar-right'; -const materialSelector = 'div.md-container main.md-main div.md-main__inner.md-grid div.md-sidebar.md-sidebar--primary div.md-sidebar__scrollwrap div.md-sidebar__inner nav.md-nav.md-nav--primary ul.md-nav__list'; +const materialSelector = 'header.md-header div.md-header__topic'; let elt = document.querySelector(materialSelector); -if (elt) { - addMaterialMenu(elt, versions); -} else { - const elt = document.querySelector(unitedSelector); - addMenu(elt, versions); -} \ No newline at end of file +addMaterialMenu(elt, versions); diff --git a/mkdocs.yml b/mkdocs.yml index 881c9e7265..f69f33542f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -26,20 +26,22 @@ plugins: - include-markdown theme: - language: 'en' - name: 'material' - feature: - tabs: false - palette: - primary: 'green' - accent: 'teal' - font: false - logo: 'janusgraph-logomark.svg' - favicon: 'favicon.ico' + language: 'en' + name: 'material' + features: + - navigation.footer + - navigation.sections + palette: + primary: 'green' + accent: 'teal' + font: false + logo: 'janusgraph-logomark.svg' + favicon: 'favicon.ico' extra_css: - - 'theme/structor-menu.css' - - 'theme/extra.css' + - 'theme/extra.css' +extra_javascript: + - 'theme/js/structor-menu.js' extra: social: