[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:
Fabio Manganiello 2023-10-21 22:52:33 +02:00
parent 02049030d0
commit b80a48ec80
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
3 changed files with 127 additions and 1 deletions

View 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)
}
})

View File

@ -0,0 +1,71 @@
a, a:visited {
/* Don't change the color for visited links */
color: var(--pst-color-link) !important;
}
ul.grid {
display: grid;
@media screen and (max-width: 500px) {
grid-template-columns: repeat(1, 1fr);
}
@media screen and (min-width: 501px) and (max-width: 699px) {
grid-template-columns: repeat(2, 1fr);
}
@media screen and (min-width: 700px) {
grid-template-columns: repeat(3, 1fr);
}
}
a.grid-title {
width: 100%;
display: block;
margin: 1.5em 0;
font-size: 1.5em !important;
border-bottom: 1px solid #ccc;
}
ul.grid li {
display: flex;
align-items: center;
margin: 0 10px 10px 0;
padding: 10px;
border: 1px solid #ccc;
border-radius: 15px;
}
ul.grid img {
width: 32px;
margin-right: 5px;
}
ul.grid li code {
width: 100%;
}
ul.grid li code .pre {
width: 100%;
display: block;
white-space: pre-wrap;
}
ul.grid li:hover {
background: linear-gradient(0deg, #e0ffe8, #e3ffff);
}
ul.grid li a {
width: calc(100% - 35px);
display: flex;
justify-content: center;
}
ul.grid li a code {
background: none;
border: none;
}
ul.grid .icon {
width: 32px;
}

View File

@ -112,7 +112,14 @@ html_theme_options = {
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
html_static_path = ['_static']
html_css_files = [
'styles/custom.css',
]
html_js_files = [
'scripts/custom.js',
]
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.