Added a configuration variable: keep_files (default: ['.git']), based on this pull request: https://github.com/mojombo/jekyll/pull/556
This commit is contained in:
parent
fa8400ab61
commit
7c800d3b07
|
@ -145,6 +145,11 @@ opts = OptionParser.new do |opts|
|
||||||
puts "Jekyll " + Jekyll::VERSION
|
puts "Jekyll " + Jekyll::VERSION
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on( "--keep-files filename1,filename2", Array, "Whether to keep files that match the filename (default: .git)") do |names|
|
||||||
|
puts "keep-files option: #{names}"
|
||||||
|
options['keep_files'] = names
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read command line options into `options` hash
|
# Read command line options into `options` hash
|
||||||
|
|
|
@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
s.name = 'jekyll'
|
s.name = 'jekyll'
|
||||||
s.version = '0.11.2'
|
s.version = '0.11.2'
|
||||||
s.date = '2011-12-27'
|
s.date = '2012-08-23'
|
||||||
s.rubyforge_project = 'jekyll'
|
s.rubyforge_project = 'jekyll'
|
||||||
|
|
||||||
s.summary = "A simple, blog aware, static site generator."
|
s.summary = "A simple, blog aware, static site generator."
|
||||||
|
@ -74,10 +74,12 @@ Gem::Specification.new do |s|
|
||||||
lib/jekyll/migrators/csv.rb
|
lib/jekyll/migrators/csv.rb
|
||||||
lib/jekyll/migrators/drupal.rb
|
lib/jekyll/migrators/drupal.rb
|
||||||
lib/jekyll/migrators/enki.rb
|
lib/jekyll/migrators/enki.rb
|
||||||
|
lib/jekyll/migrators/joomla.rb
|
||||||
lib/jekyll/migrators/marley.rb
|
lib/jekyll/migrators/marley.rb
|
||||||
lib/jekyll/migrators/mephisto.rb
|
lib/jekyll/migrators/mephisto.rb
|
||||||
lib/jekyll/migrators/mt.rb
|
lib/jekyll/migrators/mt.rb
|
||||||
lib/jekyll/migrators/posterous.rb
|
lib/jekyll/migrators/posterous.rb
|
||||||
|
lib/jekyll/migrators/rss.rb
|
||||||
lib/jekyll/migrators/textpattern.rb
|
lib/jekyll/migrators/textpattern.rb
|
||||||
lib/jekyll/migrators/tumblr.rb
|
lib/jekyll/migrators/tumblr.rb
|
||||||
lib/jekyll/migrators/typo.rb
|
lib/jekyll/migrators/typo.rb
|
||||||
|
@ -90,6 +92,7 @@ Gem::Specification.new do |s|
|
||||||
lib/jekyll/static_file.rb
|
lib/jekyll/static_file.rb
|
||||||
lib/jekyll/tags/highlight.rb
|
lib/jekyll/tags/highlight.rb
|
||||||
lib/jekyll/tags/include.rb
|
lib/jekyll/tags/include.rb
|
||||||
|
lib/jekyll/tags/post_url.rb
|
||||||
test/helper.rb
|
test/helper.rb
|
||||||
test/source/.htaccess
|
test/source/.htaccess
|
||||||
test/source/_includes/sig.markdown
|
test/source/_includes/sig.markdown
|
||||||
|
@ -141,9 +144,9 @@ Gem::Specification.new do |s|
|
||||||
test/test_post.rb
|
test/test_post.rb
|
||||||
test/test_rdiscount.rb
|
test/test_rdiscount.rb
|
||||||
test/test_redcarpet.rb
|
test/test_redcarpet.rb
|
||||||
|
test/test_redcloth.rb
|
||||||
test/test_site.rb
|
test/test_site.rb
|
||||||
test/test_tags.rb
|
test/test_tags.rb
|
||||||
test/test_redcloth.rb
|
|
||||||
]
|
]
|
||||||
# = MANIFEST =
|
# = MANIFEST =
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ module Jekyll
|
||||||
'source' => Dir.pwd,
|
'source' => Dir.pwd,
|
||||||
'destination' => File.join(Dir.pwd, '_site'),
|
'destination' => File.join(Dir.pwd, '_site'),
|
||||||
'plugins' => File.join(Dir.pwd, '_plugins'),
|
'plugins' => File.join(Dir.pwd, '_plugins'),
|
||||||
|
'keep_files' => ['.git'],
|
||||||
'layouts' => '_layouts',
|
'layouts' => '_layouts',
|
||||||
|
|
||||||
'future' => true,
|
'future' => true,
|
||||||
|
|
|
@ -5,7 +5,8 @@ module Jekyll
|
||||||
class Site
|
class Site
|
||||||
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
||||||
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
|
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
|
||||||
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts
|
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
|
||||||
|
:keep_files
|
||||||
|
|
||||||
attr_accessor :converters, :generators
|
attr_accessor :converters, :generators
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ module Jekyll
|
||||||
self.include = config['include'] || []
|
self.include = config['include'] || []
|
||||||
self.future = config['future']
|
self.future = config['future']
|
||||||
self.limit_posts = config['limit_posts'] || nil
|
self.limit_posts = config['limit_posts'] || nil
|
||||||
|
self.keep_files = config['keep_files'] || []
|
||||||
|
|
||||||
self.reset
|
self.reset
|
||||||
self.setup
|
self.setup
|
||||||
|
@ -217,8 +219,12 @@ module Jekyll
|
||||||
# all files and directories in destination, including hidden ones
|
# all files and directories in destination, including hidden ones
|
||||||
dest_files = Set.new
|
dest_files = Set.new
|
||||||
Dir.glob(File.join(self.dest, "**", "*"), File::FNM_DOTMATCH) do |file|
|
Dir.glob(File.join(self.dest, "**", "*"), File::FNM_DOTMATCH) do |file|
|
||||||
|
if self.keep_files.length > 0
|
||||||
|
dest_files << file unless file =~ /\/\.{1,2}$/ or file =~ keep_file_regex
|
||||||
|
else
|
||||||
dest_files << file unless file =~ /\/\.{1,2}$/
|
dest_files << file unless file =~ /\/\.{1,2}$/
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# files to be written
|
# files to be written
|
||||||
files = Set.new
|
files = Set.new
|
||||||
|
@ -242,6 +248,14 @@ module Jekyll
|
||||||
FileUtils.rm_rf(obsolete_files.to_a)
|
FileUtils.rm_rf(obsolete_files.to_a)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# create a regex from the keep_files array
|
||||||
|
# ['.git','.svn'] => /\/(\.git|\/.svn)/
|
||||||
|
def keep_file_regex
|
||||||
|
or_list = self.keep_files.map.inject("") { |x,y| "#{x}|#{y}" }[1..-1]
|
||||||
|
pattern = "\/(#{or_list.gsub(".", "\.")})"
|
||||||
|
Regexp.new pattern
|
||||||
|
end
|
||||||
|
|
||||||
# Write static files, pages, and posts.
|
# Write static files, pages, and posts.
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
|
|
|
@ -180,6 +180,13 @@ class TestSite < Test::Unit::TestCase
|
||||||
File.open(dest_dir('qux/obsolete.html'), 'w')
|
File.open(dest_dir('qux/obsolete.html'), 'w')
|
||||||
# empty directory
|
# empty directory
|
||||||
FileUtils.mkdir(dest_dir('quux'))
|
FileUtils.mkdir(dest_dir('quux'))
|
||||||
|
FileUtils.mkdir(dest_dir('.git'))
|
||||||
|
FileUtils.mkdir(dest_dir('.svn'))
|
||||||
|
FileUtils.mkdir(dest_dir('.hg'))
|
||||||
|
# single file in repository
|
||||||
|
File.open(dest_dir('.git/HEAD'), 'w')
|
||||||
|
File.open(dest_dir('.svn/HEAD'), 'w')
|
||||||
|
File.open(dest_dir('.hg/HEAD'), 'w')
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
@ -187,6 +194,9 @@ class TestSite < Test::Unit::TestCase
|
||||||
FileUtils.rm_f(dest_dir('obsolete.html'))
|
FileUtils.rm_f(dest_dir('obsolete.html'))
|
||||||
FileUtils.rm_rf(dest_dir('qux'))
|
FileUtils.rm_rf(dest_dir('qux'))
|
||||||
FileUtils.rm_f(dest_dir('quux'))
|
FileUtils.rm_f(dest_dir('quux'))
|
||||||
|
FileUtils.rm_rf(dest_dir('.git'))
|
||||||
|
FileUtils.rm_rf(dest_dir('.svn'))
|
||||||
|
FileUtils.rm_rf(dest_dir('.hg'))
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'remove orphaned files in destination' do
|
should 'remove orphaned files in destination' do
|
||||||
|
@ -195,6 +205,23 @@ class TestSite < Test::Unit::TestCase
|
||||||
assert !File.exist?(dest_dir('obsolete.html'))
|
assert !File.exist?(dest_dir('obsolete.html'))
|
||||||
assert !File.exist?(dest_dir('qux'))
|
assert !File.exist?(dest_dir('qux'))
|
||||||
assert !File.exist?(dest_dir('quux'))
|
assert !File.exist?(dest_dir('quux'))
|
||||||
|
assert File.exist?(dest_dir('.git'))
|
||||||
|
assert File.exist?(dest_dir('.git/HEAD'))
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'remove orphaned files in destination - keep_files .svn' do
|
||||||
|
|
||||||
|
config = Jekyll::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'keep_files' => ['.svn']})
|
||||||
|
@site = Site.new(config)
|
||||||
|
@site.process
|
||||||
|
assert !File.exist?(dest_dir('.htpasswd'))
|
||||||
|
assert !File.exist?(dest_dir('obsolete.html'))
|
||||||
|
assert !File.exist?(dest_dir('qux'))
|
||||||
|
assert !File.exist?(dest_dir('quux'))
|
||||||
|
assert !File.exist?(dest_dir('.git'))
|
||||||
|
assert !File.exist?(dest_dir('.git/HEAD'))
|
||||||
|
assert File.exist?(dest_dir('.svn'))
|
||||||
|
assert File.exist?(dest_dir('.svn/HEAD'))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue