Skip to content

Commit 75909b3

Browse files
12rambaudrammock
andauthored
docs: change rational of the gallery grid (#1390)
* docs: change name of the gallery grid * docs: create a gallery list directive * docs: split the list in 2 categories, images and no images * refactor: simplify the witting of GalleryList * refactor: clean gallery grid * docs: edit documentation of the projectst * refactor: clean * test: remove unraised warnings * fix: generate galleries with the corect keywords * comments/docstrings * fix option name * alphabetize featured projects & remove pyvista * bigger card size for featured; smaller for others * wording * alphabetize "other projects" list (and add pyvista there) * test: pyvista has been moved to other --------- Co-authored-by: Daniel McCloy <[email protected]>
1 parent c610f9a commit 75909b3

File tree

7 files changed

+115
-131
lines changed

7 files changed

+115
-131
lines changed

docs/_extension/gallery_directive.py

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323

2424
TEMPLATE_GRID = """
25-
`````{{grid}} {grid_columns}
26-
{container_options}
25+
`````{{grid}} {columns}
26+
{options}
2727
2828
{content}
2929
@@ -32,15 +32,26 @@
3232

3333
GRID_CARD = """
3434
````{{grid-item-card}} {title}
35-
{card_options}
35+
{options}
3636
3737
{content}
3838
````
3939
"""
4040

4141

42-
class GalleryDirective(SphinxDirective):
43-
"""A directive to show a gallery of images and links in a grid."""
42+
class GalleryGridDirective(SphinxDirective):
43+
"""A directive to show a gallery of images and links in a Bootstrap grid.
44+
45+
The grid can be generated from a YAML file that contains a list of items, or
46+
from the content of the directive (also formatted in YAML). Use the parameter
47+
"class-card" to add an additional CSS class to all cards. When specifying the grid
48+
items, you can use all parameters from "grid-item-card" directive to customize
49+
individual cards + ["image", "header", "content", "title"].
50+
51+
Danger:
52+
This directive can only be used in the context of a Myst documentation page as
53+
the templates use Markdown flavored formatting.
54+
"""
4455

4556
name = "gallery-grid"
4657
has_content = True
@@ -55,6 +66,7 @@ class GalleryDirective(SphinxDirective):
5566
}
5667

5768
def run(self) -> List[nodes.Node]:
69+
"""Create the gallery grid."""
5870
if self.arguments:
5971
# If an argument is given, assume it's a path to a YAML file
6072
# Parse it and load it into the directive content
@@ -70,90 +82,61 @@ def run(self) -> List[nodes.Node]:
7082
else:
7183
yaml_string = "\n".join(self.content)
7284

73-
# Read in YAML so we can generate the gallery
74-
grid_data = safe_load(yaml_string)
75-
85+
# Use all the element with an img-bottom key as sites to show
86+
# and generate a card item for each of them
7687
grid_items = []
77-
for item in grid_data:
78-
# Grid card parameters
79-
options = {}
80-
if "website" in item:
81-
options["link"] = item["website"]
82-
83-
if "class-card" in self.options:
84-
options["class-card"] = self.options["class-card"]
85-
86-
if "img-background" in item:
87-
options["img-background"] = item["img-background"]
88-
89-
if "img-top" in item:
90-
options["img-top"] = item["img-top"]
91-
92-
if "img-bottom" in item:
93-
options["img-bottom"] = item["img-bottom"]
88+
for item in safe_load(yaml_string):
9489

95-
options_str = "\n".join(f":{k}: {v}" for k, v in options.items()) + "\n\n"
90+
# remove parameters that are not needed for the card options
91+
title = item.pop("title", "")
9692

97-
# Grid card content
98-
content_str = ""
99-
if "header" in item:
100-
content_str += f"{item['header']}\n\n^^^\n\n"
93+
# build the content of the card using some extra parameters
94+
header = f"{item.pop('header')} \n^^^ \n" if "header" in item else ""
95+
image = f"![image]({item.pop('image')}) \n" if "image" in item else ""
96+
content = f"{item.pop('content')} \n" if "content" in item else ""
10197

102-
if "image" in item:
103-
content_str += f"![Gallery image]({item['image']})\n\n"
104-
105-
if "content" in item:
106-
content_str += f"{item['content']}\n\n"
98+
# optional parameter that influence all cards
99+
if "class-card" in self.options:
100+
item["class-card"] = self.options["class-card"]
107101

108-
if "footer" in item:
109-
content_str += f"+++\n\n{item['footer']}\n\n"
102+
loc_options_str = "\n".join(f":{k}: {v}" for k, v in item.items()) + " \n"
110103

111-
title = item.get("title", "")
112-
content_str += "\n"
113-
grid_items.append(
114-
GRID_CARD.format(
115-
card_options=options_str, content=content_str, title=title
116-
)
104+
card = GRID_CARD.format(
105+
options=loc_options_str, content=header + image + content, title=title
117106
)
107+
grid_items.append(card)
118108

119-
# Parse the template with Sphinx Design to create an output
120-
container = nodes.container()
109+
# Parse the template with Sphinx Design to create an output container
121110
# Prep the options for the template grid
122-
container_options = {"gutter": 2, "class-container": "gallery-directive"}
123-
if "class-container" in self.options:
124-
container_options[
125-
"class-container"
126-
] += f' {self.options["class-container"]}'
127-
container_options_str = "\n".join(
128-
f":{k}: {v}" for k, v in container_options.items()
129-
)
111+
class_ = "gallery-directive" + f' {self.options.get("class-container", "")}'
112+
options = {"gutter": 2, "class-container": class_}
113+
options_str = "\n".join(f":{k}: {v}" for k, v in options.items())
130114

131115
# Create the directive string for the grid
132116
grid_directive = TEMPLATE_GRID.format(
133-
grid_columns=self.options.get("grid-columns", "1 2 3 4"),
134-
container_options=container_options_str,
117+
columns=self.options.get("grid-columns", "1 2 3 4"),
118+
options=options_str,
135119
content="\n".join(grid_items),
136120
)
121+
137122
# Parse content as a directive so Sphinx Design processes it
123+
container = nodes.container()
138124
self.state.nested_parse([grid_directive], 0, container)
139-
# Sphinx Design outputs a container too, so just use that
140-
container = container.children[0]
141125

142-
# Add extra classes
143-
if self.options.get("container-class", []):
144-
container.attributes["classes"] += self.options.get("class", [])
145-
return [container]
126+
# Sphinx Design outputs a container too, so just use that
127+
return [container.children[0]]
146128

147129

148130
def setup(app: Sphinx) -> Dict[str, Any]:
149131
"""Add custom configuration to sphinx app.
150132
151133
Args:
152134
app: the Sphinx application
135+
153136
Returns:
154137
the 2 parallel parameters set to ``True``.
155138
"""
156-
app.add_directive("gallery-grid", GalleryDirective)
139+
app.add_directive("gallery-grid", GalleryGridDirective)
157140

158141
return {
159142
"parallel_read_safe": True,

docs/_static/contributors.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
- header: "@bollwyvl"
22
image: https://avatars.githubusercontent.com/u/45380
3-
website: https://github.com/bollwyvl
3+
link: https://github.com/bollwyvl
44
- header: "@jarrodmillman"
55
image: https://avatars.githubusercontent.com/u/123428
6-
website: https://github.com/jarrodmillman
6+
link: https://github.com/jarrodmillman
77
- header: "@hoetmaaiers"
88
image: https://avatars.githubusercontent.com/u/468045
9-
website: https://github.com/hoetmaaiers
9+
link: https://github.com/hoetmaaiers
1010
- header: "@jorisvandenbossche"
1111
image: https://avatars.githubusercontent.com/u/1020496
12-
website: https://github.com/jorisvandenbossche
12+
link: https://github.com/jorisvandenbossche
1313
- header: "@damianavila"
1414
image: https://avatars.githubusercontent.com/u/1640669
15-
website: https://github.com/damianavila
15+
link: https://github.com/damianavila
1616
- header: "@drammock"
1717
image: https://avatars.githubusercontent.com/u/1810515
18-
website: https://github.com/drammock
18+
link: https://github.com/drammock
1919
- header: "@choldgraf"
2020
image: https://avatars.githubusercontent.com/u/1839645
21-
website: https://github.com/choldgraf
21+
link: https://github.com/choldgraf
2222
- header: "@12rambau"
2323
image: https://avatars.githubusercontent.com/u/12596392
24-
website: https://github.com/12rambau
24+
link: https://github.com/12rambau
2525
- header: "@trallard"
2626
image: https://avatars.githubusercontent.com/u/23552331
27-
website: https://github.com/trallard
27+
link: https://github.com/trallard

docs/_static/gallery.yaml

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,38 @@
33
# 1. Used by `generate_gallery_images.py` to take snapshots of each item and place an image in `gallery`.
44
# 2. Used by our Gallery Grid directive to create the grid on our `examples/gallery.md` page.
55
#
6-
# title: The title of each gallery item
7-
# website: The website that will be used to create a snapshot of this item.
8-
# An image will be placed in docs/_static/gallery/{sanitized_title}.png
9-
# img-bottom: The location where img-bottoms will be placed for each entry by generate_gallery_img-bottoms.py
10-
# This should follow the form shown above and is roughly the same for all items.
11-
- title: Pandas
12-
website: https://pandas.pydata.org/docs/
13-
img-bottom: ../_static/gallery/pandas.png
14-
- title: NumPy
15-
website: https://numpy.org/doc/stable/
16-
img-bottom: ../_static/gallery/numpy.png
17-
- title: SciPy
18-
website: https://docs.scipy.org/doc/scipy/
19-
img-bottom: ../_static/gallery/scipy.png
6+
# This file should only be modified by maintainer, contributors should add their project
7+
# to the list of `gallery.md`.
8+
- title: ArviZ
9+
link: https://python.arviz.org/
10+
img-bottom: ../_static/gallery/arviz.png
2011
- title: Bokeh
21-
website: https://docs.bokeh.org/en/latest/
12+
link: https://docs.bokeh.org/en/latest/
2213
img-bottom: ../_static/gallery/bokeh.png
23-
- title: CuPy
24-
website: https://docs.cupy.dev/en/stable/index.html
25-
img-bottom: ../_static/gallery/cupy.png
26-
- title: PyVista
27-
website: https://docs.pyvista.org
28-
img-bottom: ../_static/gallery/pyvista.png
14+
- title: Jupyter
15+
link: https://docs.jupyter.org/en/latest/
16+
img-bottom: ../_static/gallery/jupyter.png
17+
- title: Jupyter Book
18+
link: https://jupyterbook.org/en/stable/intro.html
19+
img-bottom: ../_static/gallery/jupyter_book.png
20+
- title: Matplotlib
21+
link: https://matplotlib.org/stable/
22+
img-bottom: ../_static/gallery/matplotlib.png
2923
- title: MNE-Python
30-
website: https://mne.tools/stable/index.html
24+
link: https://mne.tools/stable/index.html
3125
img-bottom: ../_static/gallery/mne-python.png
3226
- title: NetworkX
33-
website: https://networkx.org/documentation/stable/
27+
link: https://networkx.org/documentation/stable/
3428
img-bottom: ../_static/gallery/networkx.png
35-
- title: Fairlearn
36-
website: https://fairlearn.org/main/about/
37-
img-bottom: ../_static/gallery/fairlearn.png
38-
- title: Jupyter Book
39-
website: https://jupyterbook.org/en/stable/intro.html
40-
img-bottom: ../_static/gallery/jupyter_book.png
41-
- title: Binder
42-
website: https://mybinder.readthedocs.io/en/latest/index.html
43-
img-bottom: ../_static/gallery/binder.png
44-
- title: Jupyter
45-
website: https://docs.jupyter.org/en/latest/
46-
img-bottom: ../_static/gallery/jupyter.png
47-
- title: MegEngine
48-
website: https://www.megengine.org.cn/doc/stable/en/index.html
49-
img-bottom: ../_static/gallery/megengine.png
50-
- title: Feature-engine
51-
website: https://feature-engine.readthedocs.io/
52-
img-bottom: ../_static/gallery/feature-engine.png
53-
- title: ArviZ
54-
website: https://python.arviz.org/
55-
img-bottom: ../_static/gallery/arviz.png
29+
- title: NumPy
30+
link: https://numpy.org/doc/stable/
31+
img-bottom: ../_static/gallery/numpy.png
32+
- title: Pandas
33+
link: https://pandas.pydata.org/docs/
34+
img-bottom: ../_static/gallery/pandas.png
35+
- title: SciPy
36+
link: https://docs.scipy.org/doc/scipy/
37+
img-bottom: ../_static/gallery/scipy.png
5638
- title: SEPAL
57-
website: https://docs.sepal.io/en/latest/index.html
39+
link: https://docs.sepal.io/en/latest/index.html
5840
img-bottom: ../_static/gallery/sepal.png
59-
- title: Matplotlib
60-
website: https://matplotlib.org/stable/
61-
img-bottom: ../_static/gallery/matplotlib.png

docs/examples/gallery.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
# Gallery of sites using this theme
22

3-
This is a gallery of documentation built on top of the `pydata-sphinx-theme`.
4-
If you'd like to add your documentation to this list, simply add an entry to [this gallery.yaml file](https://github.com/pydata/pydata-sphinx-theme/blob/main/docs/_static/gallery.yaml) and open a Pull Request to add it.
3+
This is a gallery of documentation sites built with `pydata-sphinx-theme`. If you'd like
4+
to add your documentation to this list, add an entry (in alphabetical order) to the list
5+
at the end of [this page](https://github.com/pydata/pydata-sphinx-theme/blob/main/docs/examples/gallery.md)
6+
and open a Pull Request to add it.
7+
8+
## Featured projects
9+
10+
These projects are our earliest adopters and/or present some interesting customization.
11+
Check their repositories for more information.
512

613
```{gallery-grid} ../_static/gallery.yaml
7-
:grid-columns: "1 2 2 3"
14+
:grid-columns: "1 1 2 2"
15+
```
16+
17+
## Other projects using this theme
18+
19+
Here are some other projects using `pydata-sphinx-theme` for their documentation.
20+
Thanks for your support!
21+
22+
```{gallery-grid}
23+
:grid-columns: "1 2 3 4"
824
25+
- title: Binder
26+
link: https://mybinder.readthedocs.io/en/latest/index.html
27+
- title: CuPy
28+
link: https://docs.cupy.dev/en/stable/index.html
29+
- title: Fairlearn
30+
link: https://fairlearn.org/main/about/
31+
- title: Feature-engine
32+
link: https://feature-engine.readthedocs.io/
33+
- title: MegEngine
34+
link: https://www.megengine.org.cn/doc/stable/en/index.html
35+
- title: PyVista
36+
link: https://docs.pyvista.org
937
```

docs/scripts/generate_collaborators_gallery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{
2222
"header": f"@{collaborator['login']}",
2323
"image": f"https://avatars.githubusercontent.com/u/{collaborator['id']}",
24-
"website": collaborator["html_url"],
24+
"link": collaborator["html_url"],
2525
}
2626
)
2727

docs/scripts/generate_gallery_images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def regenerate_gallery() -> None:
4444
# Visit the page and take a screenshot
4545
for ii in range(3):
4646
try:
47-
page.goto(item["website"])
47+
page.goto(item["link"])
4848
page.screenshot(path=screenshot)
4949
break
5050
except TimeoutError:
51-
print(f"Page visit start timed out for: {item['website']}")
51+
print(f"Page visit start timed out for: {item['link']}")
5252
print(f"Trying again (attempt {ii+2}/3)")
5353

5454
# copy the 404 only if the screenshot file was not manually

tests/warning_list.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ WARNING: image file not readable: _static/gallery/pandas.png
22
WARNING: image file not readable: _static/gallery/numpy.png
33
WARNING: image file not readable: _static/gallery/scipy.png
44
WARNING: image file not readable: _static/gallery/bokeh.png
5-
WARNING: image file not readable: _static/gallery/cupy.png
6-
WARNING: image file not readable: _static/gallery/pyvista.png
75
WARNING: image file not readable: _static/gallery/mne-python.png
86
WARNING: image file not readable: _static/gallery/networkx.png
9-
WARNING: image file not readable: _static/gallery/fairlearn.png
107
WARNING: image file not readable: _static/gallery/jupyter_book.png
11-
WARNING: image file not readable: _static/gallery/binder.png
128
WARNING: image file not readable: _static/gallery/jupyter.png
13-
WARNING: image file not readable: _static/gallery/megengine.png
14-
WARNING: image file not readable: _static/gallery/feature-engine.png
159
WARNING: image file not readable: _static/gallery/arviz.png
1610
WARNING: image file not readable: _static/gallery/sepal.png
1711
WARNING: image file not readable: _static/gallery/matplotlib.png

0 commit comments

Comments
 (0)