From 4eeb09a74951b2b2ef734691de61e8b0b14e7b27 Mon Sep 17 00:00:00 2001 From: Josh Habdas Date: Wed, 1 Mar 2017 17:22:10 +0800 Subject: [PATCH 1/3] Update title separator. Closes #121 Replaces the "-" used as a title separator with "|". Ref: https://moz.com/learn/seo/title-tag Also updates docs to specify title optional and fix errata. --- README.md | 2 +- lib/template.html | 20 +++++------------ spec/jekyll_seo_tag_spec.rb | 44 ++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 58b17fa..8f71d58 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A Jekyll plugin to add metadata tags for search engines and social networks to b Jekyll SEO Tag adds the following meta tags to your site: -* Pages title (with site title appended when available) +* Page title, with site title or description appended * Page description * Canonical URL * Next and previous URLs on paginated pages diff --git a/lib/template.html b/lib/template.html index 3885dd9..e320aba 100755 --- a/lib/template.html +++ b/lib/template.html @@ -5,21 +5,13 @@ {% endif %} {% assign seo_site_title = site.title | default: site.name %} +{% assign seo_page_title = page.title | default: seo_site_title %} +{% assign seo_title = page.title | default: seo_site_title %} -{% if page.title %} - {% assign seo_title = page.title %} - {% assign seo_page_title = page.title %} - - {% if seo_site_title %} - {% assign seo_title = seo_title | append:" - " | append: seo_site_title %} - {% endif %} -{% elsif seo_site_title %} - {% assign seo_title = seo_site_title %} - {% assign seo_page_title = seo_site_title %} - - {% if site.description %} - {% assign seo_title = seo_title | append:" - " | append: site.description %} - {% endif %} +{% if page.title and seo_site_title %} + {% assign seo_title = seo_title | append:" | " | append: seo_site_title %} +{% elsif site.description %} + {% assign seo_title = seo_title | append:" | " | append: site.description %} {% endif %} {% if page.seo and page.seo.name %} diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 38c0360..07ee0ea 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -44,13 +44,47 @@ describe Jekyll::SeoTag do expect(output).to match(expected) end + context "with site.name" do + let(:site) { make_site("name" => "Site Name") } + + it "builds the title with a page title and site name" do + expect(output).to match(%r!foo \| Site Name!) + end + end + context "with site.title" do let(:site) { make_site("title" => "bar") } it "builds the title with a page title and site title" do - expect(output).to match(%r!foo - bar!) + expect(output).to match(%r!foo \| bar!) end end + + context "with site.title and site.description" do + let(:site) { make_site("title" => "Site Title", "description" => "Site Description") } + + it "builds the title with a page title and site title" do + expect(output).to match(%r!foo \| Site Title!) + end + + it "does not build the title with the site description" do + expect(output).not_to match(%r!foo \| Site Description!) + end + end + + context "with site.title and site.description" do + let(:site) { make_site("title" => "Site Title", "description" => "Site Description") } + + it "builds the title with a page title and site title" do + expect(output).to match(%r!foo \| Site Title!) + end + + it "does not build the title with the site description" do + expect(output).not_to match(%r!Page Title \| Site Description!) + end + + end + end context "with site.title" do @@ -61,6 +95,14 @@ describe Jekyll::SeoTag do end end + context "with site.title and site.description" do + let(:site) { make_site("title" => "Site Title", "description" => "Site Description") } + + it "builds the title with site title and description" do + expect(output).to match(%r!Site Title \| Site Description!) + end + end + context "with page.description" do let(:page) { make_page("description" => "foo") } From 51db5806c20f3947936a009afca8ae4a6c6230c2 Mon Sep 17 00:00:00 2001 From: Josh Habdas Date: Thu, 2 Mar 2017 20:24:13 +0800 Subject: [PATCH 2/3] Correct template logic, resolve style issues --- lib/template.html | 2 +- spec/jekyll_seo_tag_spec.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/template.html b/lib/template.html index e320aba..0d0aeb8 100755 --- a/lib/template.html +++ b/lib/template.html @@ -10,7 +10,7 @@ {% if page.title and seo_site_title %} {% assign seo_title = seo_title | append:" | " | append: seo_site_title %} -{% elsif site.description %} +{% elsif site.description and seo_site_title %} {% assign seo_title = seo_title | append:" | " | append: site.description %} {% endif %} diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 07ee0ea..1937ab9 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -60,6 +60,14 @@ describe Jekyll::SeoTag do end end + context "with site.description" do + let(:site) { make_site("description" => "Site Description") } + + it "builds the title without the site description" do + expect(output).not_to match(%r!foo \| Site Description!) + end + end + context "with site.title and site.description" do let(:site) { make_site("title" => "Site Title", "description" => "Site Description") } @@ -82,9 +90,7 @@ describe Jekyll::SeoTag do it "does not build the title with the site description" do expect(output).not_to match(%r!Page Title \| Site Description!) end - end - end context "with site.title" do From 2a48f272f68b309b108b4cda27a862e6744c1f20 Mon Sep 17 00:00:00 2001 From: Josh Habdas Date: Thu, 2 Mar 2017 21:29:26 +0800 Subject: [PATCH 3/3] Be more explicity with title assignments --- lib/template.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/template.html b/lib/template.html index 0d0aeb8..eacff7f 100755 --- a/lib/template.html +++ b/lib/template.html @@ -9,9 +9,9 @@ {% assign seo_title = page.title | default: seo_site_title %} {% if page.title and seo_site_title %} - {% assign seo_title = seo_title | append:" | " | append: seo_site_title %} + {% assign seo_title = page.title | append:" | " | append: seo_site_title %} {% elsif site.description and seo_site_title %} - {% assign seo_title = seo_title | append:" | " | append: site.description %} + {% assign seo_title = seo_site_title | append:" | " | append: site.description %} {% endif %} {% if page.seo and page.seo.name %}