{escape(head.title)}
{escape(head.meta["description"])}
- Social title
- {escape(head.meta["og:title"])}
- Address
- {escape(head.meta.get("og:url", ""))}
# Create a link-preview review page from actual built metadata.
from html.parser import HTMLParser
from html import escape
from pathlib import Path
from urllib.parse import urlsplit
import json
import sys
root = Path(sys.argv[1] if len(sys.argv) > 1 else '.vercel/output/static')
class Head(HTMLParser):
def __init__(self):
super().__init__(); self.meta = {}; self.title = ''; self.in_title = False; self.images = []
def handle_starttag(self, tag, attrs):
attrs = dict(attrs)
if tag == 'title': self.in_title = True
if tag == 'meta': self.meta[attrs.get('property', attrs.get('name', ''))] = attrs.get('content', '')
if tag == 'img' and attrs.get('src'): self.images.append(attrs['src'])
def handle_endtag(self, tag):
if tag == 'title': self.in_title = False
def handle_data(self, data):
if self.in_title: self.title += data
rows = []
home = None
for file in sorted(root.rglob('index.html')):
head = Head(); head.feed(file.read_text())
route = urlsplit(head.meta.get('og:url', '')).path
if route == '/': home = head
rows.append(f' {escape(head.meta["description"])}{escape(head.title)}
PulseCanvas Studio · Production review
Review the new social image and metadata for all 11 pages. The social image and metadata are live.
''' html += f'{escape(home.meta["og:description"])}
Illustrative social preview. Platforms may crop images and shorten text.
{escape(home.meta["description"])}
Illustrative search snippet. Search engines choose the final title and description.