-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest-og-tags.js
More file actions
executable file
·71 lines (60 loc) · 2.93 KB
/
test-og-tags.js
File metadata and controls
executable file
·71 lines (60 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
/**
* Test script to verify Open Graph meta tags for recipe pages
*
* Usage:
* 1. Start local dev server: pnpm dev:cloudflare
* 2. In another terminal: node test-og-tags.js <recipe-naddr>
*
* Example:
* node test-og-tags.js naddr1qvzqqqr4gupzq44he2prxpk7qcde4fu6nrw4ktn7aa5erpgya4vpcrpld7fajwquqqwhg6rfwvkkjuedvykhgetnwskz6mn0wskkzttjv43kjur995lx8uqx
*/
const recipeNaddr = process.argv[2] || 'naddr1qvzqqqr4gupzq44he2prxpk7qcde4fu6nrw4ktn7aa5erpgya4vpcrpld7fajwquqqwhg6rfwvkkjuedvykhgetnwskz6mn0wskkzttjv43kjur995lx8uqx';
const baseUrl = process.env.TEST_URL || 'http://localhost:8788';
async function testOGTags() {
const url = `${baseUrl}/recipe/${recipeNaddr}`;
console.log(`\n🧪 Testing OG tags for: ${url}\n`);
try {
const response = await fetch(url, {
headers: {
'User-Agent': 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)'
}
});
if (!response.ok) {
console.error(`❌ HTTP ${response.status}: ${response.statusText}`);
process.exit(1);
}
const html = await response.text();
// Extract meta tags
const ogTitle = html.match(/<meta\s+property=["']og:title["']\s+content=["']([^"']+)["']/i)?.[1];
const ogDescription = html.match(/<meta\s+property=["']og:description["']\s+content=["']([^"']+)["']/i)?.[1];
const ogImage = html.match(/<meta\s+property=["']og:image["']\s+content=["']([^"']+)["']/i)?.[1];
const ogUrl = html.match(/<meta\s+property=["']og:url["']\s+content=["']([^"']+)["']/i)?.[1];
const twitterCard = html.match(/<meta\s+name=["']twitter:card["']\s+content=["']([^"']+)["']/i)?.[1];
console.log('📋 Results:');
console.log('─'.repeat(60));
console.log(`✅ og:title: ${ogTitle || '❌ MISSING'}`);
console.log(`✅ og:description: ${ogDescription ? ogDescription.substring(0, 60) + '...' : '❌ MISSING'}`);
console.log(`✅ og:image: ${ogImage || '❌ MISSING'}`);
console.log(`✅ og:url: ${ogUrl || '❌ MISSING'}`);
console.log(`✅ twitter:card: ${twitterCard || '❌ MISSING'}`);
console.log('─'.repeat(60));
const allPresent = ogTitle && ogDescription && ogImage && ogUrl && twitterCard;
if (allPresent) {
console.log('\n✅ All OG tags are present!');
console.log('\n💡 Test with social media validators:');
console.log(` - Facebook: https://developers.facebook.com/tools/debug/?q=${encodeURIComponent(url)}`);
console.log(` - Twitter: https://cards-dev.twitter.com/validator`);
console.log(` - LinkedIn: https://www.linkedin.com/post-inspector/inspect/${encodeURIComponent(url)}`);
} else {
console.log('\n❌ Some OG tags are missing!');
process.exit(1);
}
} catch (error) {
console.error(`\n❌ Error: ${error.message}`);
console.log('\n💡 Make sure the dev server is running:');
console.log(' pnpm dev:cloudflare');
process.exit(1);
}
}
testOGTags();