Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
namespace as jekyll-titles-from-headings
- Loading branch information
Showing
12 changed files
with
111 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.gem | ||
Gemfile.lock | ||
spec/examples.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ inherit_gem: | |
AllCops: | ||
Exclude: | ||
- vendor/**/* | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- spec/**/* |
6 changes: 3 additions & 3 deletions
6
titles-from-headings.gemspec → jekyll-titles-from-headings.gemspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "jekyll" | ||
require "jekyll-titles-from-headings/generator" | ||
|
||
module JekyllTitlesFromHeadings | ||
end |
2 changes: 1 addition & 1 deletion
2
lib/titles-from-headings/generator.rb → lib/jekyll-titles-from-headings/generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module JekyllTitlesFromHeadings | ||
VERSION = "0.1.0".freeze | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
RSpec.describe JekyllTitlesFromHeadings::Generator do | ||
let(:site) { fixture_site("site") } | ||
let(:post) { site.posts.first } | ||
let(:page) { page_by_path(site, "page.md") } | ||
let(:page_with_title) { page_by_path(site, "page-with-title.md") } | ||
let(:html_page) { page_by_path(site, "html-page.html") } | ||
let(:page_with_h2) { page_by_path(site, "page-with-h2.md") } | ||
let(:page_with_h3) { page_by_path(site, "page-with-h3.md") } | ||
|
||
subject { described_class.new(site) } | ||
|
||
before(:each) do | ||
site.reset | ||
site.read | ||
end | ||
|
||
it "saves the site" do | ||
expect(subject.site).to eql(site) | ||
end | ||
|
||
context "detecting titles" do | ||
it "knows when a page has a title" do | ||
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 eql(false) | ||
end | ||
end | ||
|
||
context "detecting markdown" do | ||
it "knows when a page is markdown" do | ||
expect(subject.markdown?(page)).to eql(true) | ||
end | ||
|
||
it "knows when a page isn't markdown" do | ||
expect(subject.markdown?(html_page)).to eql(false) | ||
end | ||
|
||
it "knows the markdown converter" do | ||
expect(subject.markdown_converter).to be_a(Jekyll::Converters::Markdown) | ||
end | ||
end | ||
|
||
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 eql(false) | ||
end | ||
|
||
it "knows not to add a title for HTML pages" do | ||
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 eql(true) | ||
end | ||
end | ||
|
||
context "extracting title" do | ||
it "pulls title with an H1" do | ||
expect(subject.title_for(page)).to eql("Just an H1") | ||
end | ||
|
||
it "pulls title with an H2" do | ||
expect(subject.title_for(page_with_h2)).to eql("Just an H2") | ||
end | ||
|
||
it "pulls title with an H3" do | ||
expect(subject.title_for(page_with_h3)).to eql("Just an H3") | ||
end | ||
|
||
it "respects YAML titles" do | ||
expect(subject.title_for(page_with_title)).to eql("Page with title") | ||
end | ||
end | ||
|
||
context "generating" do | ||
before { subject.generate(site) } | ||
|
||
it "sets titles for pages" do | ||
expect(page.data["title"]).to eql("Just an H1") | ||
end | ||
|
||
it "respect a document's auto-generated title" do | ||
expect(post.data["title"]).to eql("Test") | ||
end | ||
|
||
it "respects a document's YAML title" do | ||
expect(page_with_title.data["title"]).to eql("Page with title") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters