What's the definitive approach to content includes? The previous approach seems to be failing…

47 views
Skip to first unread message

Dave Everitt

unread,
Dec 20, 2019, 10:15:30 AM12/20/19
to nanoc
I maintain a large site that has various Markdown content items (not layout items) that appear in several HTML pages.

My content includes are arranged in subfolders inside an '_inc' folder.

I have the following in 'Rules':

compile '/_inc/*' do
  filter
:kramdown
end

(i've also tried '/_inc/**')

and:

route '/_inc/*' do
 
nil
end

In my Markdown content files I've used both:

<%= @items['/_inc/subfolder/mdFilename/'].compiled_content %>

and also the wildcard: '/_inc/subfolder/mdFilename.*'

But both yield the raw code in the HTML file, with 'smart quotes' around the path - which may be an issue - e.g.:

<%= @items[‘/_inc/subfolder/mdFilename.*/’].compiled_content %>

The Kramdown warning is:

kramdown warning(s) for <Nanoc::CompilationItemRepView item.identifier=/subfolder/mdFilename/ name=default>
 
No link definition for link ID ''/_inc/subfolder/mdFilename.*'' found on line 6

What's the canonical way to use content includes?

Nanoc version: 4.9.3

Dave Everitt

unread,
Dec 21, 2019, 10:33:21 AM12/21/19
to nanoc
Updated Nanoc and Ruby, all running fine, problem persists:

Nanoc 4.11.14 © 20072019 Denis Defreyne.
Running ruby 2.6.5 (2019-10-01) on x86_64-darwin18 with RubyGems 3.0.6.

Denis Defreyne

unread,
Dec 22, 2019, 6:06:36 AM12/22/19
to na...@googlegroups.com
Hey Dave,

That is odd — your code should work.

Can you check whether you have any other rules that come before compile '/_inc/*' that might also match /_inc? (e.g. ignore /**/_*). Only the first matching rule is used, and my guess is that another rule takes precedence.

Denis


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/nanoc/63c0132a-681c-4ec1-abf5-92205b8c8823%40googlegroups.com.


--

Dave Everitt

unread,
Dec 25, 2019, 9:43:46 AM12/25/19
to nanoc
Hi Denis (Happy Christmas!)

it's the first rule. Below is an abbreviated version of my "rules" file - the content includes used to work…

compile '/_inc/*' do
  filter :kramdown
end

layouts = ['ARRAY_OF_SITE_LAYOUTS_HERE'] # '_inc' has no layout

layouts.each  do |dir|
  compile "/#{dir}/*" do
    if @item[:index]
      filter :kramdown
      layout 'default'
    elsif @item[:inc]
      filter :erb
      filter :kramdown
      layout "#{dir}"
    else
      filter :kramdown
      layout "#{dir}"
    end
  end
end

compile '/*' do
  if item.binary?
    # don’t filter binary items
  else
    filter :kramdown
    layout 'default'
  end
end

route '/eamain/' do
  '/eamain.css'
end

route '/_inc/*' do
  nil
end

route '*' do
  if item.binary?
    item.identifier.chop + '.' + item[:extension]
  else
    item.identifier + 'index.html'
  end
end


layout '*', :erb

Dave Everitt

unread,
Dec 25, 2019, 11:24:00 AM12/25/19
to nanoc
Instead of trying to pin down the issue, I used an old and crude debugging technique:

  1. create a new (.md content) file with a different name
  2. copy chunks of the text/code from a working version, starting from the top
  3. test each new chunk (including the '<%= @items …' include) along the way
  4. delete the old broken file when the text/code in the new file is complete and works
  5. rename the new file same as the old broken one

It worked, so there must have been something wrong with the .md file itself (subtly corrupted, odd invisible character…?) but no idea what it was.

So the issue fixed - for me, anyway!

Dave Everitt

unread,
Apr 7, 2020, 1:31:17 PM4/7/20
to nanoc
For completeness:

I'm stupid! I forgot to process the including file when it's "index.md" with `filter :erb` - the include erb was being interpreted as text - includes are fine now.

However, unwanted smart quotes are still appearing elsewhere even though I've set them to 'apos' 'quote' etc. in "nanoc.yaml":

kramdown:
  smart_quotes: ["apos", "apos", "quot", "quot"]


Reply all
Reply to author
Forward
0 new messages