Skip to content

Commit

Permalink
Prefer site.tagline to site.description for page title (#356)
Browse files Browse the repository at this point in the history
Merge pull request 356
  • Loading branch information
qwtel authored and jekyllbot committed Nov 29, 2019
1 parent 40ef3ae commit 3319035
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

The SEO tag will respect any of the following if included in your site's `_config.yml` (and simply not include them if they're not defined):

* `title` - Your site's title (e.g., Ben's awesome site, The GitHub Blog, etc.)
* `description` - A short description (e.g., A blog dedicated to reviewing cat gifs)
* `title` - Your site's title (e.g., Ben's awesome site, The GitHub Blog, etc.), used as part of the title tag like 'page.title | title'.
* `tagline` - A short description (e.g., A blog dedicated to reviewing cat gifs), used as part of the title tag of the home page like 'title | tagline'.
* `description` - A longer description used for the description meta tag. Also used as fallback for pages that don't provide their own `description` and as part of the home page title tag if `tagline` is not defined.
* `url` - The full URL to your site. Note: `site.github.url` will be used by default.
* `author` - global author information (see [Advanced usage](advanced-usage.md#author-information))

Expand Down
10 changes: 9 additions & 1 deletion lib/jekyll-seo-tag/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def site_title
@site_title ||= format_string(site["title"] || site["name"])
end

def site_tagline
@site_tagline ||= format_string site["tagline"]
end

def site_description
@site_description ||= format_string site["description"]
end
Expand All @@ -43,14 +47,18 @@ def page_title
@page_title ||= format_string(page["title"]) || site_title
end

def site_tagline_or_description
site_tagline || site_description
end

# Page title with site title or description appended
# rubocop:disable Metrics/CyclomaticComplexity
def title
@title ||= begin
if site_title && page_title != site_title
page_title + TITLE_SEPARATOR + site_title
elsif site_description && site_title
site_title + TITLE_SEPARATOR + site_description
site_title + TITLE_SEPARATOR + site_tagline_or_description
else
page_title || site_title
end
Expand Down
11 changes: 11 additions & 0 deletions spec/jekyll_seo_tag/drop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@
end
end

context "with a site tagline but no page title" do
let(:page) { make_page }
let(:config) do
{ "title" => "site title", "description" => "site description", "tagline" => "site tagline" }
end

it "builds the title" do
expect(subject.title).to eql("site title | site tagline")
end
end

context "with just a page title" do
let(:site) { make_site }

Expand Down

0 comments on commit 3319035

Please sign in to comment.