Jekyll通过文件包含源代码

时间:2014-12-08 04:31:38

标签: web yaml jekyll liquid

我试图在我的jekyll页面中包含c程序的源代码和下载链接。

我搜索过jekyll文档以及stackoverflow,但没有任何工作。 任何人都可以指出正确的方法来做到这一点。

---
source: ["inf.c","find.c","error.c","stu.c","info.c"]
---
{% for c in page.source %}

<tr>
<th>
   <a href="{{c}}">
   {{c}}
    </a>
   </th>
</tr>
<tr>
   <th>
    {% highlight ruby %}
    {% include {{page.permalink}}{{c}} %}
    {% endhighlight %}
    </th>
</tr>

{% endfor %}

1 个答案:

答案 0 :(得分:2)

假设您的代码将/code文件夹中存储的内容隐藏为a.cb.c,依此类推。

您的网页code.html可能就像这样:

{% for c in page.source %}

  {% capture filePath %}/code/{{c}}{% endcapture %}

  <a href="{{filePath}}">{{c}}</a>

  {% highlight c %}
  {% include_relative {{ filePath }} %}
  {% endhighlight %}
{% endfor %}