|
| 1 | +""" |
| 2 | +A helper script to test out what social previews look like. |
| 3 | +I should remove this when I'm happy with the result. |
| 4 | +""" |
| 5 | +# %load_ext autoreload |
| 6 | +# %autoreload 2 |
| 7 | + |
| 8 | +from pathlib import Path |
| 9 | +from textwrap import dedent |
| 10 | +from sphinxext.opengraph.socialcards import ( |
| 11 | + render_social_card, |
| 12 | + MAX_CHAR_PAGE_TITLE, |
| 13 | + MAX_CHAR_DESCRIPTION, |
| 14 | +) |
| 15 | +import random |
| 16 | + |
| 17 | +here = Path(__file__).parent |
| 18 | + |
| 19 | +# Dummy lorem text |
| 20 | +lorem = """ |
| 21 | +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 |
| 22 | +""".split() # noqa |
| 23 | + |
| 24 | +kwargs_fig = dict( |
| 25 | + image=here / "../source/_static/og-logo.png", |
| 26 | + image_mini=here / "../../sphinxext/opengraph/_static/sphinx-logo-shadow.png", |
| 27 | +) |
| 28 | + |
| 29 | +print("Generating previews of social media cards...") |
| 30 | +plt_objects = None |
| 31 | +embed_text = [] |
| 32 | +for perm in range(20): |
| 33 | + # Create dummy text description and pagetitle for this iteration |
| 34 | + random.shuffle(lorem) |
| 35 | + title = " ".join(lorem[:100]) |
| 36 | + title = title[: MAX_CHAR_PAGE_TITLE - 3] + "..." |
| 37 | + |
| 38 | + random.shuffle(lorem) |
| 39 | + desc = " ".join(lorem[:100]) |
| 40 | + desc = desc[: MAX_CHAR_DESCRIPTION - 3] + "..." |
| 41 | + |
| 42 | + path_tmp = Path(here / "../tmp") |
| 43 | + path_tmp.mkdir(exist_ok=True) |
| 44 | + path_out = Path(path_tmp / f"num_{perm}.png") |
| 45 | + |
| 46 | + plt_objects = render_social_card( |
| 47 | + path=path_out, |
| 48 | + site_title="Sphinx Social Card Demo", |
| 49 | + page_title=title, |
| 50 | + description=desc, |
| 51 | + siteurl="sphinxext-opengraph.readthedocs.io", |
| 52 | + plt_objects=plt_objects, |
| 53 | + kwargs_fig=kwargs_fig, |
| 54 | + ) |
| 55 | + |
| 56 | + path_examples_page_folder = here / ".." |
| 57 | + embed_text.append( |
| 58 | + dedent( |
| 59 | + f""" |
| 60 | + ````{{grid-item}} |
| 61 | + ```{{image}} ../{path_out.relative_to(path_examples_page_folder)} |
| 62 | + ``` |
| 63 | + ```` |
| 64 | + """ |
| 65 | + ) |
| 66 | + ) |
| 67 | + |
| 68 | +embed_text = "\n".join(embed_text) |
| 69 | +embed_text = f""" |
| 70 | +`````{{grid}} 2 |
| 71 | +:gutter: 5 |
| 72 | +
|
| 73 | +{embed_text} |
| 74 | +````` |
| 75 | +""" |
| 76 | + |
| 77 | +# Write markdown text that we can use to embed these images in the docs |
| 78 | +(here / "../tmp/embed.txt").write_text(embed_text) |
| 79 | + |
| 80 | +print("Done generating previews of social media cards...") |
0 commit comments