Skip to content

Commit 435ac88

Browse files
committed
Convert documentation to reStructuredText
1 parent c3a689f commit 435ac88

12 files changed

+110
-124
lines changed

.github/workflows/builddoc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: >
4040
python -m sphinx
4141
build -M html
42-
./docs/source
42+
./docs
4343
./docs/build
4444
--jobs=auto
4545
--show-traceback

.readthedocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ python:
1616
sphinx:
1717
builder: html
1818
fail_on_warning: true
19-
configuration: docs/source/conf.py
19+
configuration: docs/conf.py

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The extension will automatically retrieve your site URL.
7171
Configuration for automatically creating social media card PNGs for each page.
7272
For more information, see `the social media cards docs`__.
7373

74-
__ https://github.com/sphinx-doc/sphinxext-opengraph/blob/main/docs/source/socialcards.md
74+
__ https://github.com/sphinx-doc/sphinxext-opengraph/blob/main/docs/socialcards.md
7575

7676
``ogp_image``
7777
**Optional.**
File renamed without changes.

docs/source/conf.py renamed to docs/conf.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# -- Path setup --------------------------------------------------------------
1414

15-
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
15+
sys.path.insert(0, str(Path(__file__).parent.parent))
1616

1717
# -- Project information -----------------------------------------------------
1818

@@ -32,7 +32,6 @@
3232
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3333
# ones.
3434
extensions = [
35-
"myst_parser",
3635
"sphinx_design",
3736
"sphinxext.opengraph",
3837
]
@@ -68,7 +67,5 @@
6867
}
6968

7069
# Generate sample social media preview images
71-
path_script = Path(
72-
__file__, "..", "..", "script", "generate_social_card_previews.py"
73-
).resolve()
74-
run(("python", path_script), check=False) # NoQA: S603
70+
path_script = Path(__file__, "..", "script", "generate_social_card_previews.py").resolve()
71+
run((sys.executable, path_script), check=False) # NoQA: S603

docs/index.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. include:: ../README.rst
2+
3+
.. toctree::
4+
:hidden:
5+
6+
socialcards

docs/script/generate_social_card_previews.py

+15-25
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import random
1212
from pathlib import Path
13-
from textwrap import dedent
1413

1514
from sphinxext.opengraph.socialcards import (
1615
MAX_CHAR_DESCRIPTION,
@@ -22,18 +21,21 @@
2221
PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
2322

2423
# Dummy lorem text
25-
lorem = """
26-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
27-
""".split()
24+
lorem = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
25+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
26+
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
27+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
28+
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
29+
proident, sunt in culpa qui officia deserunt mollit anim id est laborum""".split()
2830

2931
kwargs_fig = {
30-
"image": PROJECT_ROOT / "docs/source/_static/og-logo.png",
32+
"image": PROJECT_ROOT / "docs/_static/og-logo.png",
3133
"image_mini": PROJECT_ROOT / "sphinxext/opengraph/_static/sphinx-logo-shadow.png",
3234
}
3335

3436
print("Generating previews of social media cards...")
3537
plt_objects = create_social_card_objects(**kwargs_fig)
36-
embed_text = []
38+
grid_items = []
3739
for perm in range(20):
3840
# Create dummy text description and pagetitle for this iteration
3941
random.shuffle(lorem)
@@ -57,28 +59,16 @@
5759
plt_objects=plt_objects,
5860
)
5961

60-
path_examples_page_folder = PROJECT_ROOT / "docs"
61-
embed_text.append(
62-
dedent(
63-
f"""
64-
````{{grid-item}}
65-
```{{image}} ../{path_out.relative_to(path_examples_page_folder)}
66-
```
67-
````
68-
"""
69-
)
70-
)
62+
path_examples_page_folder = PROJECT_ROOT / "docs" / "tmp"
63+
grid_items.append(f"""\
64+
.. grid-item::
7165
72-
embed_text = "\n".join(embed_text)
73-
embed_text = f"""
74-
`````{{grid}} 2
75-
:gutter: 5
66+
.. image:: ./tmp/{path_out.name}
67+
""")
7668

