-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRules
145 lines (130 loc) · 4.54 KB
/
Rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env ruby
# This Rules file is an attempt at a near zero configuration for the common
# use cases when creating a simple site with nanoc. It's meant to have
# better defaults so new users don't have to configure it much if at all.
# For the most part, it copies all files from the content folder to the
# output folder with the same name. It has the following features:
#
# * Certain predefined page extensions such as html, haml, md, markdown and
# textile are routed to "clean" URI's (see below regarding Item identifiers).
# The list of these extensions should be specified in nanoc.yaml:
#
# page_extensions: [ 'haml', 'htm', 'html', 'markdown', 'md', 'textile', 'xhtml' ]
#
# All the files matching one of these page extensions are filtered through erb
# (except haml) then filtered through one of Haml, Markdown and Textile if
# appropriate. Finally, the default layout is applied.
#
# * All other text files with an extension not found in the page extensions list
# and all binary files are routed with the same path and extension on
# output as on input.
#
# * Compass/SASS are much more easily supported just by uncommenting lines
# below and adding a config.rb. This Rules file does not need to know
# where the .scss or .sass files are located which eliminates the need for
# special rules for scss and sass files and keeping paths in sync between
# this file and config.rb. The compass config.rb must still be configured
# with the correct paths.
#
# A few helpful tips about the Rules file:
#
# * The string given to #compile and #route are matching patterns for
# identifiers--not for paths. Therefore, you can’t match on extension.
#
# * The order of rules is important: for each item, only the first matching
# rule is applied.
#
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
# “content/about.html”). To select all children, grandchildren, … of an
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
# Use the compass sass framework for processing scss and sass files.
# To use, uncomment these two lines and ensure you have a config.rb for compass.
require 'compass'
Compass.add_project_configuration('compass.rb')
# From nanoc.yaml, page_extensions
page_extensions = @config[:page_extensions] || %w[ haml html markdown md textile mustache ]
# Preprocess items before they are compiled and frozen
preprocess do
end
# don't filter SASS partials
compile %r{/_.+/$} do
nil
end
# posts layout
compile '/posts/*' do
filter :mustache
filter :colorize_syntax, :default_colorizer => :pygmentsrb
layout 'posts'
end
compile '/assets/styles/*' do
# Filter if a scss or sass file
filter :sass, Compass.sass_engine_options
.merge(:syntax => item[:extension].to_sym) if
%w[scss sass].include?item[:extension]
end
# generic layout
compile '*' do
if item.binary?
# don't filter binary items
else
if page_extensions.include?(item[:extension])
# for page files, filter and apply a layout
filter :mustache
# filter by extension
case item[:extension]
when 'md','markdown' then
filter :kramdown, :auto_ids => false
when 'textile' then
filter :redcloth
when 'haml' then
filter :haml
when 'html' then
filter :erb
end
layout 'main'
filter :colorize_syntax,
:default_colorizer => :pygmentsrb,
:pygmentsrb => { :options => { :startinline => 'TRUE' } }
filter :erb
end
end
end
# don't route SASS partials
route %r{/_.+/$} do
nil
end
# remove the double extensions on fonts
passthrough '/assets/fonts/*'
passthrough '/assets/scripts/*'
# ignore scripts
ignore '/assets/scripts/*'
# blog stuff
route '/posts/*' do
y,m,d,slug = /([0-9]+)\-([0-9]+)\-([0-9]+)\-([^\/]+)/.match(item.identifier).captures
"/#{y}/#{m}/#{slug}/index.html"
end
# generic stuff
route '*' do
if item.binary?
# Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + item[:extension]
else
if page_extensions.include?(item[:extension])
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
else
# Map extensions if necessary
extension = case item[:extension]
# Map scss/sass extensions to css
when 'scss','sass'; 'css'
else item[:extension]
end
# Write item keeping extension
item.identifier.chop + '.' + extension
end
end
end
layout 'main', :erb
layout '*', :mustache
# https://gist.github.com/bburton