From 39269edc33cbd6975b705290fadbd76cf2c60263 Mon Sep 17 00:00:00 2001 From: Aleksey Spiridonov Date: Sun, 6 Jan 2019 01:16:32 +0400 Subject: [PATCH 01/15] Adding possibility to change pagination message by config file Default message can by overriten by "paginator_message" parameter in _config.yml --- docs/advanced-usage.md | 9 +++++++++ jekyll-seo-tag.gemspec | 2 +- lib/jekyll-seo-tag/drop.rb | 3 ++- spec/jekyll_seo_tag/drop_spec.rb | 21 +++++++++++++++++++++ spec/spec_helper.rb | 1 + 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index c2fbed5..13449b5 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -138,3 +138,12 @@ Which will generate following canonical_url: ```html ``` + +### Changing title message for paginated page + +You can override default title message for paginated page from `Page %s of %s for ` to custom message by adding parameter to `_config.yml`. +For example: +```yml +paginator_message: "%s / %s |" +``` +For key **paginator_message** please use string template with two variables `current` and `total`. \ No newline at end of file diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index ee00558..90d3fb6 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "jekyll", "~> 3.3" - spec.add_development_dependency "bundler", "~> 1.15" + spec.add_development_dependency "bundler" spec.add_development_dependency "html-proofer", "~> 3.7" spec.add_development_dependency "rspec", "~> 3.5" spec.add_development_dependency "rubocop-jekyll", "~> 0.4" diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 354c07f..2aa10bd 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -189,8 +189,9 @@ module Jekyll current = @context["paginator"]["page"] total = @context["paginator"]["total_pages"] + paginator_message = site["paginator_message"] || "Page %s of %s for " - return "Page #{current} of #{total} for " if current > 1 + format(paginator_message, :current => current, :total => total) if current > 1 end attr_reader :context diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index 172f581..b4678d7 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -482,6 +482,27 @@ RSpec.describe Jekyll::SeoTag::Drop do end end + context "pagination" do + let(:context) do + make_context( + { :page => page, :site => site }, + "paginator" => { "page" => 2, "total_pages" => 10 } + ) + end + + it "render default pagination title" do + expect(subject.send(:page_number)).to eq("Page 2 of 10 for ") + end + + context "render custom pagination title" do + let(:config) { { "paginator_message" => "%s of %s" } } + + it "renders the correct page number" do + expect(subject.send(:page_number)).to eq("2 of 10") + end + end + end + it "exposes the JSON-LD drop" do expect(subject.json_ld).to be_a(Jekyll::SeoTag::JSONLDDrop) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 554ba2f..643a1dc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "jekyll" require "jekyll-seo-tag" require "html-proofer" +require "jekyll-paginate" # Monkey patch Jekyll::Drops::Drop so Rspec's `have_key` works as expected module Jekyll From d585dc34184c783d7f12982e96f36e46156c6e27 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 6 Jan 2019 11:49:21 +0530 Subject: [PATCH 02/15] Undo change outside the scope of this pull request --- jekyll-seo-tag.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index 90d3fb6..ee00558 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "jekyll", "~> 3.3" - spec.add_development_dependency "bundler" + spec.add_development_dependency "bundler", "~> 1.15" spec.add_development_dependency "html-proofer", "~> 3.7" spec.add_development_dependency "rspec", "~> 3.5" spec.add_development_dependency "rubocop-jekyll", "~> 0.4" From 9b1001eb62b106a92bae07e0cc820af67d6514b2 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 6 Jan 2019 11:50:03 +0530 Subject: [PATCH 03/15] undo unnecessary change --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 643a1dc..554ba2f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,6 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "jekyll" require "jekyll-seo-tag" require "html-proofer" -require "jekyll-paginate" # Monkey patch Jekyll::Drops::Drop so Rspec's `have_key` works as expected module Jekyll From 5aab527805be017c0beeec68a05cb16697a739b1 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 6 Jan 2019 12:05:30 +0530 Subject: [PATCH 04/15] Improve documentation for this enhancement --- docs/advanced-usage.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 13449b5..f03020d 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -139,11 +139,16 @@ Which will generate following canonical_url: ``` -### Changing title message for paginated page +### Customizing title modifier for paginated pages + +You can override the default title modifier for paginated pages from `Page %{current} of %{total} for ` to a string of your +choice by setting a `paginator_message` key in your `_config.yml`. -You can override default title message for paginated page from `Page %s of %s for ` to custom message by adding parameter to `_config.yml`. For example: + ```yml -paginator_message: "%s / %s |" +paginator_message: "%s / %s | " ``` -For key **paginator_message** please use string template with two variables `current` and `total`. \ No newline at end of file + +While the value can be any string text, we recommend using a Ruby string-template containing the variables `current` and `total` +similar to the example above, to incorporate the current page-number and total number of paginated pages in the title. From 8557598116111b440d26488a307da66d62a56f08 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Tue, 8 Jan 2019 20:27:50 +0530 Subject: [PATCH 05/15] prefix config key with 'seo_' to avoid conflicts --- docs/advanced-usage.md | 4 ++-- lib/jekyll-seo-tag/drop.rb | 2 +- spec/jekyll_seo_tag/drop_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index f03020d..e93554f 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -142,12 +142,12 @@ Which will generate following canonical_url: ### Customizing title modifier for paginated pages You can override the default title modifier for paginated pages from `Page %{current} of %{total} for ` to a string of your -choice by setting a `paginator_message` key in your `_config.yml`. +choice by setting a `seo_paginator_message` key in your `_config.yml`. For example: ```yml -paginator_message: "%s / %s | " +seo_paginator_message: "%s / %s | " ``` While the value can be any string text, we recommend using a Ruby string-template containing the variables `current` and `total` diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 2aa10bd..5ecbf7b 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -189,7 +189,7 @@ module Jekyll current = @context["paginator"]["page"] total = @context["paginator"]["total_pages"] - paginator_message = site["paginator_message"] || "Page %s of %s for " + paginator_message = site["seo_paginator_message"] || "Page %s of %s for " format(paginator_message, :current => current, :total => total) if current > 1 end diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index b4678d7..3ffbb6b 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -495,7 +495,7 @@ RSpec.describe Jekyll::SeoTag::Drop do end context "render custom pagination title" do - let(:config) { { "paginator_message" => "%s of %s" } } + let(:config) { { "seo_paginator_message" => "%s of %s" } } it "renders the correct page number" do expect(subject.send(:page_number)).to eq("2 of 10") From 242ad4f12708b4756d5f8ea0fa7127b71d22588c Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Tue, 8 Oct 2019 10:42:27 -0400 Subject: [PATCH 06/15] Update history to reflect merge of #324 [ci skip] --- History.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/History.markdown b/History.markdown index 4252067..7adad60 100644 --- a/History.markdown +++ b/History.markdown @@ -7,6 +7,10 @@ * remove Google+ from example snippet (#358) * HTTPS link to https://ogp.me/ (#359) +### Minor Enhancements + + * Adding possibility to change pagination message by config file (#324) + ## 2.6.1 / 2019-05-17 ### Development Fixes From 39442c20c67411c952c9865ee183ecd41ad2e3fa Mon Sep 17 00:00:00 2001 From: Wei-Chung Liao Date: Wed, 30 Oct 2019 12:00:00 -0400 Subject: [PATCH 07/15] Make Twitter card without having Twitter account (#284) Merge pull request 284 --- lib/template.html | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/template.html b/lib/template.html index 6422141..c483cc0 100755 --- a/lib/template.html +++ b/lib/template.html @@ -51,15 +51,19 @@ {% endif %} -{% if site.twitter %} - {% if seo_tag.image %} - - - {% else %} - - {% endif %} +{% if seo_tag.image %} + + +{% else %} + +{% endif %} + +{% if seo_tag.page_title %} +{% endif %} + +{% if site.twitter %} {% if seo_tag.author.twitter %} From a937289d05dedd610d4513ae3eda877a59079c4f Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Wed, 30 Oct 2019 12:00:04 -0400 Subject: [PATCH 08/15] Update history to reflect merge of #284 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index 7adad60..c2ec268 100644 --- a/History.markdown +++ b/History.markdown @@ -10,6 +10,7 @@ ### Minor Enhancements * Adding possibility to change pagination message by config file (#324) + * Make Twitter Summary Card without having Twitter account (#284) ## 2.6.1 / 2019-05-17 From 16a5e3d6b082dbfd102c3e010a88278c291880ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= <3283596+samtrion@users.noreply.github.com> Date: Wed, 13 Nov 2019 21:32:31 +0100 Subject: [PATCH 09/15] Ensure a single leading `@` for twitter usernames (#367) Merge pull request 367 --- lib/template.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/template.html b/lib/template.html index c483cc0..d7aea1b 100755 --- a/lib/template.html +++ b/lib/template.html @@ -64,10 +64,10 @@ {% endif %} {% if site.twitter %} - + {% if seo_tag.author.twitter %} - + {% endif %} {% endif %} From 0943563d0aac6013187c742f38b90fc576075fda Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Wed, 13 Nov 2019 15:32:33 -0500 Subject: [PATCH 10/15] Update history to reflect merge of #367 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index c2ec268..511c801 100644 --- a/History.markdown +++ b/History.markdown @@ -11,6 +11,7 @@ * Adding possibility to change pagination message by config file (#324) * Make Twitter Summary Card without having Twitter account (#284) + * Ensure a single leading `@` for twitter usernames (#367) ## 2.6.1 / 2019-05-17 From ba0810c829e5dc35ac6389f3e949b27e4ea490f9 Mon Sep 17 00:00:00 2001 From: Christian Oliff Date: Fri, 29 Nov 2019 13:15:20 +0900 Subject: [PATCH 11/15] Update jekyll-seo-tag.gemspec update homepage link to: https://github.com/jekyll/jekyll-seo-tag --- jekyll-seo-tag.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index 23ccce1..f2daaaa 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| spec.authors = ["Ben Balter"] spec.email = ["ben.balter@github.com"] spec.summary = "A Jekyll plugin to add metadata tags for search engines and social networks to better index and display your site's content." - spec.homepage = "https://github.com/benbalter/jekyll-seo-tag" + spec.homepage = "https://github.com/jekyll/jekyll-seo-tag" spec.license = "MIT" # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or From 331903536d9e41e10e5e5ecbd3c1bb21a793f263 Mon Sep 17 00:00:00 2001 From: Florian Klampfer Date: Fri, 29 Nov 2019 13:18:14 +0000 Subject: [PATCH 12/15] 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 38ae530..c2890fb 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 5ecbf7b..1a1b849 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -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 diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index 3ffbb6b..d2f30b5 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -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 } From 3b99176f144e06ff03bcabe8494e3014f2a414db Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Fri, 29 Nov 2019 08:18:16 -0500 Subject: [PATCH 13/15] Update history to reflect merge of #356 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index 511c801..0d89ceb 100644 --- a/History.markdown +++ b/History.markdown @@ -12,6 +12,7 @@ * Adding possibility to change pagination message by config file (#324) * Make Twitter Summary Card without having Twitter account (#284) * Ensure a single leading `@` for twitter usernames (#367) + * Prefer site.tagline to site.description for page title (#356) ## 2.6.1 / 2019-05-17 From 895ab6c45b79a8708068e34305ecd7549e9765ab Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 29 Nov 2019 19:36:03 +0530 Subject: [PATCH 14/15] Memoize #author_hash in SeoTag::AuthorDrop (#342) Merge pull request 342 --- lib/jekyll-seo-tag/author_drop.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/jekyll-seo-tag/author_drop.rb b/lib/jekyll-seo-tag/author_drop.rb index a23c850..b55cff0 100644 --- a/lib/jekyll-seo-tag/author_drop.rb +++ b/lib/jekyll-seo-tag/author_drop.rb @@ -74,12 +74,14 @@ module Jekyll # including site-wide metadata if the author is provided as a string, # or an empty hash, if the author cannot be resolved def author_hash - if resolved_author.is_a? Hash - resolved_author - elsif resolved_author.is_a? String - { "name" => resolved_author }.merge(site_data_hash) - else - {} + @author_hash ||= begin + if resolved_author.is_a? Hash + resolved_author + elsif resolved_author.is_a? String + { "name" => resolved_author }.merge(site_data_hash) + else + {} + end end end From 68361c37ed0452b79254477fb190a9dde1cbcda8 Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Fri, 29 Nov 2019 09:06:05 -0500 Subject: [PATCH 15/15] Update history to reflect merge of #342 [ci skip] --- History.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/History.markdown b/History.markdown index 0d89ceb..ad75a0b 100644 --- a/History.markdown +++ b/History.markdown @@ -14,6 +14,10 @@ * Ensure a single leading `@` for twitter usernames (#367) * Prefer site.tagline to site.description for page title (#356) +### Development Fixes + + * Memoize #author_hash in SeoTag::AuthorDrop (#342) + ## 2.6.1 / 2019-05-17 ### Development Fixes