Skip to content

Commit 3d64d77

Browse files
committed
fix: handle subtitles in sidebar
1 parent 06d0172 commit 3d64d77

File tree

4 files changed

+60
-28
lines changed

4 files changed

+60
-28
lines changed

docs/_quarto.yml

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,38 +130,33 @@ quartodoc:
130130
- create_inventory
131131
- convert_inventory
132132

133-
- title: "Data models: structural"
133+
- title: "Data models"
134+
135+
- subtitle: "Structural"
134136
desc: |
135137
Classes for specifying the broad structure your docs.
136138
contents:
137-
- kind: "page"
138-
path: "layouts-structure"
139-
flatten: true
140-
contents:
141-
- layout.Layout
142-
- layout.Section
143-
- layout.Page
144-
- layout.SectionElement
145-
- layout.ContentElement
139+
- layout.Layout
140+
- layout.Section
141+
- layout.Page
142+
- layout.SectionElement
143+
- layout.ContentElement
146144

147-
- title: "Data models: docable"
145+
- subtitle: "Docable"
148146
desc: |
149147
Classes representing python objects to be rendered.
150148
contents:
151-
- kind: "page"
152-
path: "layouts-docable"
153-
flatten: true
154-
contents:
155-
- name: layout.Doc
156-
members: []
157-
- layout.DocFunction
158-
- layout.DocAttribute
159-
- layout.DocModule
160-
- layout.DocClass
161-
- layout.Link
162-
- layout.Item
163-
- layout.ChoicesChildren
164-
- title: "Data models: docstring patches"
149+
- name: layout.Doc
150+
members: []
151+
- layout.DocFunction
152+
- layout.DocAttribute
153+
- layout.DocModule
154+
- layout.DocClass
155+
- layout.Link
156+
- layout.Item
157+
- layout.ChoicesChildren
158+
159+
- subtitle: "Docstring patches"
165160
desc: |
166161
Most of the classes for representing python objects live
167162
in [](`griffe.dataclasses`) or [](`griffe.docstrings.dataclasses`).

docs/styles.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,29 @@ html { font-family: 'Inter', sans-serif; }
3636
line-height: 22px;
3737
}
3838

39+
.sidebar-item {
40+
margin-top: 0px;
41+
}
42+
3943
.sidebar-item-section {
4044
padding-top: 16px;
4145
}
4246

4347
.sidebar-section {
4448
padding-left: 0px !important;
4549
}
50+
51+
.sidebar-item-section .sidebar-item-section {
52+
padding-top: 0px;
53+
padding-left: 10px;
54+
}
55+
56+
57+
td:first-child {
58+
text-wrap: nowrap;
59+
text-size-adjust: 100%;
60+
}
61+
62+
td:first-child a {
63+
word-break: normal;
64+
}

quartodoc/autosummary.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,30 @@ def create_inventory(self, items):
558558

559559
def _generate_sidebar(self, blueprint: layout.Layout):
560560
contents = [f"{self.dir}/index{self.out_page_suffix}"]
561+
in_subsection = False
562+
crnt_entry = {}
561563
for section in blueprint.sections:
564+
if section.title:
565+
if crnt_entry:
566+
contents.append(crnt_entry)
567+
568+
in_subsection = False
569+
crnt_entry = {"section": section.title, "contents": []}
570+
elif section.subtitle:
571+
in_subsection = True
572+
562573
links = []
563574
for entry in section.contents:
564575
links.extend(self._page_to_links(entry))
565576

566-
contents.append({"section": section.title, "contents": links})
577+
if in_subsection:
578+
sub_entry = {"section": section.subtitle, "contents": links}
579+
crnt_entry["contents"].append(sub_entry)
580+
else:
581+
crnt_entry["contents"].extend(links)
582+
583+
if crnt_entry:
584+
contents.append(crnt_entry)
567585

568586
return {"website": {"sidebar": {"id": self.dir, "contents": contents}}}
569587

quartodoc/layout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ class Section(_Structural):
7474
subtitle: Optional[str] = None
7575
desc: Optional[str] = None
7676
package: Union[str, None, MISSING] = MISSING()
77-
contents: Optional[ContentList] = None
77+
contents: ContentList = []
7878

7979
def __init__(self, **data):
8080
super().__init__(**data)
8181

8282
# TODO: should these be a custom type? Or can we use pydantic's ValidationError?
83-
if self.title is None and self.subtitle is None and self.contents is None:
83+
if self.title is None and self.subtitle is None and not self.contents:
8484
raise ValueError(
8585
"Section must specify a title, subtitle, or contents field"
8686
)

0 commit comments

Comments
 (0)