2014-02-17 65 views
0

我正在爲我的Jekyll網站進行搜索引擎優化,並且遇到了無法設置元信息的問題。在元信息中顯示博客文章標題

... 
<meta name="og:title" content="{{ seo_title }}" /> 
... 
<!-- now in my for post-loop: --> 
{% for post in site.posts %} 
    <li class="post-link"> 
    <a class="post-title" href="{{ post.url }}"> 
     <span class="post-date">{{ post.date | date_to_string }}</span> 
     {{ assign seo_title = post.title }} 
     {{ post.title }} 
    </a> 
    </li> 
{% endfor %} 

我指定sel_title的文章標題,但它沒有出現在我的元信息了!我只是得到<meta name="og:title" content="" />

我也嘗試添加{{ assign seo_title = page.title }}post.html佈局後的內部使用{{ page.seo_title }}{{ post.seo_title }}{{ seo_title }}

現在,很明顯這真的沒有用是不是我想要的,因爲邏輯 - 在此之後for循環,它將它設置爲任何最後的帖子標題,但我甚至不能顯示。理想情況下,我希望它能出現在帖子中。

You can view the page here我希望它出現在哪裏。 我哪裏錯了?我如何使用我的發佈信息來填充我的SEO元信息?

回答

0

看看你的github回購。索引和帖子只使用一種基本佈局。在您的_posts中,當您執行{% include post.html %}時,YAML前臺事宜將被首次處理(並且只會執行一次)。但是,您將它傳遞給默認佈局,並且不能從帖子中傳遞YAML變量。

您可以採用的一種典型模式是拆分默認佈局,並在_includes文件夾中創建部分html文件,即header.html和footer.html。然後,您可以使用它們來創建默認和後期佈局。通過這種方式,您可以將帖子中相關的YAML前端變量傳遞給標題。

相關問題