Skip to content

Commit a20732f

Browse files
committed
♻️ REFACTOR: test_sd_hide_root_title to sd_hide_title front-matter
1 parent 006f348 commit a20732f

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

docs/css_classes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,5 @@ Add CSS animations when loading elements using the `sd-animate-{name}` classes:
292292
- `sd-animate-grow100`
293293
- `sd-animate-grow50`
294294
- `sd-animate-grow50-rot20`
295+
296+
See [uxdesign.cc](https://uxdesign.cc/the-ultimate-guide-to-proper-use-of-animation-in-ux-10bd98614fa9) and [material.io](https://material.io/design/motion/understanding-motion.html#user-education) for good guides to animation.

docs/get_started.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,22 @@ myst_enable_extensions = ["colon_fence"]
2626

2727
## Configuration
2828

29-
To hide the the title header on the landing page (i.e. root document), add the following to your `conf.py`:
30-
31-
```python
32-
sd_hide_root_title = True
29+
To hide the the title header of a page, add the to the top of the page:
30+
31+
::::{tab-set}
32+
:::{tab-item} MyST Markdown
33+
```markdown
34+
---
35+
sd_hide_title: true
36+
---
37+
```
38+
:::
39+
:::{tab-item} RestructuredText
40+
```rst
41+
:sd_hide_title:
3342
```
43+
:::
44+
::::
3445

3546
## Supported browsers
3647

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
sd_hide_title: true
3+
---
4+
15
# sphinx-design
26

37
::::{grid}
@@ -127,4 +131,6 @@ Change the default colors and other CSS.
127131

128132
::::
129133

134+
-----------
135+
130136
Created with inspiration from [Bootstrap](https://getbootstrap.com/) (v5), [Material Design](https://material.io) and [Material-UI](https://material-ui.com/) design frameworks.

sphinx_design/extension.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
def setup_extension(app: Sphinx) -> None:
2929
"""Set up the sphinx extension."""
30-
app.add_config_value("sd_hide_root_title", False, "env")
3130
app.connect("builder-inited", update_css_js)
3231
app.connect("env-updated", update_css_links)
3332
# we override container html visitors, to stop the default behaviour
@@ -143,15 +142,15 @@ class AddFirstTitleCss(SphinxTransform):
143142
default_priority = 699 # priority main
144143

145144
def apply(self):
146-
if not self.app.config.sd_hide_root_title:
145+
hide = False
146+
for docinfo in self.document.traverse(nodes.docinfo):
147+
for name in docinfo.traverse(nodes.field_name):
148+
if name.astext() == "sd_hide_title":
149+
hide = True
150+
break
151+
break
152+
if not hide:
147153
return
148-
# from sphinx 4 master_doc is deprecated for root_doc
149-
try:
150-
if self.env.docname != self.config.root_doc:
151-
return
152-
except Exception:
153-
if self.env.docname != self.config.master_doc:
154-
return
155154
for section in self.document.traverse(nodes.section):
156155
if isinstance(section.children[0], nodes.title):
157156
if "classes" in section.children[0]:

tests/test_snippets.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,33 @@ def test_snippets_myst_post(
105105
)
106106

107107

108-
def test_sd_hide_root_title(
108+
def test_sd_hide_title_rst(
109109
sphinx_builder: Callable[..., SphinxBuilder], file_regression
110110
):
111111
"""Test that the root title is hidden."""
112-
builder = sphinx_builder(
113-
conf_kwargs={"extensions": ["sphinx_design"], "sd_hide_root_title": True}
114-
)
115-
content = "Heading\n-------" + "\n\ncontent"
112+
builder = sphinx_builder()
113+
content = ":sd_hide_title:\n\nHeading\n-------\n\ncontent"
116114
builder.src_path.joinpath("index.rst").write_text(content, encoding="utf8")
117115
builder.build()
118116
file_regression.check(
119117
builder.get_doctree("index", post_transforms=False).pformat(),
118+
basename="sd_hide_title",
119+
extension=".xml",
120+
encoding="utf8",
121+
)
122+
123+
124+
def test_sd_hide_title_myst(
125+
sphinx_builder: Callable[..., SphinxBuilder], file_regression
126+
):
127+
"""Test that the root title is hidden."""
128+
builder = sphinx_builder()
129+
content = "---\nsd_hide_title: true\n---\n\n# Heading\n\ncontent"
130+
builder.src_path.joinpath("index.md").write_text(content, encoding="utf8")
131+
builder.build()
132+
file_regression.check(
133+
builder.get_doctree("index", post_transforms=False).pformat(),
134+
basename="sd_hide_title",
120135
extension=".xml",
121136
encoding="utf8",
122137
)

0 commit comments

Comments
 (0)