The Wayback Machine - https://web.archive.org/web/20230710032604/https://github.com/github/developer.github.com/commit/ecbcc8e6b66fcadbfe97765cf79294ebdc4970b7
Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Move static resources around, adding new datasource to handle them
  • Loading branch information
tclem committed Aug 6, 2011
1 parent 9c2709c commit ecbcc8e
Show file tree
Hide file tree
Showing 38 changed files with 317 additions and 289 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
*.svg eol=lf
5 changes: 5 additions & 0 deletions Rakefile
@@ -1,5 +1,10 @@
require 'nanoc3/tasks'

desc "Compile the site"
task :compile do
`nanoc compile`
end

desc "Publish to http://developer.github.com"
task :publish => [:clean] do
FileUtils.rm_r('output') if File.exist?('output')
Expand Down
43 changes: 3 additions & 40 deletions Rules
Expand Up @@ -10,24 +10,7 @@
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.

compile '/css/*/' do
# don’t filter or layout
end

compile '/shared/css/*/' do
# don’t filter or layout
end

compile '/images/*' do
end

compile '/shared/images/*' do
end

compile '/shared/js/*' do
end

compile '/assets/*' do
compile '/static/*' do
end

compile '*' do
Expand All @@ -38,28 +21,8 @@ compile '*' do
layout 'default'
end

route '/css/*/' do
item.identifier.chomp('/') << '.css'
end

route '/shared/css/*/' do
item.identifier.chomp('/') << '.css'
end

route '/images/*/' do
item.identifier.chomp('/') << '.png'
end

route '/shared/images/*/' do
item.identifier.chomp('/') << '.png'
end

route '/shared/js/*/' do
item.identifier.chomp('/') << '.js'
end

route '/assets/favicon/' do
'/favicon.ico'
route '/static/*' do
item.identifier[7..-2]
end

route '*' do
Expand Down
4 changes: 4 additions & 0 deletions config.yaml
Expand Up @@ -39,3 +39,7 @@ data_sources:
# The path where layouts should be mounted. The layouts root behaves the
# same as the items root, but applies to layouts rather than items.
layouts_root: /

-
type: static
items_root: /static
55 changes: 55 additions & 0 deletions lib/static.rb
@@ -0,0 +1,55 @@
require 'digest/sha1'

module Nanoc3::DataSources

class Static < Nanoc3::DataSource

identifier :static

def items
# Get prefix
prefix = config[:prefix] || 'static'

# Get all files under prefix dir
filenames = Dir[prefix + '/**/*'].select { |f| File.file?(f) }

# Convert filenames to items
filenames.map do |filename|
attributes = {
:extension => File.extname(filename)[1..-1],
:filename => filename,
}
identifier = filename[(prefix.length+1)..-1] + '/'

mtime = File.mtime(filename)
checksum = checksum_for(filename)

Nanoc3::Item.new(
filename,
attributes,
identifier,
:binary => true, :mtime => mtime, :checksum => checksum
)
end
end

private

# Returns a checksum of the given filenames
# TODO un-duplicate this somewhere
def checksum_for(*filenames)
filenames.flatten.map do |filename|
digest = Digest::SHA1.new
File.open(filename, 'r') do |io|
until io.eof
data = io.readpartial(2**10)
digest.update(data)
end
end
digest.hexdigest
end.join('-')
end

end

end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.

0 comments on commit ecbcc8e

Please sign in to comment.