Skip to content

Commit 0a6079d

Browse files
BobDotComLulalaby
andauthored
docs: Improve toctrees & sidebar formatting (#1773)
* docs: Improve toctrees & sidebar formatting * Undo font change I'm not sure if this change should be made yet, so I'm not going to include it in this PR * Add collapsing attribute lists Co-authored-by: Lala Sabathil <[email protected]>
1 parent 4947403 commit 0a6079d

File tree

7 files changed

+78
-8
lines changed

7 files changed

+78
-8
lines changed

docs/_static/css/custom.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,13 @@ img[src="_images/snake_dark.svg"] {
159159
.sidebar-logo {
160160
max-width: 60%;
161161
}
162+
163+
/*.sidebar-tree {*/
164+
/* font-family: "Saira", monospace;*/
165+
/*}*/
166+
167+
.has-selector-alternative {
168+
transition: max-height 0.2s ease-out;
169+
max-height: 0;
170+
overflow: hidden;
171+
}

docs/_static/js/custom.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,50 @@ document.addEventListener("DOMContentLoaded", () => {
66
// insert ourselves after the element
77
parent.insertBefore(table, element.nextSibling);
88
});
9+
10+
// This can be replaced once the css :has() selector is mainstream
11+
// https://developer.mozilla.org/en-US/docs/Web/CSS/:has
12+
// .reference.internal:has(code) + ul
13+
const tocObjects = document.querySelectorAll(
14+
".toc-tree li > .reference.internal:not(:only-child) code",
15+
);
16+
tocObjects.forEach((e) => {
17+
e.parentElement.parentElement
18+
.querySelector(".reference.internal + ul")
19+
.classList.add("has-selector-alternative");
20+
});
21+
});
22+
23+
// We could use this css instead, but it doesn't allow for the transition
24+
// :not(.scroll-current) > .reference.internal:has(code) + ul:not(:has(.scroll-current))
25+
26+
const getCurrentTocObject = (e) => {
27+
let target = null;
28+
let next = e.target;
29+
while (true) {
30+
if (
31+
next.firstElementChild.classList.contains("reference") &&
32+
next.firstElementChild.firstElementChild?.localName === "code"
33+
) {
34+
target = next;
35+
next = target.parentElement.parentElement;
36+
} else {
37+
break;
38+
}
39+
}
40+
return target?.querySelector("ul");
41+
};
42+
43+
document.addEventListener("gumshoeActivate", (e) => {
44+
const target = getCurrentTocObject(e);
45+
if (target) {
46+
target.style.maxHeight = target.scrollHeight + "px";
47+
}
48+
});
49+
50+
document.addEventListener("gumshoeDeactivate", (e) => {
51+
const target = getCurrentTocObject(e);
52+
if (target) {
53+
target.style.maxHeight = "0px";
54+
}
955
});

docs/ext/bridge/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _discord_ext_bridge:
22

3-
``discord.ext.bridge`` -- A module that bridges slash commands to prefixed commands
4-
===================================================================================
3+
discord.ext.bridge
4+
==================
55

66
.. versionadded:: 2.0
77

docs/ext/commands/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _discord_ext_commands:
22

3-
``discord.ext.commands`` -- Bot commands framework
4-
==================================================
3+
discord.ext.commands
4+
====================
55

66
``Pycord`` offers a lower level aspect on interacting with Discord. Often times, the library is used for the creation of
77
bots. However this task can be daunting and confusing to get correctly the first time. Many times there comes a repetition in

docs/ext/pages/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _discord_ext_pages:
22

3-
``discord.ext.pages`` -- A pagination extension module
4-
======================================================
3+
discord.ext.pages
4+
=================
55

66
.. versionadded:: 2.0
77

docs/ext/tasks/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _discord_ext_tasks:
22

3-
``discord.ext.tasks`` -- asyncio.Task helpers
4-
=============================================
3+
discord.ext.tasks
4+
=================
55

66
.. versionadded:: 1.1.0
77

docs/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,36 @@ Extensions
5959
These extensions help you during development when it comes to common tasks.
6060

6161
.. toctree::
62+
:caption: Extensions
6263
:maxdepth: 1
64+
:hidden:
6365

6466
ext/commands/index.rst
6567
ext/tasks/index.rst
6668
ext/pages/index.rst
6769
ext/bridge/index.rst
6870

71+
- :doc:`ext/commands/index` - Bot commands framework
72+
- :doc:`ext/tasks/index` - asyncio.Task helpers
73+
- :doc:`ext/pages/index` - A pagination extension module
74+
- :doc:`ext/bridge/index` - A module that bridges slash commands to prefixed commands
75+
6976
Meta
7077
----
7178

7279
If you're looking for something related to the project itself, it's here.
7380

7481
.. toctree::
82+
:caption: Meta
7583
:maxdepth: 1
84+
:hidden:
7685

7786
changelog
7887
version_guarantees
7988
migrating_to_v1
8089
migrating_to_v2
90+
91+
- :doc:`changelog` - The changelog for the library.
92+
- :doc:`version_guarantees` - The version guarantees for the library.
93+
- :doc:`migrating_to_v1` - How to migrate from v0.x to v1.x.
94+
- :doc:`migrating_to_v2` - How to migrate from v1.x to v2.x.

0 commit comments

Comments
 (0)