From 331903536d9e41e10e5e5ecbd3c1bb21a793f263 Mon Sep 17 00:00:00 2001 From: Florian Klampfer Date: Fri, 29 Nov 2019 13:18:14 +0000 Subject: [PATCH] Prefer site.tagline to site.description for page title (#356) Merge pull request 356 --- docs/usage.md | 5 +++-- lib/jekyll-seo-tag/drop.rb | 10 +++++++++- spec/jekyll_seo_tag/drop_spec.rb | 11 +++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 38ae5307..c2890fbf 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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)) diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 5ecbf7bd..1a1b849a 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -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 @@ -43,6 +47,10 @@ 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 @@ -50,7 +58,7 @@ def title 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 diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index 3ffbb6b8..d2f30b51 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -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 }