| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + *.svg eol=lf | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,10 @@ | |||
| 1 | 1 | require 'nanoc3/tasks' | |
| 2 | 2 | ||
| 3 | + desc "Compile the site" | ||
| 4 | + task :compile do | ||
| 5 | + `nanoc compile` | ||
| 6 | + end | ||
| 7 | + | ||
| 3 | 8 | desc "Publish to http://developer.github.com" | |
| 4 | 9 | task :publish => [:clean] do | |
| 5 | 10 | FileUtils.rm_r('output') if File.exist?('output') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,24 +10,7 @@ | |||
| 10 | 10 | # item, use the pattern “/about/*/”; “/about/*” will also select the parent, | |
| 11 | 11 | # because “*” matches zero or more characters. | |
| 12 | 12 | ||
| 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 | ||
| 31 | 14 | end | |
| 32 | 15 | ||
| 33 | 16 | compile '*' do | |
@@ -38,28 +21,8 @@ compile '*' do | |||
| 38 | 21 | layout 'default' | |
| 39 | 22 | end | |
| 40 | 23 | ||
| 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] | ||
| 63 | 26 | end | |
| 64 | 27 | ||
| 65 | 28 | route '*' do | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,3 +39,7 @@ data_sources: | |||
| 39 | 39 | # The path where layouts should be mounted. The layouts root behaves the | |
| 40 | 40 | # same as the items root, but applies to layouts rather than items. | |
| 41 | 41 | layouts_root: / | |
| 42 | + | ||
| 43 | + - | ||
| 44 | + type: static | ||
| 45 | + items_root: /static | ||
| Original file line number | Diff line number | Diff 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 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments