astrojuanlu / sphinx-github-role

A github role for Sphinx
https://sphinx-github-role.readthedocs.io
BSD 2-Clause "Simplified" License
5 stars 1 forks source link

Float social media previews? #10

Open astrojuanlu opened 2 years ago

astrojuanlu commented 2 years ago

Wouldn't it be cool if we could show a modal or tooltip with these cool social media previews?

Screenshot 2021-11-21 at 17-31-23 Card Validator Twitter Developers

(source: https://cards-dev.twitter.com/validator)

Content:

<meta name="twitter:image:src" content="https://opengraph.githubassets.com/d0b6e212f5531e99b4deb14274afa748ddb99ff75bc5d1d8e28d1034ffa2e62d/poliastro/poliastro/pull/1184" /><meta name="twitter:site" content="@github" /><meta name="twitter:card" content="summary_large_image" /><meta name="twitter:title" content="Move flyby computation to core by Yash-10 · Pull Request #1184 · poliastro/poliastro" /><meta name="twitter:description" content="This PR tries to move computations for threebody flybys to core.
Thanks!" />

pinging @humitos as my local sphinx-hoverxref expert, and @choldgraf because I've seen you mention this topic a few times on Twitter

choldgraf commented 2 years ago

I agree it would be very cool! (but I have no idea how to do it haha)

humitos commented 2 years ago

This looks great! The library that I used for sphinx-hoverxref is https://www.heteroclito.fr/modules/tooltipster/ and it's really simple to use. We would need to know the github image URL from that card at build time (this URL https://opengraph.githubassets.com/d0b6e212f5531e99b4deb14274afa748ddb99ff75bc5d1d8e28d1034ffa2e62d/poliastro/poliastro/pull/1184 --not sure where that hash comes from yet) and add .tooltipster class to HTML elements generated by our :github: role.

I'll try to give it a try this week, if time allows me, at leat to have a POC that you polish --now that you are better than myself with JavaScript 😉

astrojuanlu commented 2 years ago

We would need to know the github image URL from that card at build time

Wouldn't if be easier to grab <meta name="twitter:image:src" from the PR URL?

In any case, thanks a lot 🚀

humitos commented 2 years ago

@astrojuanlu

Wouldn't if be easier to grab <meta name="twitter:image:src" from the PR URL?

I'm not sure to follow. I understand that to grab it from there we would need to do a first request to get the HTML of PR's URL and a second request to the URL that it's on that meta name. If what I understood is correct, what I want to try is to reduce it to just one request to the final URL.

astrojuanlu commented 2 years ago

Sorry, this was actually an answer to "not sure where that hash comes from yet". I guess we only need to do 1 request, to grab the image URL from the PR metadata, and then serve that to the user. Or am I missing anything?

humitos commented 2 years ago

Hehe, this is getting confusing... 🙃

I guess we only need to do 1 request, to grab the image URL from the PR metadata, and then serve that to the user.

Well, those are 2 requests to me:

  1. to get the URL from the PR metadata
  2. to get the image file and how it to the user

My question is "isn't there a way to get the URL of the final image without doing a request to GH to get the metadata?"

astrojuanlu commented 2 years ago

The extension needs to do 1 request to get the image URL, then put it somewhere in the resulting HTML. Then the user needs to do 1 request to see the image, but that's not the extension job.

?

My question is "isn't there a way to get the URL of the final image without doing a request to GH to get the metadata?"

No idea, I'll have a look at the API

humitos commented 2 years ago

We can do it as you are describing. However, I see these "problems" (?) with that approach:

What I'd like to have is:

Also, if it's simple enough to generate the "generic" URL from Javascript on the client-side, we could eliminate the first step which would be better.

I hope I'm being clear here.

astrojuanlu commented 2 years ago

Oh, I see. Very good point about stale images with the "static" approach. I have no idea how could we do what you propose though. Open to suggestions.