Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Rules - gaack! and help please...

68 views
Skip to first unread message

Tom Cloyd

unread,
Jul 8, 2023, 2:08:41 PM7/8/23
to nanoc
I wish I didn't have to say this, but I have never really figured out much ofthe Rules file, and I don't quite know why. I get help for some problem periodically and trudge on until I hit the next bump, which I've just done. I've tried (experimentally) to get past this bump, but...here I am asking for help.

 My Rules file is brief, so here it is:

compile '/index.html' do
  filter :erb
  layout '/default.*'
  write '/index.html'
end

# gets 404 page and any other with html extent
compile '/*.html' do
  filter :kramdown
  filter :erb
  layout '/default.*'
  write item.identifier.without_ext + '/index.html'
end

# gets homepage
compile '/index.md' do
  filter :kramdown
  layout '/default.*'
  write '/index.html'
end

# gets me "pretty URLs", per https://groups.google.com/forum/#!topic/nanoc/b3sXlleJxcA
compile '/*.md' do
  filter :kramdown
  layout '/default.*'
  write '/' + File.basename(item.identifier.without_ext) + '/index.html' # extent is stripped, then all but the file basename is stripped, leaving just the filename
end

# in the following, the /**/ IS necessary
compile '/**/*' do
  write item.identifier.to_s
end

layout '/**/*', :erb

- - - - -

Questions:

1. What does this do?

# in the following, the /**/ IS necessary
compile '/**/*' do
  write item.identifier.to_s
end

2. In the snippet above, what does "**" do? Why is it needed?

3. For the first time ever, I am assembling a site and NOT putting all files in root. What I'm experiencing is that files in directeries in root are not getting compiled. Example: /computer/applications.md ends up in /output completely uncompiled. What do I need in Rules to fix this?

My directory depth will go beyond root + /*/some-filename.md, if that matters.

4. Links to files on my local computer are not working and I'm mystified. Example:

[Dyson DC-14 user guide]("file:///home/tomc/Dropbox/Library/08501-09000/09000-Dyson-DC-14-User-Guide.pdf")

That produces a file not found message, but that location is where the file IS. I have to be messing up something obvious but I can't see it.

Thanks so much....as always.

Tom

Denis Defreyne

unread,
Jul 22, 2023, 5:41:54 AM7/22/23
to na...@googlegroups.com
Hey Tom,

I’ll answer inline!

1. What does this do?

# in the following, the /**/ IS necessary
compile '/**/*' do
  write item.identifier.to_s
end

2. In the snippet above, what does "**" do? Why is it needed?

compile '/**/*' matches any item that hasn’t been matched by any other rule mentioned earlier. It’s a catch-all. The ** ensures that files in subdirectories are matched as well: with just '/*' you’d only match items at the top level.

Also take a look at the Patterns section of the documentation, if you haven’t already: https://nanoc.app/doc/identifiers-and-patterns/#patterns

3. For the first time ever, I am assembling a site and NOT putting all files in root. What I'm experiencing is that files in directeries in root are not getting compiled. Example: /computer/applications.md ends up in /output completely uncompiled. What do I need in Rules to fix this?

My directory depth will go beyond root + /*/some-filename.md, if that matters.

I suspect this is because the compile '/*.md' rule only matches Markdown (.md) files at the top level, and not in subdirectories. You’ll want something like compile '/**/*.md' instead.

The write rule in that rule probably also needs to be adjusted. I think this would work better, so that files end up in subdirectories of the output directory too:

write item.identifier.without_ext + '/index.html'

4. Links to files on my local computer are not working and I'm mystified. Example:

[Dyson DC-14 user guide]("file:///home/tomc/Dropbox/Library/08501-09000/09000-Dyson-DC-14-User-Guide.pdf")

That produces a file not found message, but that location is where the file IS. I have to be messing up something obvious but I can't see it.

Nanoc assumes that all files that are part of the site are pulled in via data sources. This means that referencing something via file:// won’t quite work. Here is an example of a data source configuration that pulls in all files from ~/Dropbox/Library into items under /dropbox-library/:

data_sources:
  - type: filesystem
  - type: filesystem
    content_dir: "/home/tomc/Dropbox/Library"
    items_root: "/dropbox-library/"
    layouts_dir: nil

You’ll also need a rule that copies all files from the Dropbox Library as-is. Put this somewhere near the top of the Rules file, so that it takes precedence over rules that are specified later:

passthrough '/dropbox-library/**/*'

The passthrough method is a convenience method: see https://nanoc.app/doc/rules/#convenience-methods. Note that this assumes that you want everything in ~/Dropbox/Library to be part of your site; if that’s not the case, I think it might be easier to not follow the data source approach I specified above, but use symlinks from your /content/ directory to your Dropbox.

Now, you’ll be able to refer to these items:

[Dyson DC-14 user guide](/dropbox-library/08501-09000/09000-Dyson-DC-14-User-Guide.pdf)

Hope this helps,

--
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.

Tom Cloyd

unread,
Jul 29, 2023, 1:09:45 PM7/29/23
to nanoc
Thank you, Denis, for that exceptionally helpful response. Sorry to be slow getting back to you - it's been an exceptionally busy week for me!

Tom
Reply all
Reply to author
Forward
0 new messages