Skip to content
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

Docs: generate social media cards per page #129120

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Jan 21, 2025

For python/docsbuild-scripts#147, followup to #129085, partner to python/docsbuild-scripts#242.

Let's check the performance of this on 3.14 first, to make sure the extra images don't slow the build up too much or take up too much space.


📚 Documentation preview 📚: https://cpython-previews--129120.org.readthedocs.build/

@hugovk
Copy link
Member Author

hugovk commented Jan 21, 2025

Here's the docs for the social cards: https://sphinxext-opengraph.readthedocs.io/en/latest/socialcards.html

This generates a Doc/build/html/_images/social_previews/ directory of 509 PNG images taking 40.9 MB, like summary_library_mm_8b5ad9c4.png:

summary_library_mm_8b5ad9c4

It removes HTML from the page head like:

<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
...
<meta property="og:image:width" content="200" />
<meta property="og:image:height" content="200" />

And adds:

<meta property="og:image:width" content="1146" />
<meta property="og:image:height" content="600" />
<meta property="og:image" content="https://docs.python.org/3/_images/social_previews/summary_library_mm_8b5ad9c4.png" />
<meta property="og:image:alt" content="The modules described in this chapter implement various algorithms or interfaces that are mainly useful for multimedia applications. They are available at th..." />
...
<meta name="twitter:card" content="summary_large_image" />

There's a problem: we're referring to a file at https://docs.python.org/3/_images/social_previews/summary_library_mm_8b5ad9c4.png when it will really be at https://docs.python.org/3.14/_images/social_previews/summary_library_mm_8b5ad9c4.png for 3.14.

This comes from ogp_site_url = 'https://docs.python.org/3/'

It didn't matter before that all versions referred to the static https://docs.python.org/3/_static/og-image.png logo.

@hugovk
Copy link
Member Author

hugovk commented Jan 21, 2025

Build times:


Images are only built when the create-social-cards tag is set, currently only on the docs server: python/docsbuild-scripts#242. We'll check build times on the server after this is merged.


The default RTD build time doesn't change because the create-social-cards tag isn't set so it doesn't create images. But for indicative times:

It might be useful to have them on RTD for testing social cards, but we can decide on that later.


Locally we also don't build images for the same reason, but on macOS:

  • Without images: 34s
  • With images: 45s

I expect it would be slower on older systems, and there's not much need for them locally. It's not too hard to enable it if needed (don't define ogp_image in conf.py, add matplotlib to requirements.txt) and we can decide later if we want it locally.

@hugovk hugovk marked this pull request as draft January 21, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants