3

我完全承认我是一个Ruby新手,这个问题可能只是出于我对 Ruby 的无知。

话虽这么说,我开始使用nanoc 项目(并且喜欢它)。我想用这个来为我的博客提供动力......但是:对于我的生活,我无法弄清楚如何获取要在主页上显示的文章/帖子列表。我该怎么做呢?

如果可能的话,我想使用 erb/html。

4

2 回答 2

2

这是一些 erb,它创建了一个包含标题、日期和链接的 10 篇最新文章的列表。您还可以使用添加文章内容article.compiled_content我使用 hpricot 仅显示博客中每篇文章的第一段

<% @site.sorted_articles[0, 10].each do |article| %>
<p><strong> 
<%= link_to(article[:title], article.path) %> </strong><br/>
<%= article[:created_at] %> <br/>
<%= tags_for(article) %> <br/></p>
<% end %>
于 2011-02-18T08:17:28.987 回答
1

其中Nanoc3::Helpers::Blogging有一些称为articlesand的方法sorted_articles(请参阅http://nanoc.stoneship.org/docs/api/3.1/Nanoc3/Helpers/Blogging.html)。

您可以“启用”该助手使用

include Nanoc3::Helpers::Blogging

lib/类似的文件中lib/helpers.rb

http://nanoc.stoneship.org/docs/4-basic-concepts/#helpers

于 2011-02-07T09:43:34.347 回答