Skip to content

Commit b930f1c

Browse files
committed
📚 DOCS: Add article-info documentation
1 parent 621ba67 commit b930f1c

File tree

11 files changed

+150
-26
lines changed

11 files changed

+150
-26
lines changed

docs/additional.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
(special)=
2+
3+
# Additional
4+
5+
These are additional components that are not part of the standard Materials Design or Bootstrap systems.
6+
7+
## `article-info`
8+
9+
This directive is used to display a block of information about an article,
10+
normally positioned just below the title of the article (show below with non-standard outline).
11+
12+
```{article-info}
13+
:avatar: images/ebp-logo.png
14+
:avatar-link: https://executablebooks.org/
15+
:avatar-outline: muted
16+
:author: Executable Books
17+
:date: "Jul 24, 2021"
18+
:read-time: "5 min read"
19+
:class-container: sd-p-2 sd-outline-muted sd-rounded-1
20+
```
21+
22+
`````{dropdown} Syntax
23+
:icon: code
24+
:color: light
25+
26+
````{tab-set-code}
27+
```{literalinclude} ./snippets/myst/article-info.txt
28+
:language: markdown
29+
```
30+
```{literalinclude} ./snippets/rst/article-info.txt
31+
:language: rst
32+
```
33+
````
34+
`````
35+
36+
The `author`, `date`, and `read-time` options are parsed as syntax,
37+
so you can use substitutions like:
38+
39+
- `date`
40+
- MyST: `` :date: "{sub-ref}`today`" ``
41+
- RST: `:data: |today|`
42+
- `read-time`
43+
- MyST: `` :read-time: "{sub-ref}`wordcount-minutes` min read" ``
44+
45+
### options
46+
47+
avatar
48+
: A URI (relative file path or URL) to an image for use as the avatar.
49+
50+
avatar-alt
51+
: Alternative text for the avatar.
52+
53+
avatar-link
54+
: A URL to link to if the avatar icon is clicked.
55+
56+
avatar-outline
57+
: A semantic color to use for the outline of the avatar.
58+
59+
author
60+
: Text to display in the author of of the article.
61+
62+
date
63+
: Text to display in the date of the article.
64+
65+
read-time
66+
: Text to indicate the time to read the article.
67+
68+
class-container
69+
: Additional CSS classes for the container element.
70+
71+
class-avatar
72+
: Additional CSS classes for the avatar element.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
extensions = ["myst_parser", "sphinx_design"]
99

1010
html_theme = os.environ.get("SPHINX_THEME", "alabaster")
11-
html_title = f"Sphinx Design ({html_theme.replace('_', '-')}"
11+
html_title = f"Sphinx Design ({html_theme.replace('_', '-')})"
1212

1313
if html_theme == "alabaster":
1414
html_css_files = [

docs/images/ebp-logo.png

11.2 KB
Loading

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ cards
3131
dropdowns
3232
tabs
3333
badges_buttons
34+
additional
3435
```
3536

3637
```{toctree}

docs/snippets/myst/_article-info.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```{article-info}
2+
:avatar: ebp-logo.png
3+
:avatar-link: https://executablebooks.org/
4+
:avatar-outline: muted
5+
:author: Executable Books
6+
:date: Jul 24, 2021
7+
:read-time: 5 min read
8+
:class-container: sd-p-2 sd-outline-muted sd-rounded-1
9+
```

docs/snippets/rst/article-info.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. article-info::
2+
:avatar: ebp-logo.png
3+
:avatar-link: https://executablebooks.org/
4+
:avatar-outline: muted
5+
:author: Executable Books
6+
:date: Jul 24, 2021
7+
:read-time: 5 min read
8+
:class-container: sd-p-2 sd-outline-muted sd-rounded-1

sphinx_design/article_info.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sphinx.util.docutils import SphinxDirective
77

88
from .icons import get_octicon
9-
from .shared import create_component
9+
from .shared import SEMANTIC_COLORS, create_component, make_choice
1010

1111

1212
def setup_article_info(app: Sphinx):
@@ -24,10 +24,12 @@ class ArticleInfoDirective(SphinxDirective):
2424
"avatar": directives.uri,
2525
"avatar-alt": directives.unchanged,
2626
"avatar-link": directives.uri,
27+
"avatar-outline": make_choice(SEMANTIC_COLORS),
2728
"author": directives.unchanged_required,
2829
"date": directives.unchanged_required,
2930
"read-time": directives.unchanged_required,
30-
"class": directives.class_option,
31+
"class-container": directives.class_option,
32+
"class-avatar": directives.class_option,
3133
}
3234

3335
def _parse_text(
@@ -59,17 +61,13 @@ def run(self) -> List[nodes.Node]:
5961
"sd-mt-2",
6062
"sd-mb-4",
6163
]
62-
+ self.options.get("class", []),
64+
+ self.options.get("class-container", []),
6365
)
6466
self.set_source_info(top_grid)
6567

