fix(redirect): Stop failing on redirect pages

Fixes #60.

Using `redirect_from` from the `jekyll-redirect-from` plugin was
throwing errors. Such redirect files are now correctly excluded from
indexing.
This commit is contained in:
Pixelastic 2018-12-07 17:28:56 +01:00
parent 81327d8fad
commit fc7847e842
2 changed files with 15 additions and 1 deletions

View File

@ -90,7 +90,15 @@ module Jekyll
# an HTML meta refresh. We need to exclude those files from indexing.
# https://github.com/jekyll/jekyll-redirect-from
def self.redirect?(file)
file.respond_to?(:name) && file.name == 'redirect.html'
# When using redirect_from, jekyll-redirect-from creates a page named
# `redirect.html`
return true if file.respond_to?(:name) && file.name == 'redirect.html'
# When using redirect_to, it sets the layout to `redirect`
if file.respond_to?(:data) && file.data['layout'] == 'redirect'
return true
end
false
end
# Public: Check if the file has one of the allowed extensions
@ -305,6 +313,7 @@ module Jekyll
selector = Configurator.algolia('nodes_to_index')
first_node = Nokogiri::HTML(html).css(selector).first
return nil if first_node.nil?
first_node.to_s
end

View File

@ -200,6 +200,11 @@ describe(Jekyll::Algolia::FileBrowser) do
let(:file) { double('File', name: 'redirect.html') }
it { should eq true }
end
describe 'file with a redirect layout' do
let(:file) { double('File', data: { 'layout' => 'redirect' }) }
it { should eq true }
end
end
describe '.allowed_extension?' do