我的一些(但不是全部)Gatsby React Helmet 元标签似乎被 facebook 丢失了。这是代码:
<Helmet>
<title>Code Championship | Code is Sport</title>
<meta name="description" content="Code is Sport. Competitive coding competitions for elementary, middle, and high school students." />
<meta name="keywords" content="code, championship, competition, minnesota" />
<meta property="og:url" content="https://www.codechampionship.com" />
<meta property="og:title" content="Code Championship | Code is Sport" />
<meta property="og:description" content="Code is Sport. Competitive coding competitions for elementary, middle, and high school students." />
<meta property="og:type" content="website" />
<meta property="fb:app_id" content="281289809224344" />
<meta property="og:image" content="https://www.codechampionship.com/static/running-with-tagline-b034f5627c117830a13bb19345ebb2b0.png" />
<meta property="og:image:width" content="1080" />
<meta property="og:image:height" content="608" />
<meta property="og:image:alt" content="Running Athlete with Code in Foreground" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@codechampionshp" />
<meta name="twitter:title" content="Code Championship | Code is Sport" />
<meta name="twitter:description" content="Code is Sport. Competitive coding competitions for elementary, middle, and high school students." />
<meta name="twitter:image" content="https://www.codechampionship.com/static/running-with-tagline-b034f5627c117830a13bb19345ebb2b0.png" />
<link rel="icon" href={logo} />
<html lang="en" />
<script id="stripe-js" src="https://js.stripe.com/v3/" async />
</Helmet>
这是 Facebook 所说的它看到的内容:
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="generator" content="Gatsby 2.0.66" />
<meta name="theme-color" content="#ffe83d" />
<meta data-react-helmet="true" name="description" content="Code is Sport. Competitive coding competitions for elementary, middle, and high school students." />
<meta data-react-helmet="true" name="keywords" content="code, championship, competition, minnesota" />
<meta data-react-helmet="true" property="og:title" content="Code Championship | Code is Sport" />
<meta data-react-helmet="true" property="og:description" content="Code is Sport. Competitive coding competitions for elementary, middle, and high school students." />
<meta data-react-helmet="true" property="og:image" content="/static/running-with-tagline-b034f5627c117830a13bb19345ebb2b0.png" />
<meta data-react-helmet="true" property="og:image:width" content="1080" />
<meta data-react-helmet="true" property="og:image:height" content="608" />
<meta data-react-helmet="true" name="twitter:card" content="summary" />
<meta data-react-helmet="true" name="twitter:site" content="@codechampionshp" />
<meta data-react-helmet="true" name="twitter:title" content="Code Championship | Code is Sport" />
<meta data-react-helmet="true" name="twitter:description" content="Code is Sport. Competitive coding competitions for elementary, middle, and high school students." />
<meta data-react-helmet="true" name="twitter:image" content="/static/running-with-tagline-b034f5627c117830a13bb19345ebb2b0.png" />
Facebook 列出的第一个问题是:
提供的 og:image URL,/static/running-with-tagline-b034f5627c117830a13bb19345ebb2b0.png 不是有效的 URL。
我知道这是因为它需要一个完整的 URL,例如 "https://www.codechampionship.com/static/running-with-tagline-b034f5627c117830a13bb19345ebb2b0.png"
,但这就是我我在元标记中提供。还有什么我需要做的吗?此错误不会显示在具有完全不同 url 的 Netlify“预览”站点上。因此,这些图像似乎更适合“预览”网站。
Facebook 列出的第二期是:
缺少以下必需属性:og:url、og:type、fb:app_id
这是有道理的,因为它似乎并没有抓取这些。我的元标记中有什么地方做错了吗?
我知道这与其他问题类似,所以我试图阐明这不同之处并列出具体细节。我正在使用 Netlify 进行部署也可能是相关的。
最佳答案
这最终成为一个缓存问题。我没有对代码做任何更改,睡着了,醒来,它开始工作了。我不确定是 Netlify 还是 Facebook 或其他公司在进行缓存。
有人向我建议我可以在最后使用查询字符串来测试(缓存中断)。如果您遇到类似的问题,您可以尝试类似的操作:www.example.com?foo=bar
以强制它进行搜索。它在技术上是不同的 url,但查询字符串不应影响页面结果(除非您使用查询字符串来实现功能)。
关于Facebook 无法识别 Netlify 上的一些 Gatsby React Helmet 元标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53991920/