feat(index): Do not index index.html page

This commit is contained in:
Pixelastic 2016-06-30 16:51:51 +02:00
parent ce3ec4fa30
commit db1f95237e
5 changed files with 22 additions and 3 deletions

View File

@ -57,8 +57,9 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
# Check if the file is in the list of excluded files
def excluded_file?(file)
# Blacklist of pages generated by Jekyll that we know should not be
# indexed
# indexing
excluded = [
/^index\.html$/, # Index page
%r{^page([0-9]*)/index\.html} # Pagination pages
]
# User-provided blacklist

View File

@ -3,7 +3,9 @@ layout: default
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 %}
<a href="{{ site.baseurl }}{{ post.url }}">

View File

@ -3,7 +3,9 @@ layout: default
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 %}
<a href="{{ site.baseurl }}{{ post.url }}">
@ -11,3 +13,4 @@ This default index page is used to display the paginated posts
</a>
{{ post.content }}
{% endfor %}

View File

@ -13,6 +13,7 @@ describe(AlgoliaSearchJekyllPush) do
let(:pagination_page) { site.file_by_name('page2/index.html') }
let(:err_404) { site.file_by_name('404.md') }
let(:err_404_html) { site.file_by_name('404.html') }
let(:homepage) { site.file_by_name('index.html') }
let(:items) do
[{
name: 'foo',
@ -75,6 +76,10 @@ describe(AlgoliaSearchJekyllPush) do
it 'does not index 404 pages (in html)' do
expect(push.indexable?(err_404_html)).to eq false
end
it 'does not index homepage' do
expect(push.indexable?(homepage)).to eq false
end
end
describe 'excluded_files?' do

View File

@ -35,9 +35,17 @@ def get_site(config = {}, options = {})
.jekyll_new(config)
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|
return file if file.path =~ /#{file_name}$/
end
nil
end