Skip to content
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Commit ecbcc8e

Browse files
committed
Move static resources around, adding new datasource to handle them
1 parent 9c2709c commit ecbcc8e

38 files changed

+317
-289
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.svg eol=lf

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
require 'nanoc3/tasks'
22

3+
desc "Compile the site"
4+
task :compile do
5+
`nanoc compile`
6+
end
7+
38
desc "Publish to http://developer.github.com"
49
task :publish => [:clean] do
510
FileUtils.rm_r('output') if File.exist?('output')

Rules

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,7 @@
1010
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
1111
# because “*” matches zero or more characters.
1212

13-
compile '/css/*/' do
14-
# don’t filter or layout
15-
end
16-
17-
compile '/shared/css/*/' do
18-
# don’t filter or layout
19-
end
20-
21-
compile '/images/*' do
22-
end
23-
24-
compile '/shared/images/*' do
25-
end
26-
27-
compile '/shared/js/*' do
28-
end
29-
30-
compile '/assets/*' do
13+
compile '/static/*' do
3114
end
3215

3316
compile '*' do
@@ -38,28 +21,8 @@ compile '*' do
3821
layout 'default'
3922
end
4023

41-
route '/css/*/' do
42-
item.identifier.chomp('/') << '.css'
43-
end
44-
45-
route '/shared/css/*/' do
46-
item.identifier.chomp('/') << '.css'
47-
end
48-
49-
route '/images/*/' do
50-
item.identifier.chomp('/') << '.png'
51-
end
52-
53-
route '/shared/images/*/' do
54-
item.identifier.chomp('/') << '.png'
55-
end
56-
57-
route '/shared/js/*/' do
58-
item.identifier.chomp('/') << '.js'
59-
end
60-
61-
route '/assets/favicon/' do
62-
'/favicon.ico'
24+
route '/static/*' do
25+
item.identifier[7..-2]
6326
end
6427

6528
route '*' do

config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ data_sources:
3939
# The path where layouts should be mounted. The layouts root behaves the
4040
# same as the items root, but applies to layouts rather than items.
4141
layouts_root: /
42+
43+
-
44+
type: static
45+
items_root: /static

lib/static.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
require 'digest/sha1'
2+
3+
module Nanoc3::DataSources
4+
5+
class Static < Nanoc3::DataSource
6+
7+
identifier :static
8+
9+
def items
10+
# Get prefix
11+
prefix = config[:prefix] || 'static'
12+
13+
# Get all files under prefix dir
14+
filenames = Dir[prefix + '/**/*'].select { |f| File.file?(f) }
15+
16+
# Convert filenames to items
17+
filenames.map do |filename|
18+
attributes = {
19+
:extension => File.extname(filename)[1..-1],
20+
:filename => filename,
21+
}
22+
identifier = filename[(prefix.length+1)..-1] + '/'
23+
24+
mtime = File.mtime(filename)
25+
checksum = checksum_for(filename)
26+
27+
Nanoc3::Item.new(
28+
filename,
29+
attributes,
30+
identifier,
31+
:binary => true, :mtime => mtime, :checksum => checksum
32+
)
33+
end
34+
end
35+
36+
private
37+
38+
# Returns a checksum of the given filenames
39+
# TODO un-duplicate this somewhere
40+
def checksum_for(*filenames)
41+
filenames.flatten.map do |filename|
42+
digest = Digest::SHA1.new
43+
File.open(filename, 'r') do |io|
44+
until io.eof
45+
data = io.readpartial(2**10)
46+
digest.update(data)
47+
end
48+
end
49+
digest.hexdigest
50+
end.join('-')
51+
end
52+
53+
end
54+
55+
end
File renamed without changes.

0 commit comments

Comments
 (0)