Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions .goldens/manifest.tsv

Large diffs are not rendered by default.

Binary file removed public/chere/join-og.jpg
Binary file not shown.
Binary file modified public/og/chere-join.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/og/chere-onboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/og/chere-privacy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/og/chere-support.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/og/chere.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions scripts/audit/page-repeats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# page-repeats.py (S339): usage: python3 page-repeats.py DIST_CLIENT_DIR
# Flags statements a page says twice inside <main> (closer, header, footer,
# menu skipped). It catches word-level repeats; read each page for the same
# idea said in new words, which it cannot see.
# Per page: find repeated or near-repeated statements inside <main>, ignoring
# the sitewide closer, header, footer and menu. Prints pairs to review by eye.
import re, sys, glob, html, difflib, os
from html.parser import HTMLParser
class P(HTMLParser):
def __init__(s): super().__init__(); s.stack=[]; s.blocks=[]; s.cur=None; s.inmain=0; s.skip=0
def handle_starttag(s,t,a):
a=dict(a); c=a.get('class') or ''
if t=='main': s.inmain+=1
if t in('script','style','svg','noscript') or any(k in c for k in ('wc-closer','closer','textbar','menu-panel','wc-foot','sr-only')): s.skip+=1; s.stack.append(('skip',t)); return
s.stack.append(('n',t))
if s.inmain and not s.skip and t in('p','li','h1','h2','h3','h4','dt','dd','figcaption','summary','span','a') and s.cur is None and t not in('span','a'): s.cur=[t,'']
def handle_endtag(s,t):
while s.stack:
k,tt=s.stack.pop()
if k=='skip': s.skip-=1
if tt==t: break
if t=='main': s.inmain-=1
if s.cur and s.cur[0]==t:
txt=re.sub(r'\s+',' ',s.cur[1]).strip()
if len(txt)>25: s.blocks.append((t,txt))
s.cur=None
def handle_data(s,d):
if s.cur is not None and not s.skip: s.cur[1]+=d
root=sys.argv[1]
for f in sorted(glob.glob(root+'/**/*.html',recursive=True)):
rel=os.path.relpath(f,root)
if any(x in rel for x in ('lamp','404','onboard','wall')): continue
p=P(); p.feed(open(f).read()); b=p.blocks; hits=[]
for i in range(len(b)):
for j in range(i+1,len(b)):
r=difflib.SequenceMatcher(None,b[i][1].lower(),b[j][1].lower()).ratio()
# shared long phrase
m=difflib.SequenceMatcher(None,b[i][1].lower(),b[j][1].lower()).find_longest_match(0,len(b[i][1]),0,len(b[j][1]))
if r>0.6 or m.size>=40: hits.append((round(r,2),m.size,b[i][1][:110],b[j][1][:110]))
if hits:
print('##',rel,len(b),'blocks')
for h in hits[:8]: print(' ',h[0],h[1],'|',h[2],'||',h[3])
Binary file added scripts/cards/chere-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 27 additions & 4 deletions scripts/cards/og-cards.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const COPPER = {
'/': 'software.',
'/about': 'Preston Winters.',
'/chere': 'back office.',
'/chere/join': 'your phone.',
'/chere/privacy': 'in plain English.',
'/chere/support': 'a text away.',
'/chere/onboard': 'your business.',
'/process': 'a live site you own.',
'/audit': 'doing right',
'/wall': 'live.',
Expand All @@ -35,6 +39,11 @@ const COPPER = {
'/work/grand-management': '13 business days.',
};
const SKIP = new Set(['/404', '/lamp', '/media']);
// Noindex pages that still get sent by text: the Chere' setup link goes to every new customer.
const KEEP_NOINDEX = new Set(['/chere/onboard']);
// Chere' pages wear the app's own colors and icon on the same plate (S339 round 4b, Preston
// 2026-11-22: the blue card had "better branding", the plate cards read better).
const isChere = (path) => path === '/chere' || path.startsWith('/chere/');

const walk = (dir) => readdirSync(dir).flatMap((f) => {
const p = join(dir, f);
Expand All @@ -49,7 +58,7 @@ for (const file of walk(dist)) {
const path = rel === '/' || rel === '' ? '/' : rel.replace(/\/$/, '');
if (SKIP.has(path) || path.startsWith('/api')) continue;
const html = readFileSync(file, 'utf8');
if (/name="robots" content="[^"]*noindex/.test(html)) continue;
if (/name="robots" content="[^"]*noindex/.test(html) && !KEEP_NOINDEX.has(path)) continue;
const m = html.match(/<h1[^>]*>([\s\S]*?)<\/h1>/);
if (!m) continue;
const h1 = decode(m[1].replace(/<[^>]+>/g, ' ')).replace(/\s+/g, ' ').trim();
Expand All @@ -70,6 +79,8 @@ function split(path, h1) {

const font = (f) => pathToFileURL(join(root, 'public/_fonts', f)).href;
const seal = pathToFileURL(join(root, 'public/wc-seal-512.webp')).href;
// The Chere' app icon (wf-seabreeze AppIcon 1024, cut to 256), kept beside this script.
const chereIcon = pathToFileURL(join(root, 'scripts/cards/chere-icon.png')).href;
const css = `
@font-face{font-family:F;src:url(${font('fraunces-normal-400-700.woff2')});font-weight:400 700}
@font-face{font-family:F;font-style:italic;src:url(${font('fraunces-italic-400-700.woff2')});font-weight:400 700}
Expand All @@ -94,6 +105,14 @@ h1{position:absolute;left:92px;right:92px;top:170px;bottom:150px;display:flex;al
.foot{position:absolute;left:92px;right:92px;bottom:76px;display:flex;align-items:center;justify-content:space-between}
.tag{font-family:F;font-style:italic;font-size:30px;color:#5fe8b5}
.url{font-family:M;font-size:18px;letter-spacing:.16em;color:#aab7ba}
/* Chere': the app icon's own blues, cream type, mint where the site uses copper */
body.ch{color:#f0ece2;background:radial-gradient(60% 70% at 8% 0%,rgba(0,196,167,.20),transparent 70%),radial-gradient(55% 65% at 100% 100%,rgba(1,109,144,.55),transparent 70%),linear-gradient(150deg,#05506a 0%,#06384b 50%,#062c3b 100%)}
.ch .plate{border-color:rgba(240,236,226,.16)}
.ch .rv{background:radial-gradient(circle at 35% 35%,#c9fff3,#4fe0c6 55%,#00977f);box-shadow:0 0 0 4px rgba(79,224,198,.14)}
.ch .mast img{border-radius:18px;box-shadow:0 8px 22px rgba(0,0,0,.35),0 0 0 1px rgba(240,236,226,.16)}
.ch .loc{color:#4fe0c6}
.ch .cu{background:linear-gradient(100deg,#b8f7e9 0%,#6fe9d2 38%,#22cfb2 72%,#00a58c 100%);-webkit-background-clip:text;background-clip:text}
.ch .tag{color:#f0ece2}.ch .url{color:#b9cdd2}
.lamp{display:inline-block;width:10px;height:10px;border-radius:50%;background:#5fe8b5;box-shadow:0 0 0 4px rgba(77,216,168,.18),0 0 14px rgba(95,232,181,.7);margin-right:14px;vertical-align:2px}
`;
const sizeFor = (t) => (t.length <= 28 ? 112 : t.length <= 44 ? 96 : t.length <= 60 ? 80 : 68);
Expand All @@ -105,11 +124,15 @@ const tmp = join(root, 'dist', '.og-card.html');
const done = [];
for (const p of pages) {
const [lead, cu] = split(p.path, p.h1);
const body = `<!doctype html><html><head><meta charset="utf-8"><style>${css}</style></head><body>
const ch = isChere(p.path);
const mast = ch
? `<img src="${chereIcon}" alt=""><div><div class="name">Chere'</div><div class="loc">By Winters Code</div></div>`
: `<img src="${seal}" alt=""><div><div class="name">Winters Code</div><div class="loc">Bandon, Oregon</div></div>`;
const body = `<!doctype html><html><head><meta charset="utf-8"><style>${css}</style></head><body${ch ? ' class="ch"' : ''}>
<div class="plate"></div><span class="rv tl"></span><span class="rv tr"></span><span class="rv bl"></span><span class="rv br"></span>
<div class="mast"><img src="${seal}" alt=""><div><div class="name">Winters Code</div><div class="loc">Bandon, Oregon</div></div></div>
<div class="mast">${mast}</div>
<h1 style="font-size:${sizeFor(p.h1)}px"><span class="t">${esc(lead)}<span class="cu">${esc(cu)}</span></span></h1>
<div class="foot"><div class="tag"><span class="lamp"></span>Help is just a text away.</div><div class="url">WINTERSCODE.COM</div></div>
<div class="foot"><div class="tag"><span class="lamp"></span>${ch ? 'Said like Sherrie.' : 'Help is just a text away.'}</div><div class="url">${ch ? 'WINTERSCODE.COM/CHERE' : 'WINTERSCODE.COM'}</div></div>
</body></html>`;
// A file page, so the fonts and the seal load from disk (setContent runs
// on about:blank, which may not read file: URLs).
Expand Down
77 changes: 77 additions & 0 deletions scripts/cards/og-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python3
"""og-check.py (S339 round 4b): strict share-card check over every built page, then over HTTP.
Usage: python3 scripts/cards/og-check.py dist/client BASE_URL (after a build; BASE_URL is the host the build points its cards at)
Per page: og:title, og:description, og:url == canonical, og:image absolute https,
og:image:width/height match the real file, og:image:type matches the bytes,
og:image:alt, twitter:card summary_large_image, twitter:image == og:image,
title length, description length. Per card over HTTP: 200, content-type image/*,
under 300 KB (WhatsApp drops larger previews), 1200x630, RGB baseline-readable.
Exits 1 when anything is BAD, so a build or deploy gate can stop on it."""
import sys, re, os, io, glob, html, urllib.request
from PIL import Image
dist, base = sys.argv[1].rstrip('/'), sys.argv[2].rstrip('/')

def meta(doc, key, attr='property'):
m = re.search(r'<meta %s="%s" content="([^"]*)"' % (attr, re.escape(key)), doc)
return html.unescape(m.group(1)) if m else None

def get(u):
req = urllib.request.Request(u, headers={'User-Agent': 'facebookexternalhit/1.1'})
with urllib.request.urlopen(req, timeout=20) as r:
return r.status, r.headers.get('content-type', ''), r.read()

bad, cards = 0, {}
# Same skip as og-cards.mjs: /lamp is Preston's own page outside the business site.
SKIP = {'/lamp'}
for f in sorted(glob.glob(dist + '/**/*.html', recursive=True)):
page = f[len(dist):].replace('/index.html', '/').replace('.html', '') or '/'
if page in SKIP:
print(f'skip {page}'); continue
doc = open(f, encoding='utf-8').read()
probs = []
noindex = 'name="robots" content="noindex' in doc
canon = re.search(r'<link rel="canonical" href="([^"]+)"', doc)
canon = canon.group(1) if canon else None
t, d = meta(doc, 'og:title'), meta(doc, 'og:description')
img, alt = meta(doc, 'og:image'), meta(doc, 'og:image:alt')
w, h, typ = meta(doc, 'og:image:width'), meta(doc, 'og:image:height'), meta(doc, 'og:image:type')
tw, twi = meta(doc, 'twitter:card', 'name'), meta(doc, 'twitter:image', 'name')
if not t: probs.append('no og:title')
elif len(t) > 70: probs.append(f'og:title {len(t)} chars')
if not d: probs.append('no og:description')
elif not 50 <= len(d) <= 200: probs.append(f'og:description {len(d)} chars')
if meta(doc, 'og:url') != canon: probs.append('og:url != canonical')
if not img: probs.append('NO og:image')
else:
if not img.startswith('https://'): probs.append('og:image not absolute https')
if not alt: probs.append('no og:image:alt')
if tw != 'summary_large_image': probs.append(f'twitter:card {tw}')
if twi != img: probs.append('twitter:image != og:image')
local = dist + re.sub(r'^https?://[^/]+', '', img).split('?')[0]
if not os.path.exists(local): probs.append('card file missing in build')
else:
data = open(local, 'rb').read()
im = Image.open(io.BytesIO(data))
if (str(im.size[0]), str(im.size[1])) != (w, h): probs.append(f'declared {w}x{h}, real {im.size}')
if im.size != (1200, 630): probs.append(f'size {im.size}')
real = 'image/jpeg' if im.format == 'JPEG' else 'image/' + im.format.lower()
if typ != real: probs.append(f'og:image:type {typ}, bytes {real}')
if im.mode != 'RGB': probs.append(f'mode {im.mode}')
if im.format == 'JPEG' and im.info.get('progression'): probs.append('progressive jpeg')
if len(data) > 300_000: probs.append(f'{len(data)//1024} KB > 300')
cards[img] = page
bad += bool(probs)
print(f"{'BAD ' if probs else 'ok '}{page:42s} {'noindex ' if noindex else ''}{(img or '-').split('/', 3)[-1]:40s} {'; '.join(probs)}")

print('\nHTTP pass on', base)
for img, page in sorted(cards.items()):
path = re.sub(r'^https?://[^/]+', '', img)
try:
st, ct, data = get(base + path)
ok = st == 200 and ct.startswith('image/') and Image.open(io.BytesIO(data)).size == (1200, 630)
if not ok: bad += 1
print(f"{'ok ' if ok else 'BAD '}{path:45s} {st} {ct} {len(data)//1024}KB")
except Exception as e:
bad += 1; print('BAD ', path, e)
print('PAGES', len(glob.glob(dist + '/**/*.html', recursive=True)), 'CARDS', len(cards), 'BAD', bad)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return a failing exit status when card checks fail

When a built page has invalid metadata or a card fails the HTTP checks, the script increments bad but still exits successfully. A metadata-only fixture with no OpenGraph tags produces BAD 1 and exit status 0, so invoking this strict checker from a build or deployment gate will silently allow broken share cards through. Exit with a nonzero status when bad is nonzero.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f4d74e8: exits 1 when anything is BAD. A page with no og tags exits 1; the preview build exits 0.

sys.exit(1 if bad else 0)
73 changes: 0 additions & 73 deletions scripts/sharecards/chere-join.html

This file was deleted.

24 changes: 21 additions & 3 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import KeyboardShortcuts from '../components/layout/KeyboardShortcuts.astro';
import Footer from '../components/layout/Footer.astro';
import TextBar from '../components/layout/TextBar.astro';
import ogCards from '../lib/og-cards.json';
import { createHash } from 'node:crypto';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
// Print stylesheet. loaded with media="print" so the browser parses it
// at lowest priority and NEVER blocks screen paint. Saves ~1KB off the
// render-blocking BaseLayout CSS chunk.
Expand Down Expand Up @@ -73,10 +76,25 @@ const ogImage = ogImageProp === undefined ? ownCard : ogImageProp;
// builds leave it unset and use the site origin. Canonical never moves.
declare const __WC_OG_ORIGIN__: string;
const ogOrigin = (__WC_OG_ORIGIN__ || siteUrl).replace(/\/$/, '');
// A local card's URL carries the first 8 hex of its own sha256 (S339 round 4b). Facebook,
// iMessage, Slack and LinkedIn cache a card by URL, so a redrawn card under the same name
// keeps showing the old one; a new hash is a new URL. The build runs from the repo root.
const cardVersion = (p: string) => {
try {
const file = join(process.cwd(), 'public', p.split('?')[0]);
return createHash('sha256').update(readFileSync(file)).digest('hex').slice(0, 8);
} catch {
return null;
}
};
const ogImageLocal =
ogImage && !ogImage.startsWith('http') && !ogImage.includes('?') && cardVersion(ogImage)
? `${ogImage}?v=${cardVersion(ogImage)}`
: ogImage;
const ogImageUrl =
ogImage === null ? null : ogImage.startsWith('http') ? ogImage : `${ogOrigin}${ogImage}`;
// The type follows the file: a page's own card may be a JPEG (S384, the Chere' join card is a photo
// and a lossless PNG of it runs past 800 KB, over what chat apps fetch for a preview).
ogImageLocal === null ? null : ogImageLocal.startsWith('http') ? ogImageLocal : `${ogOrigin}${ogImageLocal}`;
// The type follows the file. The generated cards are baseline JPEGs: a lossless PNG of a card
// runs past 800 KB, over what chat apps fetch for a preview (S384).
const ogImageType = ogImageUrl && /\.jpe?g(\?|$)/i.test(ogImageUrl) ? 'image/jpeg' : 'image/png';

// Preview-deploy guard. Cloudflare Pages sets CF_PAGES_BRANCH on every build.
Expand Down
1 change: 1 addition & 0 deletions src/lib/og-cards.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"/changelog",
"/chere",
"/chere/join",
"/chere/onboard",
"/chere/privacy",
"/chere/support",
"/contact",
Expand Down
Loading