2011-12-14 82 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