2017-01-27 30 views
1

我有一個集合_authors與一些條目。我如何使用標籤集合

我想通過筆者標籤分配給我的帖子:

{% assign author = site.authors | where: "title", page.author | first %} 
{% if author %} 
    <a href="{{ author.url }}">{{ author.title }}</a> 
{% endif %} 
我只喜歡 Bob一個用名字測試這

和它的作品。如果我在我的作者集合中爲標題選擇Bob Baumeister這樣的前綴和姓氏,它不起作用。有誰知道爲什麼發生這種情況?

例Frontmatter後:

--- 
title: Building 
date: 2017-01-11 16:22:51 +0100 
author: Bob Baumeister 
--- 

Content 

例Frontmatter的集合項:

--- 
title: Bob Baumeister 
twitter: bobby 
--- 

Content 

感謝您的幫助。

+0

你能舉個作者入門例子? –

+0

這可能是由於過濾器「first」的用法,即在作者名稱中選擇第一個字符串,使用page.author示例更新問題,並且它是數據文件中的條目 – marcanuy

+0

@ David:是的,我在上面添加了一些例子。 – user3473628

回答

2

嘗試"

author: "Bob Baumeister" 

更新

<!-- Bob Bau => bob-bau --> 
{% assign slug = page.author | slugify %} 

<!-- filter by the slugified title --> 
{% assign author = site.authors | where: "title", slug | first%} 
... 

,但我覺得用一個authors.yml文件,而不是一個集合可以給更多的靈活性:

- name: Bob Baumeister 
    title: bob-baumeister 
    url: /bob-baumeister 

- name: Henri Beyle 
    title: Stendhal 
    url: /stendhal 

- name: Jon Doe 
    title: jon-doe 
    url: https://author.jo 
+0

感謝您的提示。試了我的帖子。但不起作用。如果我只使用一個名字,比如'Bob'it的作品。還有'Bob-Baumeister'works也是。只有'Bob Baumeister'不起作用... – user3473628

+0

它看起來像'作者'像一個網址, – yaitloutou

+0

這是正確的方法。因爲'page.author'是slugified,而來自site.authors的「title」沒有給作者集合添加另一個標籤,例如'authors_slug',其內容爲'bob-baumeister' 或者是否有可能使「標題「呢? 謝謝! – user3473628