Merge branch 'master' into patch-1

This commit is contained in:
Frank Taillandier 2019-11-29 23:29:59 +01:00 committed by GitHub
commit 7afb0c8ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 93 additions and 20 deletions

View File

@ -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

View File

@ -147,3 +147,17 @@ Which will generate following canonical_url:
```html
<link rel="canonical" href="https://example.com/title-of-your-post" />
```
### 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: "%<current>s / %<total>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.

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -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 %<current>s of %<total>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

View File

@ -51,19 +51,23 @@
<link rel="next" href="{{ paginator.next_page_path | absolute_url }}" />
{% endif %}
{% if site.twitter %}
{% if seo_tag.image %}
<meta name="twitter:card" content="{{ page.twitter.card | default: site.twitter.card | default: "summary_large_image" }}" />
<meta property="twitter:image" content="{{ seo_tag.image.path }}" />
{% else %}
<meta name="twitter:card" content="summary" />
{% endif %}
{% if seo_tag.image %}
<meta name="twitter:card" content="{{ page.twitter.card | default: site.twitter.card | default: "summary_large_image" }}" />
<meta property="twitter:image" content="{{ seo_tag.image.path }}" />
{% else %}
<meta name="twitter:card" content="summary" />
{% endif %}
{% if seo_tag.page_title %}
<meta property="twitter:title" content="{{ seo_tag.page_title }}" />
<meta name="twitter:site" content="@{{ site.twitter.username | replace:"@","" }}" />
{% endif %}
{% if site.twitter %}
<meta name="twitter:site" content="@{{ site.twitter.username | remove:'@' }}" />
{% if seo_tag.author.twitter %}
<meta name="twitter:creator" content="@{{ seo_tag.author.twitter }}" />
<meta name="twitter:creator" content="@{{ seo_tag.author.twitter | remove:'@' }}" />
{% endif %}
{% endif %}

View File

@ -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" => "%<current>s of %<total>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