better homepage_or_about detection

This commit is contained in:
Ben Balter 2017-04-11 15:13:24 -05:00
parent ab916c974e
commit cfe7e56cf8
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
2 changed files with 25 additions and 1 deletions

View File

@ -7,6 +7,7 @@ module Jekyll
FORMAT_STRING_METHODS = %i[
markdownify strip_html normalize_whitespace escape_once
].freeze
HOMEPAGE_OR_ABOUT_REGEX = %r!^/(about/)?(index.html?)?$!
def initialize(text, context)
@obj = {}
@ -192,7 +193,7 @@ module Jekyll
end
def homepage_or_about?
["/", "/index.html", "/about/"].include? page["url"]
page["url"] =~ HOMEPAGE_OR_ABOUT_REGEX
end
attr_reader :context

View File

@ -465,4 +465,27 @@ RSpec.describe Jekyll::SeoTag::Drop do
end
end
end
context "homepage_or_about?" do
[
"/", "/index.html", "index.html", "/index.htm",
"/about/", "/about/index.html",
].each do |permalink|
context "when passed '#{permalink}' as a permalink" do
let(:page_meta) { { "permalink" => permalink } }
it "knows it's the home or about page" do
expect(subject.send(:homepage_or_about?)).to be_truthy
end
end
end
context "a random URL" do
let(:page_meta) { { "permalink" => "/about-foo/" } }
it "knows it's not the home or about page" do
expect(subject.send(:homepage_or_about?)).to be_falsy
end
end
end
end