2011-12-14 79 views
0

我有一個節點網絡,其中一些是相互關聯的。我使用Jekyll爲網站提供支持,並希望使用液體標籤來映射這些關係。使用液體標籤鏈接節點

所以,我一直在試圖做到這一點的方式如下。

,這在類別,是關係到 ,這在類別,是關係到,和Ç

當我訪問A的頁面時,我想看到B被列爲相關的。

我已經定義了YAML前面的問題這樣:

title: A 
category: 1 
tags: 
- B.html 

title: B 
category: 2 
tags: 
- A.html 
- C.html 

我液態模板的樣子:

<h2>{{ page.title }} <span class="label important">{{ page.category }}</span></h2> 
<p>Last edited: {{ post.date | date_to_string }}</p> 
<p><em>{{ content }}</em></p> 

<h4>Related</h4> 
<ul> 
{% for post in site.tag.{{ post.url }} %} 
<li><a href="{{ post.url }}">{{ post.title }}</a></li> 
{% endfor %} 
</ul> 

對我來說,這看起來像它應該工作。事實上,事實並非如此。

歡迎提出建議!

此外,相關Github的頁面在這裏: https://raw.github.com/salmonhabitat/salmonhabitat.github.com/master/_posts/2011-12-12-bycatch.md

https://raw.github.com/salmonhabitat/salmonhabitat.github.com/master/_posts/2011-12-12-accidental.md

https://github.com/salmonhabitat/salmonhabitat.github.com/blob/master/_layouts/post.html

我正打算要發生是爲 '意外傷害' 下 '海洋誤捕的' 露面相關節點...

回答

1

第一個問題是帖子基本上對其他用戶是「盲目的」在jekyll的帖子。在jekyll的另一篇文章裏,一個帖子的url(或標題)是不可能的,只有前者的id。你的site.tag.{{ post.url }},雖然有創意,但不會工作:)。

首先,你前面的問題必須是(不幸)更復雜一些,以便能夠實現這一目標:

title: A 
category: 1 
related_posts: 
- title: B 
    href: /2010/01/01/B.html 
- title: C 
    href: /2011/11/11/C.html 

請注意,我已經從「標籤」到「related_posts」更名。我覺得這樣更清楚。

現在你可以試試這個代碼:

<h2>{{ post.title }} <span class="label important">{{ post.category }}</span></h2> 
<p>Last edited: {{ post.date | date_to_string }}</p> 
<p><em>{{ content }}</em></p> 

{% if post.related_posts %} 
    <h4>Related</h4> 
    <ul> 
    {% for related_post in post.related_posts %} 
    <li><a href="{{ related_post.href }}">{{ related_post.title }}</a></li> 
    {% endfor %} 
    </ul> 
{% endif %} 

雖然這是一個有點比你的版本更詳細的,它有一個好處 - 你可以在相關的職位指定自己的標題,而無需被迫使用B鈕或C.

讓我知道如果你有這個問題,祝你好運!

+1

從jekyll文檔中,您可以使用'{%post_url 2010-07-21-name-of-post%}' – bluesmoon 2012-06-06 01:38:51