diff --git a/lib/jekyll-algolia.rb b/lib/jekyll-algolia.rb index f76eaab..d6669c9 100644 --- a/lib/jekyll-algolia.rb +++ b/lib/jekyll-algolia.rb @@ -73,9 +73,13 @@ module Jekyll end # A Jekyll::Site subclass that overrides #write from the parent class to - # create JSON records out of rendered documents and push those records - # to Algolia instead of writing files to disk. + # create JSON records out of rendered documents and push those records to + # Algolia instead of writing files to disk. class Site < Jekyll::Site + # We make the cleanup method a noop, otherwise it will remove excluded + # files from destination + def cleanup; end + def write records = [] files = [] diff --git a/spec/jekyll-algolia_spec.rb b/spec/jekyll-algolia_spec.rb index b80e268..d96155f 100644 --- a/spec/jekyll-algolia_spec.rb +++ b/spec/jekyll-algolia_spec.rb @@ -65,6 +65,20 @@ describe(Jekyll::Algolia) do end end + describe 'overriding Jekyll::Site#cleanup' do + # Given + let(:configuration) { Jekyll.configuration } + let(:jekyll_site) { Jekyll::Site.new(configuration) } + let(:algolia_site) { Jekyll::Algolia::Site.new(configuration) } + let!(:initial_method) { jekyll_site.method(:cleanup).source_location } + let!(:overridden_method) { algolia_site.method(:cleanup).source_location } + + # Then + it 'should change the initial .cleanup method' do + expect(overridden_method).to_not eq initial_method + end + end + describe '.run (mocked build)' do # Prevent the whole process to stop if Algolia config is not available before do