feat(index): Do not index index.html page
This commit is contained in:
parent
ce3ec4fa30
commit
db1f95237e
@ -57,8 +57,9 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
|
|||||||
# Check if the file is in the list of excluded files
|
# Check if the file is in the list of excluded files
|
||||||
def excluded_file?(file)
|
def excluded_file?(file)
|
||||||
# Blacklist of pages generated by Jekyll that we know should not be
|
# Blacklist of pages generated by Jekyll that we know should not be
|
||||||
# indexed
|
# indexing
|
||||||
excluded = [
|
excluded = [
|
||||||
|
/^index\.html$/, # Index page
|
||||||
%r{^page([0-9]*)/index\.html} # Pagination pages
|
%r{^page([0-9]*)/index\.html} # Pagination pages
|
||||||
]
|
]
|
||||||
# User-provided blacklist
|
# User-provided blacklist
|
||||||
|
|||||||
4
spec/fixtures/jekyll_version_2/index.html
vendored
4
spec/fixtures/jekyll_version_2/index.html
vendored
@ -3,7 +3,9 @@ layout: default
|
|||||||
title: Home
|
title: Home
|
||||||
---
|
---
|
||||||
|
|
||||||
This default index page is used to display the paginated posts
|
This default index page is usually used to display the list of posts, or briefly explain the product.
|
||||||
|
|
||||||
|
I feel that it should not be indexed.
|
||||||
|
|
||||||
{% for post in paginator.posts %}
|
{% for post in paginator.posts %}
|
||||||
<a href="{{ site.baseurl }}{{ post.url }}">
|
<a href="{{ site.baseurl }}{{ post.url }}">
|
||||||
|
|||||||
5
spec/fixtures/jekyll_version_3/index.html
vendored
5
spec/fixtures/jekyll_version_3/index.html
vendored
@ -3,7 +3,9 @@ layout: default
|
|||||||
title: Home
|
title: Home
|
||||||
---
|
---
|
||||||
|
|
||||||
This default index page is used to display the paginated posts
|
This default index page is usually used to display the list of posts, or briefly explain the product.
|
||||||
|
|
||||||
|
I feel that it should not be indexed.
|
||||||
|
|
||||||
{% for post in paginator.posts %}
|
{% for post in paginator.posts %}
|
||||||
<a href="{{ site.baseurl }}{{ post.url }}">
|
<a href="{{ site.baseurl }}{{ post.url }}">
|
||||||
@ -11,3 +13,4 @@ This default index page is used to display the paginated posts
|
|||||||
</a>
|
</a>
|
||||||
{{ post.content }}
|
{{ post.content }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ describe(AlgoliaSearchJekyllPush) do
|
|||||||
let(:pagination_page) { site.file_by_name('page2/index.html') }
|
let(:pagination_page) { site.file_by_name('page2/index.html') }
|
||||||
let(:err_404) { site.file_by_name('404.md') }
|
let(:err_404) { site.file_by_name('404.md') }
|
||||||
let(:err_404_html) { site.file_by_name('404.html') }
|
let(:err_404_html) { site.file_by_name('404.html') }
|
||||||
|
let(:homepage) { site.file_by_name('index.html') }
|
||||||
let(:items) do
|
let(:items) do
|
||||||
[{
|
[{
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
@ -75,6 +76,10 @@ describe(AlgoliaSearchJekyllPush) do
|
|||||||
it 'does not index 404 pages (in html)' do
|
it 'does not index 404 pages (in html)' do
|
||||||
expect(push.indexable?(err_404_html)).to eq false
|
expect(push.indexable?(err_404_html)).to eq false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not index homepage' do
|
||||||
|
expect(push.indexable?(homepage)).to eq false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'excluded_files?' do
|
describe 'excluded_files?' do
|
||||||
|
|||||||
@ -35,9 +35,17 @@ def get_site(config = {}, options = {})
|
|||||||
.jekyll_new(config)
|
.jekyll_new(config)
|
||||||
|
|
||||||
def site.file_by_name(file_name)
|
def site.file_by_name(file_name)
|
||||||
|
# We first check the exact match
|
||||||
|
each_site_file do |file|
|
||||||
|
return file if file.path == file_name
|
||||||
|
end
|
||||||
|
|
||||||
|
# If not found (happens for static files that uses a full absolute path), we
|
||||||
|
# try with a loose regexp
|
||||||
each_site_file do |file|
|
each_site_file do |file|
|
||||||
return file if file.path =~ /#{file_name}$/
|
return file if file.path =~ /#{file_name}$/
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user