Get Github repository preview images

Ema Suriano - Sep 26 - - Dev Community

While I was writing another TIL I needed to put some image about an open source project, in this case, was the popular project of Ollama. Normally what I do is take a screenshot of the website and store it locally in my assets folder, which is what most of the websites also do.

The main issue of this problem is not the fact that the repository size is going to grow (I solved this issue by using Git submodules), it is that the image most probably is going to get out of date. The information about the post is most probably also going to get outdated, but having as well old pictures doesn't help a lot ...

While I was searching for some kind of image that represents the project without information that can get outdated, I found this preview:

Ollama Github preview

It caught my attention because all the information was extremely up-to-date, considering that the last commit was less than 12 hours ago.

Then I decided to inspect the URL and, I found out that, it was coming from the Open Graph of Github assets. The URL itself looks like:

https://opengraph.githubassets.com/16dc0ce438cf338ca03e98e84238f23161d058f1665111075ba68fcd2f0ecf04/ollama/ollama

Enter fullscreen mode Exit fullscreen mode

Then I checked on the Internet what each part means, and I found the following explanation:

https://opengraph.githubassets.com/<random_hash>/<owner>/<repo>

Enter fullscreen mode Exit fullscreen mode

After knowing this I started playing with some of my other repositories and I found that I can always reliably get an up-to-date Github preview of my projects. As an example, I generated the one for this website:

Portfolio Github preview

That will be all for now.

Thanks for reading.

. . . . . . . . . . . . . . . . . .
Terabox Video Player