better homepage_or_about detection
This commit is contained in:
		
							parent
							
								
									ab916c974e
								
							
						
					
					
						commit
						cfe7e56cf8
					
				|  | @ -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 | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue