Skip to content

Commit 4ad988f

Browse files
committed
Update readme.md and adjust image:alt functionality
1 parent b846603 commit 4ad988f

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,37 @@ ogp_custom_meta_tags = [
6262
```
6363

6464
## Per Page Overrides
65-
[Field lists](https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html) are used to allow you to override certain settings on each page.
65+
[Field lists](https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html) are used to allow you to override certain settings on each page and set unsupported arbitrary OpenGraph tags.
6666

6767
Make sure you place the fields at the very start of the document such that Sphinx will pick them up and also won't build them into the html.
6868

6969
### Overrides
70+
These are some overrides that can be used, you can actually override any tag and field lists will always take priority.
7071

71-
* `:ogp-description-length:`
72-
* Configure the amount of characters to grab for the description of the page. If the value isn't a number it will fall back to `ogp_description_length`.
73-
* `:ogp-description:`
72+
* `:og_description_length:`
73+
* Configure the amount of characters to grab for the description of the page. If the value isn't a number it will fall back to `ogp_description_length`. Note the slightly different syntax because this isn't directly an OpenGraph tag.
74+
* `:og:description:`
7475
* Lets you override the description of the page.
75-
* `:ogp-title:`
76+
* `:og:title:`
7677
* Lets you override the title of the page.
77-
* `:ogp-type:`
78+
* `:og:type:`
7879
* Override the type of the page, for the list of available types take a look at https://ogp.me/#types.
79-
* `:ogp-image:`
80+
* `:ogp:image:`
8081
* Set the image for the page.
81-
* `:ogp-image-alt:`
82-
* Will be ignored if the image isn't set with the above field, if the image is set, sets the alt text for it.
82+
* `:ogp:image:alt:`
83+
* Sets the alt text. Will be ignored if there is no image set.
8384

8485
### Example
8586
Remember that the fields **must** be placed at the very start of the file. You can verify Sphinx has picked up the fields if they aren't shown in the final html file.
8687

8788
```rst
88-
:ogp-description: New description
89-
:ogp-image: http://example.org/image.png
90-
:ogp-image-alt: Example Image
89+
:og:description: New description
90+
:og:image: http://example.org/image.png
91+
:og:image:alt: Example Image
9192
```
9293

93-
## Arbitrary Tags
94-
Additionally, you can use field lists to add any arbitrary OpenGraph tag not supported by the extension. The syntax for arbitrary tags is `:og:tag: content`. For Example:
94+
### Arbitrary Tags
95+
Additionally, you can use field lists to add any arbitrary OpenGraph tag not supported by the extension. The syntax for arbitrary tags is the same with `:og:tag: content`. For Example:
9596

9697
```rst
9798
:og:video: http://example.org/video.mp4

sphinxext/opengraph/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def get_tags(
109109
ogp_use_first_image = False
110110
ogp_image_alt = fields.get("og:image:alt")
111111
fields.pop("og:image", None)
112-
fields.pop("og:image:alt", None)
113112
else:
114113
image_url = config["ogp_image"]
115114
ogp_use_first_image = config["ogp_use_first_image"]
116-
ogp_image_alt = config["ogp_image_alt"]
115+
ogp_image_alt = fields.get("og:image:alt", config["ogp_image_alt"])
116+
fields.pop("og:image:alt", None)
117117

118118
if ogp_use_first_image:
119119
first_image = doctree.next_node(nodes.image)

0 commit comments

Comments
 (0)