开发者

Ruby / nanoc: How do I get a list of items to display in a page?

开发者 https://www.devze.com 2023-02-09 13:31 出处:网络
I fully admit I am a Ruby newb, and this question could come simply out of my ignorance for Ruby. That being said, I\'m getting started with the nanoc project (and loving it).I\'d like to power my bl

I fully admit I am a Ruby newb, and this question could come simply out of my ignorance for Ruby.

That being said, I'm getting started with the nanoc project (and loving it). I'd like to power my blog using this ... but: For the life of me, I can't figure out how to get a list of articles / posts to display on 开发者_高级运维the main page. How do I do this?

I'd like to use erb/html if possible.


Here is some erb that creates a list of 10 most recent articles with the title, date and links. You can also add the article content using article.compiled_content. I use hpricot to display only the fist paragraph of each post in my blog

<% @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 %>


In Nanoc3::Helpers::Blogging there are methods called articles and sorted_articles (see http://nanoc.stoneship.org/docs/api/3.1/Nanoc3/Helpers/Blogging.html).

You can "enable" that helper using

include Nanoc3::Helpers::Blogging

in a file in lib/ like lib/helpers.rb.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消