social-metadata-hardening
它能做什么
这个工具可以帮你确保链接在社交媒体和即时通讯应用中分享时,能显示出漂亮、完整的预览,而不是只有一串光秃秃的链接。它能修复一些常见问题,比如图片缺失、文字错误或预览信息过时。
适用场景
- ✓分享的链接没有显示图片,或者显示了错误的图片时。
- ✓你希望链接预览的效果和你预期的一模一样时。
- ✓网站上线前,想确保所有链接在各个平台上都显示正常时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/social-metadata-hardening/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“让我的网站链接在 Facebook 和 WhatsApp 上显示漂亮的预览。”
每周 5 个新技能,1 分钟读完。
工作原理
这个工具会把重要信息(比如标题、描述和图片)添加到你网站的代码中。同时,它还会确保所用图片的尺寸正确,并且采用社交媒体平台能够识别的格式。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Social Metadata Hardening Skill
Fix social sharing so every important URL unfurls as a rich card across all platforms.
When to Use
- Use when shared links show missing, stale, cropped, or incorrect previews on social and chat platforms.
- Use when auditing Open Graph, Twitter/X card, image URL, alt text, or
metadataBasecoverage in a web app. - Use before launch when every public page needs predictable rich previews across LinkedIn, X, Facebook, WhatsApp, Slack, Discord, and Telegram.
Why Previews Break
| Problem | Root Cause |
|---|---|
| No preview at all | Missing og:title, og:description, or og:image |
| Broken image | Relative URL (must be absolute) |
| Wrong image size | Image not 1200×630px (OG standard) |
| Plain text card | Twitter card type missing or set to summary |
| Stale preview | Platform caching old metadata |
| Metadata missing on crawl | Tags added by client-side JS (crawlers don't run JS) |
The Gold Standard Metadata Block
Every shareable page needs ALL of these in static HTML:
// Next.js App Router — lib/socialMetadata.js
export function buildSocialMetadata({
title,
description,
path, // '/blog/my-post'
image, // '/images/og/my-post.jpg' or full URL
imageAlt,
imageWidth = 1200,
imageHeight = 630,
}) {
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'https://www.yourdomain.com';
// Always produce an absolute URL
const imageUrl = image?.startsWith('http') ? image : `${baseUrl}${image}`;
const pageUrl = `${baseUrl}${path}`;
// Detect MIME type from extension
const ext = imageUrl.split('.').pop().toLowerCase();
const mimeMap = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp' };
const imageType = mimeMap[ext] || 'image/jpeg';
return {
title,
description,
alternates: { canonical: pageUrl },
openGraph: {
title,
description,
url: pageUrl,
type: 'website', // use 'article' for blog posts
images: [{
url: imageUrl,
secureUrl: imageUrl, // explicit HTTPS version
width: imageWidth,
height: imageHeight,
alt: imageAlt || title,
type: imageType,
}],
},
twitter: {
card: 'summary_large_image', // NOT 'summary' — that shows a tiny image
title,
description,
images: [imageUrl],
},
};
}
Applying the Helper
Static page
// app/about/page.js
import { buildSocialMetadata } from '@/lib/socialMetadata';
export const metadata = buildSocialMetadata({
title: 'About Us | My Site',
description: 'Learn about our team and mission.',
path: '/about',
image: '/images/og/about.jpg',
imageAlt: 'The My Site team',
});
Dynamic page (blog post, tool page)
// app/blog/[slug]/page.js
import { buildSocialMetadata } from '@/lib/socialMetadata';
export async function generateMetadata({ params }) {
const post = await getPost(params.slug);
return buildSocialMetadata({
title: `${post.title} | My Blog`,
description: post.excerpt,
path: `/blog/${params.slug}`,
image: post.ogImage || '/images/og/default.jpg',
imageAlt: post.title,
});
}
Homepage (app/layout.js or app/page.js)
export const metadata = {
metadataBase: new URL('https://www.yourdomain.com'), // REQUIRED for absolute URLs
...buildSocialMetadata({
title: 'My Site — Tagline Here',
description: 'Site-wide description.',
path: '/',
image: '/images/og/home.jpg',
}),
};
⚠️ Set
metadataBasewhen using relative metadata URLs. If your helper already outputs absolute canonical/OG URLs, previews can still work without it.
OG Image Checklist
Good OG images:
- 1200 × 630px (2:1 ratio — works on all platforms)
- Under 8MB (Facebook limit)
- Served over HTTPS
- File name has no spaces (use hyphens)
- Format: JPEG or PNG (WebP works on most but not all crawlers)
- Accessible via GET with no authentication
# Verify your OG image is reachable and correct size
curl -sI https://www.yourdomain.com/images/og/home.jpg | grep -i "content-type\|content-length\|status"
Platform-Specific Notes
Facebook / Meta
- Caches aggressively — use the Sharing Debugger to force recrawl
- Minimum image: 200×200px (but use 1200×630 for quality)
- Needs:
og:title,og:description,og:image,og:url
…
常见问题
为什么我的链接预览显示不正常?
这可能有几种原因:缺少关键信息(标题、描述、图片);图片使用了相对路径(需要改为完整的 URL);图片尺寸不对;或者社交平台仍在显示旧的信息(缓存)。
预览图的理想尺寸是多少?
推荐尺寸是宽 1200 像素、高 630 像素。这样图片在各个平台上都能显示得很好。
如果我已经分享过这个链接,怎么更新预览?
在网站上修复问题之后,你可以使用各平台提供的工具(比如 Facebook 的 Debugger 或 Twitter/X 的 Card Validator),请它们重新抓取该链接的最新信息。
详情
作者的原始描述
Fix social sharing previews so URLs render as rich cards on Facebook, LinkedIn, X/Twitter, WhatsApp, Telegram, and more. Covers OG tags, Twitter cards, absolute image URLs, and debugging.
热度
- GitHub 星标
- 48k
- 排名
- #5821
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。