-
-
Notifications
You must be signed in to change notification settings - Fork 845
Use sphinxext-opengraph to generate OpenGraph metadata #953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
conf.py
Outdated
|
||
# sphinxext-opengraph config | ||
ogp_site_url = "https://devguide.python.org/" | ||
ogp_image = "https://devguide.python.org/_static/python-logo.svg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently SVGs are not supported, so we should use a different image.
Should we also add more variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will find another image. The recommended image size is 1200 x 630, should we use a Python logo or something else?
I don't think we need any of the other variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: other variables:
I'll check ogp_custom_meta_tags
for <meta name="description">
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check
ogp_custom_meta_tags
for<meta name="description">
.
We can use ogp_custom_meta_tags
to add it, but it would be hardcoded and we'd like to generate it from each page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommended image size is 1200 x 630, should we use a Python logo or something else?
Since the image is rectangular (and somewhat big), it would be nice if it had both the Python logo and the text "Devguide". If/when we do the same for cpython
(or for the peps
repo), we can have the same logo but different texts, so that the links are easily distinguishable.
This however would require creating new images, so if you don't want to do that, just a simple logo will do (we can always update the image later).
I don't think we need any of the other variables.
ok
We can use
ogp_custom_meta_tags
to add it, but it would be hardcoded and we'd like to generate it from each page.
Right, it would be better if the description was created dynamically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SVG replaced with a PNG of the Python logo + "Devguide".
I wrote a script to create it (hugovk/pixel-tools#15), so we can re-use that for other repos if we want.
I also squashed out the extra bytes from the PNG using optipng -o7 -zm1-9 _static/og-image.png
(57,118 -> 9,573 bytes, 16.76% decrease).
When temporarily setting ogp_image = "https://cpython-devguide--953.org.readthedocs.build/_static/og-image.png"
Facebook's sharing debugger shows the following OG metadata/preview:
Also included og:image:width
and og:image:height
because the debugger said "Using these tags will specify the image to the crawler so that it can render it immediately without having to asynchronously".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new image looks good -- I wonder if we can use the same font used with the logo though.
https://www.python.org/community/logos/ says
The font used in the logo is called "Flux Regular". The PSF owns a copy but we cannot distribute it, except for work on the PSF's behalf.
Further down on the same page it says:
In general, we want the logo to be used as widely as possible to indicate use of Python or suitability for Python. However, please ask first when using a derived version of the logo or when in doubt.
So we should ask there first, and if they agree we can regenerate the logos with the right font.
This is not a blocker by any means though, so we can merge with the current image and recreate it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's taking a while to get the font. It would be nice to get this merged to see how it works when live. Shall we merge this as-is, or with the image removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge it.
I'll ping Deb again about the font and we can update that in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Continued in main thread: #953 (comment))
65f1738
to
d186e52
Compare
conf.py
Outdated
|
||
# sphinxext-opengraph config | ||
ogp_site_url = "https://devguide.python.org/" | ||
ogp_image = "https://devguide.python.org/_static/python-logo.svg" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new image looks good -- I wonder if we can use the same font used with the logo though.
https://www.python.org/community/logos/ says
The font used in the logo is called "Flux Regular". The PSF owns a copy but we cannot distribute it, except for work on the PSF's behalf.
Further down on the same page it says:
In general, we want the logo to be used as widely as possible to indicate use of Python or suitability for Python. However, please ask first when using a derived version of the logo or when in doubt.
So we should ask there first, and if they agree we can regenerate the logos with the right font.
This is not a blocker by any means though, so we can merge with the current image and recreate it later.
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the latest iteration and got this:
The website name works, but the image still doesn't (it loads for a while and then 💩).
This is because it currently points to https://devguide.python.org/_static/og-image.png, so the suggestion below should fix it.
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
I saw that in the source of https://cpython-devguide--953.org.readthedocs.build/ there is a With the On the main page (i.e. |
This would be better fixed upstream, as it will break for other sites using |
Reported at sphinx-doc/sphinxext-opengraph#77 and created PR sphinx-doc/sphinxext-opengraph#78. |
The Also, to help python/docs-community#65, my PR sphinx-doc/sphinxext-opengraph#71 to use Here's a demo branch and build with the URL fixed so the image URL works (hugovk@483ee38) Here's a page in the Facebook sharing debugger: Here's a Slack share (demo and current site): And Discord: |
Noticed you have a Discord example. Adding a "theme-color" meta tag lets you customize the color of the vertical bar on the left side of the Discord embed. |
I found the fonts in https://github.com/python/pythondotorg/tree/main/static/fonts so have regenerated the image using https://github.com/hugovk/pixel-tools/blob/1618b2a09bd5998899958856b7fef4503f95cba2/og_image.py like: python og_image.py --logo tests/python-logo.png --size 210 --font ../pythondotorg/static/fonts/FluxRegular.ttf
...
optipng -o7 -zm1-9 _static/og-image.png # 16.28% decrease Demohttps://hugovk-devguide.readthedocs.io/en/add-og-metadata2/testing/run-write-tests/ Preview in FacebookPreview in Slack |
ogp_custom_meta_tags = [ | ||
'<meta property="og:image:width" content="1200">', | ||
'<meta property="og:image:height" content="630">', | ||
'<meta name="theme-color" content="#3776ab" />', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I looked into using a gradient that matches both colors of the Python logo, but this doesn't seem supported.
Google's SEO checksUsing their PageSpeed Insights tool: https://pagespeed.web.dev/report?url=https%3A%2F%2Fdevguide.python.org%2F&form_factor=desktop
|
Facebook sharing previewhttps://developers.facebook.com/tools/debug/?q=https%3A%2F%2Fdevguide.python.org%2F
|
Add Open Graph metadata using https://github.com/wpilibsuite/sphinxext-opengraph.