2016-10-02 39 views
0

所以我',我遇到了一個問題HEXO不返回使用靜態網站發生器hexo.io post.categories或post.tags

在索引頁我想只顯示其職位類別是「秀」 。 我在.md文件中指定了類別,如官方文檔中所示。

--- 
layout: post 
title: "doors" 
categories: 
- show 
date: 2016-10-02 17:54:22 
header-img: "1.jpg" 
author: "default" 
--- 

但似乎類別沒有得到分配,因爲當嘗試這樣

<% site.posts.each(function(post){ %> 
    <div class="post-preview col-md-4 col-xs-12"> 
      <h2 class="post-title"> 
       <%- post.categories || "Untitled" %> 
       <% console.log(post.categories)%> 
      </h2> 
<% }); %> 

<h2>顯示它我得到[object Object]而不是文本show。 當我試圖安慰post.categories我獲得以下控制檯輸出

Query { data: [], length: 0 } 
Query { data: [], length: 0 } 
Query { data: [], length: 0 } 
Query { data: [], length: 0 } 
Query { data: [], length: 0 } 
Query { 
    data: 
    [ Document { 
     name: 'show', 
     _id: 'citstcz9q000f8zi5oij9o5dg', 
     slug: [Getter], 
     path: [Getter], 
     permalink: [Getter], 
     posts: [Getter], 
     length: [Getter] } ], 
    length: 1 } 
Query { data: [], length: 0 } 

誰能告訴我什麼IAM做錯了什麼?

回答

0

Hexo很整潔,我很熱衷於爲我工作。文檔不關心把手(這是我喜歡的),所以我不得不做一些爭論。來到這裏看看是否有修復,我自己想出來。幹得好!

{{#each site.posts.data}} 
<section class="post-block inner-wrap"> 
    <h2 class="post-block__title"><a href="/thoughts/{{this.slug}}">{{this.title}}</a></h2> 
    <h5 class="post-block__meta"> 
    posted in 

    {{#each this.categories.data}} 
     <a href="{{this.permalink}}" class="post-block__category">{{this.name}}</a> 
    {{/each}} 

    on <span class="post-block__date">{{this.date._d}}</span> 
    </h5> 

    <span class="post-block__content">{{{this.content}}}</span> 
</section> 
{{/each}} 

看起來你正在使用ejs,但我希望我的代碼可以幫助你找到一個解決方案!