2017-01-27 16 views
1

私はコレクション_authorsにいくつかのエントリがあります。タグのコレクションを使用するにはどうすればいいですか

私は経由して、私の記事に著者タグを割り当てたい:私はBobのようなだけforenameでこれをテストし、それが動作

{% assign author = site.authors | where: "title", page.author | first %} 
{% if author %} 
    <a href="{{ author.url }}">{{ author.title }}</a> 
{% endif %} 

。私がauthors-collectionのタイトルのために姓と姓を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

これはおそらく、著者名の最初の文字列を選択し、page.authorの例とそれをデータファイルのエントリの例で更新するフィルタfirstを使用しているからです。 – 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」のような名前を1つだけ使用すると、そして、「ボブ・バウマイスター」もやっている。 'Bob Baumeister'だけがうまくいきません... – user3473628

+0

' author'はURLのように見えます。 – yaitloutou

+0

これは正しい方法でした。 'page.author'がslugifiedされ、site.authorsの" title "がないので、authors-collectionのように' bob-baumeister'という内容のauthors_slugのような別のタグを追加しました または、タイトル "と同様に? ありがとう! – user3473628

関連する問題