Branchwell

PulseCanvas / website / scripts / create-og-review.py

1# Create an OG and SEO review page from actual built metadata.
2from html.parser import HTMLParser
3from html import escape
4from pathlib import Path
5from urllib.parse import urlsplit
6import json
7import sys
8root = Path(sys.argv[1] if len(sys.argv) > 1 else '.vercel/output/static')
9class Head(HTMLParser):
10 def __init__(self):
11 super().__init__(); self.meta = {}; self.title = ''; self.in_title = False; self.canonical = ''; self.images = []
12 def handle_starttag(self, tag, attrs):
13 attrs = dict(attrs)
14 if tag == 'title': self.in_title = True
15 if tag == 'meta': self.meta[attrs.get('property', attrs.get('name', ''))] = attrs.get('content', '')
16 if tag == 'link' and attrs.get('rel') == 'canonical': self.canonical = attrs.get('href', '')
17 if tag == 'img' and attrs.get('src'): self.images.append(attrs['src'])
18 def handle_endtag(self, tag):
19 if tag == 'title': self.in_title = False
20 def handle_data(self, data):
21 if self.in_title: self.title += data
22rows = []
23home = None
24for file in sorted(root.rglob('index.html')):
25 head = Head(); head.feed(file.read_text())
26 route = urlsplit(head.canonical).path
27 if route == '/': home = head
28 rows.append(f'<article class="page"><a class="route" href="{escape(route)}">{escape(route)}</a><h3>{escape(head.title)}</h3><p>{escape(head.meta["description"])}</p><dl><dt>Social title</dt><dd>{escape(head.meta["og:title"])}</dd><dt>Canonical</dt><dd>{escape(head.canonical)}</dd></dl></article>')
29image_url = urlsplit(home.meta['og:image'])
30image_path = image_url.path + ('?' + image_url.query if image_url.query else '')
31html = '''<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="noindex, nofollow"><title>OG & SEO review — PulseCanvas Studio</title><link rel="icon" href="/images/favicon.png"><style>
32:root{color-scheme:dark;font-family:Arial,sans-serif;color:#f7f1ed;background:#17121b}*{box-sizing:border-box}body{margin:0}main{width:min(1060px,100% - 40px);margin:56px auto 80px}a{color:#f2b394}a:focus-visible{outline:3px solid #f2b394;outline-offset:5px}.eyebrow{color:#f2b394;text-transform:uppercase;letter-spacing:.14em;font-size:12px;font-weight:700}h1{font-size:clamp(32px,5vw,54px);line-height:1.08;margin:18px 0 16px;letter-spacing:-.04em}h2{font-size:26px;margin:40px 0 18px}p{line-height:1.7;color:#c8bdcd}.intro{max-width:710px;margin:0 0 28px}.hero{width:100%;height:auto;display:block;border-radius:16px;border:1px solid #3b303f}.meta-line{display:flex;flex-wrap:wrap;gap:14px;justify-content:space-between;font-size:13px;color:#b8adbf;margin:14px 0 30px}.split{display:grid;grid-template-columns:1fr 1fr;gap:22px}.card{background:#201925;border:1px solid #3b303f;border-radius:14px;overflow:hidden}.card img{display:block;width:100%;height:auto}.card-copy{padding:20px}.domain{font-size:12px;color:#c5b3df}.card h3{font-size:20px;line-height:1.3;margin:12px 0}.card p{font-size:14px;margin:0}.search-card{padding:24px;background:#fff;color:#202124;border-radius:14px;align-self:start}.search-card .search-domain{font-size:13px;color:#3c4043}.search-card h3{color:#1a0dab;font-size:22px;line-height:1.3;font-weight:400;margin:16px 0 10px}.search-card p{color:#4d5156;font-size:14px;margin:0}.caption{font-size:12px;color:#b8adbf;margin-top:10px}.checks{padding:22px 26px;border:1px solid #3b303f;border-radius:14px;background:#201925;line-height:1.8}.checks li{color:#d4c8db}.checks li+li{margin-top:8px}.status{color:#bde1c5}.page{border-top:1px solid #3b303f;padding:26px 0}.route{font-size:13px;overflow-wrap:anywhere}.page h3{font-size:22px;margin:12px 0}.page p{margin:0;font-size:15px;max-width:800px}dl{display:grid;grid-template-columns:95px 1fr;gap:8px;font-size:13px;margin-bottom:0}dt{color:#b8adbf}dd{margin:0;overflow-wrap:anywhere}.note{margin:22px 0;color:#c5b3df;font-size:14px}footer{padding-top:30px;border-top:1px solid #3b303f;margin-top:24px;font-size:14px}@media(max-width:680px){main{margin-top:32px;width:calc(100% - 32px)}.split{grid-template-columns:1fr}.checks{padding:20px}dl{grid-template-columns:1fr;gap:4px}dd{margin-bottom:8px}}
33</style></head><body><main><p class="eyebrow">PulseCanvas Studio · Production review</p><h1>Your next first impression.</h1><p class="intro">Review the new social image and metadata for all 11 pages. The new OG image, metadata, and SEO fixes are now deployed to production.</p>'''
34html += f'<a href="{image_path}"><img class="hero" src="{image_path}" width="1200" height="630" alt="{escape(home.meta["og:image:alt"])}"></a><div class="meta-line"><span>1200 × 630 · PNG · Open Graph + X</span><a href="{image_path}">Open full image</a></div><h2>How the homepage could appear</h2><div class="split"><div><article class="card"><img src="{image_path}" width="1200" height="630" alt=""><div class="card-copy"><div class="domain">PULSECANVAS.AI</div><h3>{escape(home.meta["og:title"])}</h3><p>{escape(home.meta["og:description"])}</p></div></article><p class="caption">Illustrative social preview. Platforms may crop images and shorten text.</p></div><div><article class="search-card"><div class="search-domain">PulseCanvas Studio<br>https://pulsecanvas.ai</div><h3>{escape(home.title)}</h3><p>{escape(home.meta["description"])}</p></article><p class="caption">Illustrative search snippet. Search engines choose the final title and description.</p></div></div>'
35html += '''<h2>SEO checks & fixes</h2><div class="checks"><span class="status">All 11 built pages passed technical checks.</span><ul><li>Unique titles and descriptions, one canonical URL per page, crawlable HTML, sitemap coverage, image alt attributes, and internal links.</li><li>Complete Open Graph and X cards; verified image file, dimensions, MIME type, HTTPS URL, and descriptive alt text.</li><li>Added guide headlines, author and relevant app imagery to structured data. Removed brittle effect counts from schema.</li><li>Corrected stale support-page source availability and licensing copy.</li><li>Public production pages, crawl directives, canonical redirects, and genuine 404 behavior checked separately.</li></ul></div><p class="note">The app has no published ratings or reviews, so it currently lacks the rating/review required for Google's software-app rich result. No ratings were invented. Passing technical checks does not guarantee indexing or rankings.</p><h2>Metadata for every page</h2>'''
36html += ''.join(rows)
37html += '''<footer><a href="/">Open the live website</a> · <a href="https://developers.google.com/search/docs/essentials/technical">Google technical requirements</a> · <a href="https://developers.google.com/search/docs/appearance/structured-data/software-app">Software-app rich results</a></footer></main></body></html>'''
38review = Head()
39review.feed(html)
40for source in review.images:
41 asset = root / urlsplit(source).path.lstrip('/')
42 if not asset.is_file():
43 raise FileNotFoundError(f'Review image missing from deployment package: {source}')
44(root / 'og-review.html').write_text(html)
45# Vercel package: mark the page noindex in its routes (Cloudflare does this in _headers).
46config_path = Path('.vercel/output/config.json')
47if config_path.exists():
48 config = json.loads(config_path.read_text())
49 if not any(route.get('src') == '^/og-review\\.html$' for route in config['routes']):
50 config['routes'].insert(0, {'src': '^/og-review\\.html$', 'headers': {'X-Robots-Tag': 'noindex, nofollow'}, 'continue': True})
51 config_path.write_text(json.dumps(config, indent=2)+'\n')
52print('OG and SEO review page created at /og-review.html.')