simonw/til

Social media cards should not display raw markdown

simonw opened this issue · 6 comments

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, ">

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

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.

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

I think first paragraph with HTML stripped will work here.

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