Skip to content

Commit bc1aa2c

Browse files
committed
fix: serve playground index.html as 404 fallback for OG tags
Crawlers don't execute JS, so the old 404.html redirect meant they never saw OG meta tags. Now the 404.html is a copy of the playground's built index.html, which contains the OG tags directly.
1 parent b7dba5a commit bc1aa2c

3 files changed

Lines changed: 5 additions & 26 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,10 @@ jobs:
5555
mkdir -p _site/playground
5656
cp -r packages/playground/dist/* _site/playground/
5757
58-
# SPA fallback for playground client-side routes
59-
cat > _site/404.html << 'FOUROHFOUR'
60-
<!DOCTYPE html><html><head><meta charset="utf-8"><script>
61-
var p = window.location.pathname;
62-
if (p.startsWith('/spac/playground')) {
63-
var base = '/spac/playground/';
64-
var route = p.slice(base.length).split('?')[0];
65-
var search = window.location.search;
66-
var sep = search ? search + '&' : '?';
67-
window.location.replace(base + sep + '__route=' + encodeURIComponent(route) + window.location.hash);
68-
}
69-
</script></head><body></body></html>
70-
FOUROHFOUR
58+
# SPA fallback — use the playground's index.html as 404 page.
59+
# This gives crawlers the OG meta tags, and browsers get the SPA
60+
# which reads the example from the URL path client-side.
61+
cp _site/playground/index.html _site/404.html
7162
7263
- uses: actions/upload-pages-artifact@v3
7364
with:

packages/playground/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<meta name="twitter:card" content="summary_large_image" />
1414
<meta name="twitter:title" content="spac playground" />
1515
<meta name="twitter:description" content="Interactive TypeScript → OpenAPI explorer with hover docs and source maps" />
16-
<meta name="twitter:image" content="__OG_IMAGE__" />
16+
<meta name="twitter:image" content="/og/playground.png" />
1717
</head>
1818
<body>
1919
<style>html { color-scheme: dark; }</style>

packages/playground/src/App.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ const EXAMPLE_OPTIONS: Record<string, ExampleOption> = {
1616
}
1717

1818
function getExampleFromPath(): string | null {
19-
// Check for SPA fallback redirect (GitHub Pages 404.html sets __route param)
20-
const params = new URLSearchParams(window.location.search)
21-
const route = params.get('__route')
22-
if (route) {
23-
// Clean up the __route param from the URL
24-
params.delete('__route')
25-
const clean = params.toString()
26-
const newUrl = `${baseUrl}${route}${clean ? '?' + clean : ''}${window.location.hash}`
27-
window.history.replaceState({}, '', newUrl)
28-
return route.split('/')[0] || null
29-
}
30-
3119
// Strip the Vite base URL before parsing
3220
const path = window.location.pathname.replace(baseUrl.replace(/\/$/, ''), '')
3321
const seg = path.split('/').filter(Boolean)[0]

0 commit comments

Comments
 (0)