2017-05-21 131 views
0

我只在客戶端使用流星,並一直試圖優化開放圖元標記。我已經使用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> 
+0

您應該使用預渲染lib或服務如已經提到的,一些其他鏈接:[增強spiderable包(https://github.com/VeliovGroup/jazeee-meteor-spiderable),[有ES6支持預渲染](https://ostr.io/info/prerendering) –

回答

1

有2個原因,我可以區分:

  1. 流星有客戶端渲染,這意味着當Facebook打開URL分析OG標籤,它沒有看到任何,所以你需要告訴Facebook機器人,它需要等到你的網頁加載,看看這個流星包:https://atmospherejs.com/meteor/spiderable

  2. 該URL的數據可能會被緩存。

+0

如果你想知道SEO,你可以使用[prerender.io](https://prerender.io/)服務 –