diff --git a/History.markdown b/History.markdown index 4252067..ad75a0b 100644 --- a/History.markdown +++ b/History.markdown @@ -7,6 +7,17 @@ * 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) + * 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) + +### Development Fixes + + * Memoize #author_hash in SeoTag::AuthorDrop (#342) + ## 2.6.1 / 2019-05-17 ### Development Fixes diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 02ed499..4e89e04 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -147,3 +147,17 @@ Which will generate following canonical_url: ```html ``` + +### 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 `seo_paginator_message` key in your `_config.yml`. + +For example: + +```yml +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` +similar to the example above, to incorporate the current page-number and total number of paginated pages in the title. 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/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 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 diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 354c07f..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 @@ -189,8 +197,9 @@ module Jekyll current = @context["paginator"]["page"] total = @context["paginator"]["total_pages"] + paginator_message = site["seo_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/lib/template.html b/lib/template.html index 6422141..d7aea1b 100755 --- a/lib/template.html +++ b/lib/template.html @@ -51,19 +51,23 @@ {% 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 %} - + {% endif %} {% endif %} diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index 172f581..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 } @@ -482,6 +493,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) { { "seo_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