Sha256: a84794fb2b635913174e86dd7524ef8bc1baef2db0d396aec6df566aa3cfe6af

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

describe 'GH-1045', site: true, stdio: true do
  before do
    File.write('content/foo.txt', 'foo')
    FileUtils.touch('content/foo.txt', mtime: Time.parse('2015-03-02 10:00:00Z'))

    File.write('content/sitemap.erb', '<%= xml_sitemap(items: items.select { |i| i.path.end_with?(\'/\') }) %>')

    File.write('nanoc.yaml', <<EOS)
base_url: 'http://example.com'
EOS

    File.write('lib/default.rb', <<EOS)
include Nanoc::Helpers::XMLSitemap
EOS

    File.write('Rules', <<EOS)
compile '/*.txt' do
  write item.identifier.without_ext + '/index.html'
end

compile '/sitemap.erb' do
  filter :erb
  write item.identifier.without_ext + '.xml'
end
EOS
  end

  it 'creates the sitemap' do
    Nanoc::CLI.run(%w(compile))

    expect(File.file?('output/sitemap.xml')).to be
    contents = File.read('output/sitemap.xml')
    expect(contents).to match(%r{<loc>http://example.com/foo/</loc>})
    expect(contents).to match(%r{<lastmod>2015-03-02</lastmod>})
  end

  it 'updates the sitemap' do
    Nanoc::CLI.run(%w(compile))
    File.write('content/foo.txt', 'foo 2')
    FileUtils.touch('content/foo.txt', mtime: Time.parse('2016-04-03 10:00:00Z'))
    Nanoc::CLI.run(%w(compile))

    expect(File.file?('output/sitemap.xml')).to be
    contents = File.read('output/sitemap.xml')
    expect(contents).to match(%r{<loc>http://example.com/foo/</loc>})
    expect(contents).to match(%r{<lastmod>2016-04-03</lastmod>})
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
nanoc-4.7.5 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.7.4 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.7.3 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.7.2 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.7.1 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.7.0 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.6.4 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.6.3 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.6.2 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.6.1 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.6.0 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.5.4 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.5.3 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.5.2 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.5.1 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.5.0 spec/nanoc/regressions/gh_1045_spec.rb
nanoc-4.4.7 spec/nanoc/regressions/gh_1045_spec.rb