diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index a0116ca..b876180 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -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 diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index 678cfb4..ab0b852 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -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