3

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.

Dan Esparza
  • 28,047
  • 29
  • 99
  • 127

2 Answers2

2

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 %>
Matti Pastell
  • 9,135
  • 3
  • 37
  • 44
1

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

Koraktor
  • 41,357
  • 10
  • 69
  • 99
  • If there's no file like that in your `lib/` directory. Just created one and paste the line above in that file. Nanoc will require every file in `lib/` so you may add it to one of the others as well or create another file with an arbitrary name. – Koraktor Feb 07 '11 at 14:19
  • 3
    I think @DanEsparza meant an example of using the sorted_articles method after you've included the Blogging helper. – Ed Brannin May 15 '13 at 21:47