Skip to content

Commit

Permalink
fix version handler for new mkdocs
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Jansen <[email protected]>
(cherry picked from commit 020642a)

# 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
  • Loading branch information
farodin91 committed Nov 18, 2023
1 parent 106000e commit 059b7b3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 129 deletions.
Empty file added docs/theme/js/.gitkeep
Empty file.
10 changes: 0 additions & 10 deletions docs/theme/structor-menu.css

This file was deleted.

147 changes: 40 additions & 107 deletions docs/theme/structor-menu.js.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
addMaterialMenu(elt, versions);
26 changes: 14 additions & 12 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 059b7b3

Please sign in to comment.