Nanoc

Install

Install Nanoc

$ gem install nanoc

install dependencies if needed

$ gem install nokogiri kramdown adsf

then compile by

$ nanoc
Loading site data… done
Compiling site…
      update  [0.07s]  xx/xx/index.html
      ...

Site compiled in 0.83s.

and serve the website by

$ nanoc view
[2014-10-29 14:40:29] INFO  WEBrick 1.3.1
[2014-10-29 14:40:29] INFO  ruby 2.1.4 (2014-10-27) [x86_64-darwin14.0]
[2014-10-29 14:40:29] INFO  WEBrick::HTTPServer#start: pid=31613 port=3000

Guard: Watch and Auto-recompile

Install Guard

$ gem install guard
$ gem install guard-nanoc

To run it from bundle, add these to Gemfile:

gem 'guard-nanoc', :git => 'https://github.com/guard/guard-nanoc'
gem 'nanoc', '~> 4.0.0rc2'

then run:

$ bundle install

Create a file called Guardfile

guard 'nanoc' do
  watch('nanoc.yaml') # Change this to config.yaml if you use the old config file name
  watch('Rules')
  watch(%r{^(content|layouts|lib)/.*$})
end

Watch

$ guard

or

$ bundle exec guard

TypeError: no implicit conversion of String into Hash

If you see this error when executing nanoc:

TypeError: no implicit conversion of String into Hash

One reason could be that you are missing a space after title:.

E.g. this will cause the error

---
title:your_title
---

while this is the correct version(with space after :)

---
title: your_title
---

Code Syntax Highlighting

Install CodeRay

$ gem install coderay

Create coderay.css

$ coderay stylesheet > coderay.css

Add filter :colorize_syntax to Rules

#!ruby
compile '*' do
    filter :kramdown
    filter :colorize_syntax
    layout 'default'
end

Also the route

#!ruby
route '/coderay/' do
    '/coderay.css'
end

Finally add #!language to the first line of the code block

Math in Browsers

Add to layout

#!javascript

    ...

and a nav.html for navbar:

#!html

then in default.html add these:



<%= render '/head.*' %>

    <%= render '/nav.*' %>
    ...

or for version<=3.8:



<%= render '/head/' %>

    <%= render '/nav/' %>
    ...

Folder layout:

- project
    - content
    - layouts
        - default.html
        - head.html
        - nav.html
    - lib
    - output

Error: textual filters cannot be used on binary items

Error Message

ERROR - Compilation failed!

Captain! We’ve been hit!

Message:

Nanoc::Int::Errors::CannotUseTextualFilter: The “...” filter cannot be used to filter the “/.../file.json” item (rep “default”), because textual filters cannot be used on binary items.

Cause

By default .json is considered as binary, not textual. All textual file formats must be explicitly declared.

Solution

Modify nanoc.yaml, add .json to text_extensions like this:

text_extensions: [ 'json', 'coffee', 'css', 'erb', 'haml', 'handlebars', 'hb', 'htm', 'html', 'js', 'less', 'markdown', 'md', 'ms', 'mustache', 'php', 'rb', 'rdoc', 'sass', 'scss', 'slim', 'txt', 'xhtml', 'xml' ]