6668
top_row = create_component(
6769
"grid-row",
68-
[
69-
"sd-row",
70-
"sd-row-cols-2",
71-
"sd-g-1",
72-
],
70+
["sd-row", "sd-row-cols-2", "sd-gx-2", "sd-gy-1"],
7371
)
7472
self.set_source_info(top_row)
7573
top_grid += top_row
@@ -82,11 +80,16 @@ def run(self) -> List[nodes.Node]:
8280
["sd-col", "sd-col-auto", "sd-d-flex", "sd-align-items-center"],
8381
)
8482
self.set_source_info(avatar_column)
83+
avatar_classes = ["sd-avatar-sm"]
84+
if "avatar-outline" in self.options:
85+
avatar_classes.append(f"sd-outline-{self.options['avatar-outline']}")
86+
if "class-avatar" in self.options:
87+
avatar_classes += self.options["class-avatar"]
8588
avatar_image = nodes.image(
8689
"",
8790
uri=avatar_uri,
8891
alt=self.options.get("avatar-alt", ""),
89-
classes=["sd-avatar-sm"],
92+
classes=avatar_classes,
9093
)
9194
self.set_source_info(avatar_image)
9295
if self.options.get("avatar-link"):

tests/test_snippets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
def write_assets(src_path: Path):
1515
"""Write additional assets to the src directory."""
1616
src_path.joinpath("snippet.py").write_text("a = 1")
17+
src_path.joinpath("ebp-logo.png").touch()
1718

1819

1920
@pytest.mark.parametrize(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<document source="index">
2+
<section ids="heading" names="heading">
3+
<title>
4+
Heading
5+
<container classes="sd-container-fluid sd-sphinx-override sd-p-0 sd-mt-2 sd-mb-4 sd-p-2 sd-outline-muted sd-rounded-1" design_component="grid-container" is_div="True">
6+
<container classes="sd-row sd-row-cols-2 sd-gx-2 sd-gy-1" design_component="grid-row" is_div="True">
7+
<container classes="sd-col sd-col-auto sd-d-flex sd-align-items-center" design_component="grid-item" is_div="True">
8+
<reference refuri="https://executablebooks.org/">
9+
<image alt="" candidates="{'*': 'ebp-logo.png'}" classes="sd-avatar-sm sd-outline-muted" uri="ebp-logo.png">
10+
<container classes="sd-col sd-d-flex sd-align-items-center" design_component="grid-item" is_div="True">
11+
<container classes="sd-container-fluid sd-sphinx-override" design_component="grid-container" is_div="True">
12+
<container classes="sd-row sd-row-cols-2 sd-row-cols-xs-2 sd-row-cols-sm-3 sd-row-cols-md-3 sd-row-cols-lg-3 sd-gx-3 sd-gy-1" design_component="grid-row" is_div="True">
13+
<container classes="sd-col sd-col-auto sd-d-flex sd-align-items-center" design_component="grid-item" is_div="True">
14+
<paragraph classes="sd-p-0 sd-m-0">
15+
Executable Books
16+
<container classes="sd-col sd-col-auto sd-d-flex sd-align-items-center" design_component="grid-item" is_div="True">
17+
<paragraph classes="sd-p-0 sd-m-0">
18+
<raw classes="sd-pr-2" format="html" xml:space="preserve">
19+
<svg version="1.1" width="16" height="16" class="sd-octicon sd-octicon-calendar" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M4.75 0a.75.75 0 01.75.75V2h5V.75a.75.75 0 011.5 0V2h1.25c.966 0 1.75.784 1.75 1.75v10.5A1.75 1.75 0 0113.25 16H2.75A1.75 1.75 0 011 14.25V3.75C1 2.784 1.784 2 2.75 2H4V.75A.75.75 0 014.75 0zm0 3.5h8.5a.25.25 0 01.25.25V6h-11V3.75a.25.25 0 01.25-.25h2zm-2.25 4v6.75c0 .138.112.25.25.25h10.5a.25.25 0 00.25-.25V7.5h-11z"></path></svg>
20+
Jul 24, 2021
21+
<container classes="sd-col sd-col-auto sd-d-flex sd-align-items-center" design_component="grid-item" is_div="True">
22+
<paragraph classes="sd-p-0 sd-m-0">
23+
<raw classes="sd-pr-2" format="html" xml:space="preserve">
24+
<svg version="1.1" width="16" height="16" class="sd-octicon sd-octicon-clock" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zm.5 4.75a.75.75 0 00-1.5 0v3.5a.75.75 0 00.471.696l2.5 1a.75.75 0 00.557-1.392L8.5 7.742V4.75z"></path></svg>
25+
5 min read

0 commit comments

Comments
 (0)