77-
{embed_text}
78-
`````
79-
"""
69+
embed_text = '.. grid:: 2\n :gutter: 5\n\n' + '\n'.join(grid_items)
8070

81-
# Write markdown text that we can use to embed these images in the docs
71+
# Write text that we can use to embed these images in the docs
8272
(PROJECT_ROOT / "docs/tmp/embed.txt").write_text(embed_text)
8373

8474
print("Done generating previews of social media cards...")

docs/socialcards.rst

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Social media card images
2+
========================
3+
4+
This extension will automatically generate a PNG meant for sharing documentation links on social media platforms.
5+
These cards display metadata about the page that you link to, and are meant to catch the attention of readers.
6+
7+
See `the opengraph.xyz website`__ for a way to preview what your social media cards look like.
8+
Here's an example of what the card for this page looks like:
9+
10+
.. image:: ./tmp/num_0.png
11+
:width: 500
12+
13+
__ https://www.opengraph.xyz/
14+
15+
Disable card images
16+
-------------------
17+
18+
To disable social media card images, use the following configuration:
19+
20+
.. code-block:: python
21+
:caption: conf.py
22+
23+
ogp_social_cards = {
24+
"enable": False
25+
}
26+
27+
Update the top-right image
28+
--------------------------
29+
30+
By default the top-right image will use the image specified by ``html_logo`` if it exists.
31+
To update it, specify another path in the **image** key like so:
32+
33+
.. code-block:: python
34+
:caption: conf.py
35+
36+
ogp_social_cards = {
37+
"image": "path/to/image.png",
38+
}
39+
40+
.. warning::
41+
42+
The image cannot be an SVG
43+
44+
Matplotlib does not support easy plotting of SVG images,
45+
so ensure that your image is a PNG or JPEG file, not SVG.
46+
47+
Customize the text font
48+
-----------------------
49+
50+
By default, the Roboto Flex font is used to render the card text.
51+
52+
You can specify the other font name via ``font`` key:
53+
54+
.. code-block:: python
55+
:caption: conf.py
56+
57+
ogp_social_cards = {
58+
"font": "Noto Sans CJK JP",
59+
}
60+
61+
You might need to install an additional font package on your environment. Also, note that the font name needs to be
62+
discoverable by Matplotlib FontManager.
63+
See `Matplotlib documentation`__
64+
for the information about FontManager.
65+
66+
__ https://matplotlib.org/stable/tutorials/text/text_props.html#default-font
67+
68+
Customize the card
69+
------------------
70+
71+
There are several customization options to change the text and look of the social media preview card.
72+
Below is a summary of these options.
73+
74+
- **site_url**: Set a custom site URL.
75+
- **line_color**: Colour of the border line at the bottom of the card, in hex format.
76+
77+
Example social cards
78+
--------------------
79+
80+
Below are several social cards to give an idea for how this extension behaves with different length and size of text.
81+
82+
.. include:: ./tmp/embed.txt

docs/source/index.md

-9
This file was deleted.

docs/source/socialcards.md

-79
This file was deleted.

noxfile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def docs(session: nox.Session) -> None:
2323
"""Build the documentation. Use `-- live` to build with a live server."""
2424
session.install("--group", "docs")
2525
session.install("-e", ".")
26-
common_args = '-M', 'html', 'docs/source', 'docs/build'
26+
common_args = '-M', 'html', 'docs', 'docs/build'
2727
if "live" in session.posargs:
2828
session.install("ipython")
2929
session.install("sphinx-autobuild")

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ email = "[email protected]"
5454
docs = [
5555
"furo>=2024",
5656
"matplotlib",
57-
"myst-parser>=4",
5857
"sphinx-design",
5958
"sphinx~=8.1.0",
6059
]

0 commit comments

Comments
 (0)