simonw / til

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

Social media cards should not display raw markdown #77

Closed simonw closed 1 year ago

simonw commented 1 year ago

e.g. https://twitter.com/simonw/status/1661869062836846592

CleanShot 2023-05-26 at 08 51 50@2x

HTML is:

<meta name="twitter:description" content="Today I noticed that [Datasette](https://datasette.io/) wasn&#39;t serving  a `Access-Control-Max-Age` header.

This meant that any `OPTIONS` CORS pre-flight requests would be repeated for every request, ">
simonw commented 1 year ago

I think the best way to implement this is at build time, writing out a description field into the database table.

simonw commented 1 year ago

GPT-4 suggestion:

from markdown import markdown
from bs4 import BeautifulSoup

def markdown_to_text(markdown_string):
    html = markdown(markdown_string)
    text = ''.join(BeautifulSoup(html, "html.parser").stripped_strings)
    return text

I have both of those dependencies already.

simonw commented 1 year ago

I use the first paragraph for the summaries on https://til.simonwillison.net/python

I think first paragraph with HTML stripped will work here.

simonw commented 1 year ago

Oops, that triggered a full regeneration of all of the screenshots because the hash of the template file changed.

https://github.com/simonw/til/actions/runs/5092870560/jobs/9154783613

simonw commented 1 year ago

Shipped: https://developers.facebook.com/tools/debug/?q=https%3A%2F%2Ftil.simonwillison.net%2Fhttp%2Ftesting-cors-max-age

image image
simonw commented 1 year ago

https://til.simonwillison.net/tils?sql=select+title%2C+summary+from+til+order+by+created_utc+desc

image