simonw / til

Today I Learned
https://til.simonwillison.net
Apache License 2.0
1.02k stars 81 forks source link

Social media cards for new posts aren't visible during the build #23

Closed simonw closed 3 years ago

simonw commented 3 years ago

I just published https://til.simonwillison.net/til/til/cloudrun_using-gcloud-run-services-list.md and then noticed that the card image looks like this: https://til.simonwillison.net/-/media/screenshot/cloudrun_using-gcloud-run-services-list.md

image

That's because the script that fetches the previews ran during the build - so the page hadn't been deployed yet!

simonw commented 3 years ago

I need to be able to render the image before it's been deployed to the site. That's tricky. I may have to move my screenshot rendering into the GitHub Action itself.

simonw commented 3 years ago

Maybe use this: https://github.com/JarvusInnovations/puppeteer-cli

simonw commented 3 years ago

This worked:

npm install -g puppeteer-cli
puppeteer screenshot https://til.simonwillison.net/til/til/cloudrun_using-gcloud-run-services-list.md \
  --viewport 800x400 --full-page=false > img.png

img.png looks like this:

image

simonw commented 3 years ago

It works from disk too - so I can use datasette --get in combination of it to generate a screenshot:

datasette . --get /til/til/pytest_subprocess-server.md > page.html
puppeteer screenshot page.html --viewport 800x400 --full-page=false > img.png

I'll need to do this as a separate script from the original build_database.py.

simonw commented 3 years ago

This works now (I had to solve #25 on the way): https://twitter.com/simonw/status/1301029646033534977

Simon_Willison_on_Twitter___For_Google_Cloud_Run_users__I_wrote_some_notes_on_how_to_use_the__gcloud_run_services_list__command__in_particular_the_--filter_and_--format_options_https___t_co_GQA63OcN2U____Twitter