Debian Codegraph @

docs/user_guide/layout.rst

raw
1 ==========================
2 Theme Structure and Layout
3 ==========================
4
5 This section describes some basic ways to control the layout and structure of your documentation.
6 This theme inherits its structure and section terminology from the `Sphinx Basic NG theme <https://sphinx-basic-ng.readthedocs.io/en/latest/>`__.
7
8 Overview of theme layout
9 ========================
10
11 Below is a brief overview of the major layout of this theme.
12 Take a look at the diagram to understand what the major sections are called.
13 Where you can insert component templates in ``html_theme_options``, we include the variable name ``in inline code``.
14 Click on section titles to learn more about them and some basic layout configurations.
15 For complete reference of the existing option please see :ref:`the last section of this page <references>`.
16
17 .. The directives below generate a grid-like layout that mimics the structure of this theme.
18 .. It uses Sphinx Design grids: https://sphinx-design.readthedocs.io/en/latest/grids.html
19
20 .. raw:: html
21
22 <style>
23 .content {
24 min-height: 14rem;
25 justify-content: space-between;
26 display: flex;
27 flex-direction: column;
28 }
29 </style>
30
31 .. grid::
32 :gutter: 0
33 :class-container: sd-text-center
34
35 .. grid-item::
36 :padding: 2
37 :outline:
38 :columns: 12
39
40 .. grid::
41 :margin: 0
42
43 .. grid-item::
44 :padding: 2
45 :columns: 12
46
47 .. button-ref:: layout-header
48 :color: primary
49 :outline:
50
51 .. grid-item::
52 :padding: 2
53 :columns: 2
54
55 Logo
56
57 ``navbar_start``
58
59 .. grid-item::
60 :padding: 2
61 :columns: 4
62
63 Section links
64
65 ``navbar_center``
66
67 .. grid-item::
68 :padding: 2
69 :columns: 4
70
71 Persistent components
72
73 ``navbar_persistent``
74
75 .. grid-item::
76 :padding: 2
77 :columns: 2
78
79 Components
80
81 ``navbar_end``
82
83 .. grid-item::
84 :padding: 2
85 :outline:
86 :columns: 4
87 :class: primary-sidebar
88
89 .. button-ref:: layout-sidebar-primary
90 :color: primary
91 :outline:
92
93 Primary Sidebar
94
95 Links between pages in the active section.
96
97 ``sidebars``
98
99 ``primary_sidebar_end``
100
101 .. grid-item::
102 :columns: 8
103
104 .. grid::
105 :margin: 0
106 :gutter: 0
107
108 .. grid-item::
109 :class: content
110 :padding: 2
111 :columns: 6
112 :outline:
113
114 .. button-ref:: layout-article-header
115 :color: primary
116 :outline:
117
118 Article Header
119
120 ``article_header_start``
121 ``article_header_end``
122
123 **Article Content**
124
125 .. button-ref:: layout-article-footer
126 :color: primary
127 :outline:
128
129 Article Footer
130
131 ``article_footer_items``
132 ``prev_next_area``
133
134 .. grid-item::
135 :padding: 2
136 :columns: 6
137 :outline:
138 :class: sidebar-secondary
139
140 .. button-ref:: layout-sidebar-secondary
141 :color: primary
142 :outline:
143
144 Secondary Sidebar
145
146 Within-page header links
147
148 ``secondary_sidebar_items``
149
150 .. grid::
151 :margin: 0
152 :gutter: 0
153 :outline:
154
155 .. grid-item::
156 :padding: 2
157 :columns: 12
158 :class: footer-content
159
160 .. button-ref:: layout-footer-content
161 :color: primary
162 :outline:
163
164 Footer content
165
166 ``content_footer_items``
167
168 .. grid-item::
169 :padding: 2
170 :outline:
171 :columns: 12
172 :class: footer
173
174 .. button-ref:: layout-footer
175 :color: primary
176 :outline:
177
178 Footer
179
180 ``footer_start``
181 ``footer_center``
182 ``footer_end``
183
184 Horizontal spacing
185 ------------------
186
187 By default, the theme's three columns have fixed widths.
188 The ``primary sidebar`` will snap to the left, the ``secondary sidebar`` will snap to the right, and the ``article content`` will be centered in between.
189
190 - If one of the sidebars is not present, then the ``article content`` will be centered between the other sidebar and the side of the page.
191 - If neither sidebar is present, the ``article content`` will be in the middle of the page.
192
193 If you'd like the ``article content`` to take up more width than its default, use the ``max-width`` CSS property with the following selectors:
194
195 .. code-block:: css
196
197 .bd-main .bd-content .bd-article-container {
198 max-width: 100%; /* default is 60em */
199 }
200
201 The above rule will set the article content max width to the same width as the top navigation bar.
202 To truly use *all* of the available page width, you also need to set the following CSS rule:
203
204 .. code-block:: css
205
206 .bd-page-width {
207 max-width: 100%; /* default is 88rem */
208 }
209
210 This will affect both the article content and the top navigation bar.
211
212 .. note::
213
214 If you use both of the custom CSS rules above, *be sure to keep them as separate
215 rules* in your CSS file.
216 If you combine them, the result will be a CSS selector that is *less specific*
217 than the two default rules in the theme, and your custom CSS will fail to
218 override the theme defaults.
219
220
221 Templates and components
222 ========================
223
224 There are a few major theme sections that you can customize to add/remove
225 built-in components or add your own components. Each section is configured with a
226 list of *HTML templates* — these are snippets of HTML that are inserted into
227 the section by Sphinx.
228
229 You can choose which templates show up in each section, as well as the order in
230 which they appear. This page describes the major areas that you can customize.
231
232 .. note::
233
234 When configuring templates in each section, you may omit the ``.html``
235 suffix after each template if you wish.
236
237
238 .. _layout-header:
239
240 Header / Navigation Bar
241 =======================
242
243 Located in ``sections/header.html``.
244
245 The header is at the top of the page above all other content and contains site-level information.
246
247 Header sections
248 ---------------
249
250 The header is broken up into three sections.
251 Each section is configured in ``conf.py`` with the following configuration:
252
253 - Left section: ``html_theme_options['navbar_start']``
254 - Middle menu: ``html_theme_options['navbar_center']``
255 - Right section: ``html_theme_options['navbar_end']``
256 - Persistent right section: ``html_theme_options['navbar_persistent']``
257
258 By default, the following configuration is used:
259
260 .. code-block:: python
261
262 html_theme_options = {
263 # ...
264 "navbar_start": ["navbar-logo"],
265 "navbar_center": ["navbar-nav"],
266 "navbar_end": ["navbar-icon-links"],
267 "navbar_persistent": ["search-button"]
268 # ...
269 }
270
271 .. warning::
272
273 The *Persistent right section* is placed next to the ``navbar_end``, but its elements will remain visible in the header even on small screens when all other elements are collapsed. It has been design for the ``search-button`` only and we cannot guarantee its compatibility with other components.
274
275 Configure the navbar center alignment
276 -------------------------------------
277
278 By default, the navigation bar center area will align with the content on your
279 page. This equals the following default configuration:
280
281 .. code-block:: python
282
283 html_theme_options = {
284 # ...
285 "navbar_align": "content"
286 # ...
287 }
288
289 If instead, you'd like these items to snap to the left (closer to the logo), use this
290 configuration:
291
292 .. code-block:: python
293
294 html_theme_options = {
295 # ...
296 "navbar_align": "left"
297 # ...
298 }
299
300 If you'd like these items to snap to the right of the page, use this configuration:
301
302 .. code-block:: python
303
304 html_theme_options = {
305 # ...
306 "navbar_align": "right"
307 # ...
308 }
309
310
311 .. _layout-article-header:
312
313 Article Header
314 ==============
315
316 Located in ``sections/header-article.html``.
317
318 The article header is a narrow bar just above the article's content.
319 There are two sub-sections that can have component templates added to them:
320
321 - ``article_header_start`` is aligned to the beginning (left) of the article header.
322 By default, this section has the ``breadcrumbs.html`` component which displays links to parent pages of the current page.
323 - ``article_header_end`` is aligned to the end (right) of the article header.
324 By default, this section is empty.
325
326 .. _layout-sidebar-primary:
327
328 Primary sidebar (left)
329 ======================
330
331 Located in ``sections/sidebar-primary.html``.
332
333 The primary sidebar is just to the left of a page's main content.
334 It is primarily used for between-section navigation.
335 By default, it will show links to any siblings/children of the current active top-level section (corresponding to links in your header navigation bar).
336
337 Configuring it is a bit different from configuring the other sections because configuring the sidebar is natively supported in Sphinx, via the ``html_sidebars`` configuration variable.
338
339 For the primary sidebar only, you can configure templates so that they only show
340 up on certain pages. You do so via a configuration like so in ``conf.py``:
341
342 .. code-block:: python
343
344 html_sidebars = {
345 "<page_pattern>": ["list", "of", "templates"]
346 }
347
348 Any pages that match ``<page_pattern>`` will have their respective templates
349 inserted. You can also ``*`` to do ``glob``-style matching, and may use ``**``
350 to match all pages.
351
352 By default, it has the following configuration:
353
354 .. code-block:: python
355
356 html_sidebars = {
357 "**": ["sidebar-collapse", "sidebar-nav-bs"]
358 }
359
360 - ``sidebar-collapse.html`` - a button that allows users to expand and collapse the sidebar.
361
362 - ``sidebar-nav-bs.html`` - a bootstrap-friendly navigation section.
363
364 When there are no pages to show, it will disappear and potentially add extra space for your page's content.
365
366 Primary sidebar end sections
367 ----------------------------
368
369 There is a special ``<div>`` within the primary sidebar that appears at the
370 bottom of the page, regardless of the content that is above it.
371
372 To control the HTML templates that are within this div, use
373 ``html_theme_options['primary_sidebar_end']`` in ``conf.py``.
374
375 By default, it has the following templates:
376
377 .. code-block:: python
378
379 html_theme_options = {
380 # ...
381 "primary_sidebar_end": ["sidebar-ethical-ads"],
382 # ...
383 }
384
385 ``sidebar-ethical-ads.html`` is a placement for ReadTheDocs's Ethical Ads (will only show up on ReadTheDocs).
386
387 Remove the primary sidebar from pages
388 -------------------------------------
389
390 If you'd like the primary sidebar to be removed from a page, you can use the
391 following configuration in ``conf.py``:
392
393 .. code-block:: python
394
395 html_sidebars = {
396 "pagename": []
397 }
398
399 This works for glob-style patterns as well. For example:
400
401 .. code-block:: python
402
403 html_sidebars = {
404 "folder/*": []
405 }
406
407 If you'd like to remove the primary sidebar from **all** pages of your documentation,
408 use this pattern:
409
410 .. code-block:: python
411
412 html_sidebars = {
413 "**": []
414 }
415
416 .. _layout-footer-content:
417
418 Footer Content
419 ==============
420
421 Located in ``sections/footer-content.html``.
422
423 The footer content is a narrow bar spanning the article's content and the secondary sidebar.
424 It does not contain anything immediately viewable to the reader but is kept as a placeholder in case theme developers wish to re-use it in the future.
425
426
427 .. _layout-sidebar-secondary:
428
429 Secondary Sidebar (right)
430 =========================
431
432 Located in ``sections/sidebar-secondary.html``.
433
434 The in-page sidebar is just to the right of a page's article content and is
435 configured in ``conf.py`` with ``html_theme_options['secondary_sidebar_items']``.
436
437 By default, it has the following templates:
438
439 .. code-block:: python
440
441 html_theme_options = {
442 # ...
443 "secondary_sidebar_items": ["page-toc", "edit-this-page", "sourcelink"],
444 # ...
445 }
446
447 To learn how to further customize or remove the secondary sidebar, please check :doc:`page-toc`.
448
449 .. _layout-article-footer:
450
451 Article Footer
452 ==============
453
454 Located in ``sections/footer-article.html``.
455
456 The article footer exists just below your page's article. By default, It does not contain anything immediately viewable to the reader, but is kept as a placeholder for custom or built-in templates.
457
458 .. code-block:: python
459
460 html_theme_options = {
461 # ...
462 "article_footer_items": [],
463 # ...
464 }
465
466 Hide the previous and next buttons
467 ----------------------------------
468
469 By default, each page of your site will have "previous" and "next" buttons
470 at the bottom displayed in the ``prev_next_area``. You can hide these buttons with the following configuration:
471
472 .. code:: python
473
474 html_theme_options = {
475 "show_prev_next": False
476 }
477
478
479 Content Footer
480 ==============
481
482 Located in ``sections/footer-content.html``.
483
484 The content footer exists below your page's article and secondary sidebar.
485 By default it is empty, but you can add templates to it with the following configuration:
486
487 .. code-block:: python
488
489 html_theme_options = {
490 # ...
491 "content_footer_items": ["your-template.html"],
492 # ...
493 }
494
495 .. _layout-footer:
496
497 Footer
498 ======
499
500 Located in ``sections/footer.html``.
501
502 The footer is just below a page's main content, and is configured in ``conf.py``
503 with ``html_theme_options['footer_start']``, ``html_theme_options['footer_center']`` and ``html_theme_options['footer_end']``.
504
505 By default, ``footer_center`` is empty, and ``footer_start`` and ``footer_end`` have the following templates:
506
507 .. code-block:: python
508
509 html_theme_options = {
510 #...
511 "footer_start": ["copyright", "sphinx-version"],
512 "footer_end": ["theme-version"]
513 #...
514 }
515
516 Within each subsection, components will stack **vertically**.
517 If you'd like them to stack **horizontally** use a custom CSS rule like the following:
518
519 .. code-block:: css
520
521 .footer-items__start, .footer-items__end {
522 flex-direction: row;
523 }
524
525 Built-in components to insert into sections
526 ===========================================
527
528 Below is a list of built-in templates that you can insert into any section.
529 Note that some of them may have CSS rules that assume a specific section (and
530 will be named accordingly).
531
532 .. note::
533
534 When adding/changing/overwritting a component, the ".html" suffix is optional.
535 That's why all of them are displayed without it in the following list.
536
537 .. component-list::
538
539
540 Add your own HTML templates to theme sections
541 =============================================
542
543 If you'd like to add your own custom template to any of these sections, you
544 could do so with the following steps:
545
546 1. Create an HTML file in a folder called ``_templates``. For example, if
547 you wanted to display the version of your documentation using a Jinja
548 template, you could create a file: ``_templates/version.html`` and put the
549 following in it:
550
551 .. code-block:: html
552
553 <!-- This will display the version of the docs -->
554 {{ version }}
555
556 2. Now add the file to your menu items for one of the sections above. For example:
557
558 .. code-block:: python
559
560 html_theme_options = {
561 # ...
562 "navbar_start": ["navbar-logo", "version"],
563 # ...
564 }
565
566 Build date
567 ==========
568
569 By default this theme does not display the build date even when Sphinx's `html_last_updated_fmt <https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_last_updated_fmt>`__ variable is set. If you want the build date displayed, the theme includes a :code:`last-updated` template that you can add to one of the page regions in your ``conf.py``. For example:
570
571 .. code-block:: python
572 :caption: conf.py
573
574 html_theme_options = {
575 "content_footer_items": ["last-updated"],
576 # other settings...
577 }
578
579 If you do specify ``html_last_updated_fmt`` but don't include the :code:`last-updated` template, the theme will still write the build date into a ``meta`` tag in the HTML header, which can be inspected by viewing the page source or extracted with an HTML parser. The tag will look like:
580
581 .. code-block:: html
582
583 <meta name="docbuild:last-update" content="Aug 15, 2023">
584
585 The tag's ``content`` attribute will follow the format specified in the ``html_last_updated_fmt`` configuration variable.
586
587
588 .. _references:
589
590 References
591 ==========
592
593 Please find here the full list of keys you can use in the ``html_theme_options`` in ``conf.py``:
594
595 .. include:: ../../src/pydata_sphinx_theme/theme/pydata_sphinx_theme/theme.conf
596 :code: ini
597 :class: highlight-ini