Skip to content

Commit

Permalink
Let default Rules handle index.* files (fixes #1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Feb 29, 2020
1 parent 71f7315 commit 14e8291
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
19 changes: 12 additions & 7 deletions nanoc-cli/lib/nanoc/cli/commands/create-site.rb
Expand Up @@ -35,14 +35,14 @@ def array_to_yaml(array)
DEFAULT_RULES = <<~EOS unless defined? DEFAULT_RULES
#!/usr/bin/env ruby
compile '/index.html' do
layout '/default.*'
write '/index.html'
end
compile '/**/*.html' do
layout '/default.*'
write item.identifier.without_ext + '/index.html'
if item.identifier =~ '**/index.*'
write item.identifier.to_s
else
write item.identifier.without_ext + '/index.html'
end
end
# This is an example rule that matches Markdown (.md) files, and filters them
Expand All @@ -52,7 +52,12 @@ def array_to_yaml(array)
#compile '/**/*.md' do
# filter :kramdown
# layout '/default.*'
# write item.identifier.without_ext + '/index.html'
#
# if item.identifier =~ '**/index.*'
# write item.identifier.to_s
# else
# write item.identifier.without_ext + '/index.html'
# end
#end
compile '/**/*' do
Expand Down
24 changes: 24 additions & 0 deletions nanoc/test/orig_cli/commands/test_create_site.rb
Expand Up @@ -123,4 +123,28 @@ def test_new_site_prunes_by_default
refute File.file?('output/blah.txt')
end
end

def test_default_site_routes_items_properly
Nanoc::CLI.run %w[create_site foo]

FileUtils.cd('foo') do
FileUtils.mkdir_p('content/bar')
File.write('content/index.html', 'Index')
File.write('content/foo.html', 'Foo')
File.write('content/bar/index.html', 'Bar Index')
File.write('content/bar/qux.html', 'Bar Qux')

site = Nanoc::Core::SiteLoader.new.new_from_cwd
Nanoc::Core::Compiler.compile(site)

assert File.file?('output/index.html')
assert File.file?('output/foo/index.html')
assert File.file?('output/bar/index.html')
assert File.file?('output/bar/qux/index.html')
assert_match(/Index/, File.read('output/index.html'))
assert_match(/Foo/, File.read('output/foo/index.html'))
assert_match(/Bar Index/, File.read('output/bar/index.html'))
assert_match(/Bar Qux/, File.read('output/bar/qux/index.html'))
end
end
end

0 comments on commit 14e8291

Please sign in to comment.