Skip to content

Commit

Permalink
Merge pull request #24 from benbalter/revert-23-no-homepage-title
Browse files Browse the repository at this point in the history
Revert "Don't set title on homepage"
  • Loading branch information
benbalter authored Aug 11, 2017
2 parents caf70a6 + 70be8b0 commit d8b4ce5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
9 changes: 1 addition & 8 deletions lib/jekyll-titles-from-headings/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class Generator < Jekyll::Generator
# (footnotes at the moment).
EXTRA_MARKUP_REGEX = %r!\[\^[^\]]*\]!

# Regex to determine if the given document is the site's homepage
HOMEPAGE_REGEX = %r!^/(index.html?)?$!

safe true
priority :lowest

Expand All @@ -40,7 +37,7 @@ def generate(site)
end

def should_add_title?(document)
markdown?(document) && !title?(document) && !homepage?(document)
markdown?(document) && !title?(document)
end

def title?(document)
Expand Down Expand Up @@ -74,9 +71,5 @@ def strip_markup(string)
def filters
@filters ||= JekyllTitlesFromHeadings::Filters.new(site)
end

def homepage?(document)
document.url =~ HOMEPAGE_REGEX
end
end
end
4 changes: 0 additions & 4 deletions spec/fixtures/site/index.md

This file was deleted.

25 changes: 8 additions & 17 deletions spec/jekyll-titles-from-headings/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
let(:site) { fixture_site("site") }
let(:post) { site.posts.first }
let(:page) { page_by_path(site, "page.md") }
let(:index) { page_by_path(site, "index.md") }
let(:page_with_title) { page_by_path(site, "page-with-title.md") }
let(:page_with_md_title) { page_by_path(site, "page-with-md-title.md") }
let(:html_page) { page_by_path(site, "html-page.html") }
Expand Down Expand Up @@ -31,21 +30,21 @@

context "detecting titles" do
it "knows when a page has a title" do
expect(subject.title?(page_with_title)).to be_truthy
expect(subject.title?(page_with_title)).to eql(true)
end

it "knows when a page doesn't have a title" do
expect(subject.title?(page)).to be_falsy
expect(subject.title?(page)).to eql(false)
end
end

context "detecting markdown" do
it "knows when a page is markdown" do
expect(subject.markdown?(page)).to be_truthy
expect(subject.markdown?(page)).to eql(true)
end

it "knows when a page isn't markdown" do
expect(subject.markdown?(html_page)).to be_falsy
expect(subject.markdown?(html_page)).to eql(false)
end

it "knows the markdown converter" do
Expand All @@ -55,27 +54,19 @@

context "detecting when to add a title" do
it "knows not to add a title for pages with titles" do
expect(subject.should_add_title?(page_with_title)).to be_falsy
expect(subject.should_add_title?(page_with_title)).to eql(false)
end

it "knows not to add a title for HTML pages" do
expect(subject.should_add_title?(html_page)).to be_falsy
expect(subject.should_add_title?(html_page)).to eql(false)
end

it "knows not add a title to non-HTML pages without titles" do
expect(subject.should_add_title?(page)).to be_truthy
expect(subject.should_add_title?(page)).to eql(true)
end

it "knows not add a title to pages with empty titles" do
expect(subject.should_add_title?(page_with_empty_title)).to be_falsy
end

it "knows not to add a title to the homepage" do
expect(subject.should_add_title?(index)).to be_falsy
end

it "knows to add titles normally" do
expect(subject.should_add_title?(page)).to be_truthy
expect(subject.should_add_title?(page_with_empty_title)).to eql(false)
end
end

Expand Down

0 comments on commit d8b4ce5

Please sign in to comment.