我只在客戶端使用流星,並一直試圖優化開放圖元標記。我已經使用kadira:dochead
和在路由器把下面的代碼:Facebook OG標籤在流星不工作
Router.route('/', function() {
setupOg();
if (isMobile()) {
this.render('landing_mobile');
$('body').css("overflow", "visible");
}
else {
this.render('landing');
$('body').css("overflow", "hidden");
}
});
function setupOg() {
var title = { property: "og:title", content: "Blah" };
var type = { property: "og:type", content: "website" };
var url = { property: "og:url", content: "https://blah.io" };
var image = { property: "og:image", content: "http://i63.tinypic.com/2howf4k.png" };
var siteName = { property: "og:site_name", content: "Blah" };
var description = { property: "blah blah blah." };
DocHead.addMeta(title);
DocHead.addMeta(type);
DocHead.addMeta(url);
DocHead.addMeta(image);
DocHead.addMeta(siteName);
DocHead.addMeta(description);
}
在瀏覽器中,當檢查頭的內容,所述內容是那裏作爲<meta property="og:title" content="Blah" dochead="1">
等對上述各特性。
但是,當我看到Facebook Sharing Debugger時,似乎沒有發現任何這些優化,並且當我嘗試在LinkedIn上分享時,也是如此。爲什麼是這樣?
注意,我main.html
看起來是這樣的:
<head>
<link rel="icon" sizes="16x16 32x32" href="/favicon.ico">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Blah</title>
</head>
您應該使用預渲染lib或服務如已經提到的,一些其他鏈接:[增強spiderable包(https://github.com/VeliovGroup/jazeee-meteor-spiderable),[有ES6支持預渲染](https://ostr.io/info/prerendering) –