Hi Tom,
nanoc does not have an explicit way of merging two items together, but you can still do it in a pretty generic way.
There are multiple approaches to this, but I’ll explain my preferred one. You can do this in three steps:
1. Create an “entry” item in the preprocessing step.
2. Compile foo.md and bar.md using Markdown.
3. Define the rules to let the entry item include the foo and bar items.
The first step would be to create the item in the preprocessor. Items created in the preprocessor act as if they were part of content/ all along. This needs to go in Rules:
preprocess do
items << Nanoc::Item.new(
"<%= render '_merge' %>",
{ :identifiers => [ '/entry/foo/', '/entry/bar/' ] },
"/entry/")
end
The first argument is the content (I’ll come back to this later). The second argument is the metadata: in here I define which items to merge into one. The last argument is the identifier.
The foo and bar items should be compiled using markdown but should not be written, so the Rules looks like this:
compile '/entry/*/' do
filter :kramdown # or bluecloth, rdiscount, …
end
route '/entry/*/' do
nil
end
To let the entry item combine the two items, I‘d suggest creating a partial layout which, when ERB-evaluated, combines the items with identifiers mentioned in the :identifiers attribute. Put this in layouts/_merge.erb:
<%= @item[:identifiers].map { |id| @items[id].compiled_content }.join %>
(This requires nanoc 3.6 because of @items[id].)
The "<%= render '_merge' %>" item content will make sure this layout is invoked. To ensure that happens, the /entry/ item now needs to be ERB-compiled, like this:
compile '/entry/'
filter :erb
end
Also make sure to enable the Rendering helper. Put this in lib/helpers.rb (or whereever you like to place helpers):
include Nanoc::Helpers::rendering
That’s it. I haven’t tested it, so your YMMV, but that is the gist of it!
Denis
On 22 Feb 2013, at 03:39,
t...@atomeye.com wrote:
> I'm somewhat new to Nanoc and am try to figure out how I can combine multiple Markdown files and output it to a single index.html page.
>
> My content dir looks like this:
>
> content/
> entry/
> foo.md
> bar.md
>
> And I'd like foo.md and bar.md to compile first with Markdown but merge together, one after the other, in the output. It's that second part I'm having trouble with.
>
>
> --
> --
> You received this message because you are subscribed to the nanoc discusssion group.
>
> To post to this group, send email to
na...@googlegroups.com
> To unsubscribe from this group, send email to
>
nanoc+un...@googlegroups.com
> For more options, visit this group at
>
http://groups.google.com/group/nanoc?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups "nanoc" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
nanoc+un...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>