forked from platypush/platypush
[Docs] Added custom style to the main doc page.
Component lists are now displayed in a grid format, each accompained by an icon.
This commit is contained in:
parent
02049030d0
commit
b80a48ec80
3 changed files with 127 additions and 1 deletions
docs/source/_static/scripts
48
docs/source/_static/scripts/custom.js
Normal file
48
docs/source/_static/scripts/custom.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const processList = (list, level, addTitle) => {
|
||||
const title = list.parentElement.querySelector('a')
|
||||
list.classList.add('grid')
|
||||
if (addTitle)
|
||||
title.classList.add('grid-title')
|
||||
|
||||
list.querySelectorAll(`li.toctree-l${level}`).forEach((item) => {
|
||||
const link = item.querySelector('a')
|
||||
if (link) {
|
||||
item.style.cursor = 'pointer'
|
||||
item.addEventListener('click', () => link.click())
|
||||
}
|
||||
|
||||
const name = item.querySelector('a').innerText
|
||||
const img = document.createElement('img')
|
||||
img.src = `https://static.platypush.tech/icons/${name.toLowerCase()}-64.png`
|
||||
img.alt = ' '
|
||||
item.prepend(img)
|
||||
})
|
||||
}
|
||||
|
||||
const tocWrappers = document.querySelectorAll('.toctree-wrapper.compound')
|
||||
|
||||
if (!tocWrappers.length) {
|
||||
return
|
||||
}
|
||||
|
||||
if (window.location.pathname.endsWith('/index.html')) {
|
||||
if (tocWrappers.length < 2) {
|
||||
return
|
||||
}
|
||||
|
||||
const referenceLists = [
|
||||
...tocWrappers[1].querySelectorAll('ul li.toctree-l1 ul')
|
||||
].slice(0, 4)
|
||||
|
||||
referenceLists.forEach((list) => processList(list, 2, true))
|
||||
} else if (window.location.pathname.endsWith('/plugins.html') || window.location.pathname.endsWith('/backends.html')) {
|
||||
if (tocWrappers.length < 1) {
|
||||
return
|
||||
}
|
||||
|
||||
const list = tocWrappers[0].querySelector('ul')
|
||||
if (list)
|
||||
processList(list, 1, false)
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue