Prefer site.tagline to site.description for page title (#356)
Merge pull request 356
This commit is contained in:
parent
40ef3ae227
commit
331903536d
|
@ -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))
|
||||
|
||||
|
|
|
@ -34,6 +34,10 @@ module Jekyll
|
|||
@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
|
||||
|
@ -43,6 +47,10 @@ module Jekyll
|
|||
@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
|
||||
|
@ -50,7 +58,7 @@ module Jekyll
|
|||
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
|
||||
|
|
|
@ -84,6 +84,17 @@ RSpec.describe Jekyll::SeoTag::Drop do
|
|||
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 }
|
||||
|
||||
|
|
Loading…
Reference in New Issue