Merge branch 'master' into bump-dev-dependencies

This commit is contained in:
Ben Balter 2017-04-04 09:44:13 -04:00 committed by GitHub
commit 9183898ad7
8 changed files with 75 additions and 35 deletions

1
.gitignore vendored
View File

@ -7,4 +7,5 @@
/pkg/
/spec/reports/
/tmp/
/bin/
*.gem

View File

@ -16,6 +16,10 @@ Style/Documentation:
Style/FileName:
Enabled: false
Style/IndentHeredoc:
Exclude:
- spec/**/*
AllCops:
Exclude:
- vendor/**/*

16
Gemfile
View File

@ -1,15 +1,15 @@
source 'https://rubygems.org'
require 'json'
require 'open-uri'
source "https://rubygems.org"
require "json"
require "open-uri"
gemspec
group :development, :test do
versions = JSON.parse(open('https://pages.github.com/versions.json').read)
versions.delete('ruby')
versions.delete('jekyll-seo-tag')
versions.delete('github-pages')
versions.delete('jekyll') # Remove this line when GitHub Pages supports 3.3.0
versions = JSON.parse(open("https://pages.github.com/versions.json").read)
versions.delete("ruby")
versions.delete("jekyll-seo-tag")
versions.delete("github-pages")
versions.delete("jekyll") # Remove this line when GitHub Pages supports 3.3.0
versions.each do |dep, version|
gem dep, version

View File

@ -13,8 +13,8 @@ Jekyll SEO Tag adds the following meta tags to your site:
* Canonical URL
* Next and previous URLs on paginated pages
* [JSON-LD Site and post metadata](https://developers.google.com/structured-data/) for richer indexing
* [Open graph](http://ogp.me/) title, description, site title, and URL (for Facebook, LinkedIn, etc.)
* [Twitter summary card](https://dev.twitter.com/cards/overview) metadata
* [Open Graph](http://ogp.me/) title, description, site title, and URL (for Facebook, LinkedIn, etc.)
* [Twitter Summary Card](https://dev.twitter.com/cards/overview) metadata
While you could theoretically add the necessary metadata tags yourself, Jekyll SEO Tag provides a battle-tested template of crowdsourced best-practices.
@ -102,12 +102,15 @@ webmaster_verifications:
yandex: 1234
```
* `lang` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`.
The SEO tag will respect the following YAML front matter if included in a post, page, or document:
* `title` - The title of the post, page, or document
* `description` - A short description of the page's content
* `image` - URL to an image associated with the post, page, or document (e.g., `/assets/page-pic.jpg`)
* `author` - Page-, post-, or document-specific author information (see below)
* `lang` - Page-, post-, or document-specific language information
## Advanced usage
@ -191,17 +194,14 @@ The following options can be set for any particular page. While the default opti
For most users, setting `image: [path-to-image]` on a per-page basis should be enough. If you need more control over how images are represented, the `image` property can also be an object, with the following options:
* `path` - The relative path to the image. Same as `image: [path-to-image]`
* `twitter` - The relative path to a Twitter-specific image.
* `facebook` - The relative path to a Facebook-specific image.
* `height` - The height of the Facebook (`og:image`) image
* `width` - The width of the Facebook (`og:image`) image
* `height` - The height of the Open Graph (`og:image`) image
* `width` - The width of the Open Graph (`og:image`) image
You can use any of the above, optional properties, like so:
```yml
image:
twitter: /img/twitter.png
facebook: /img/facebook.png
path: /img/twitter.png
height: 100
width: 100
```

View File

@ -1,6 +1,6 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task default: :spec
task :default => :spec

View File

@ -44,7 +44,7 @@ module Jekyll
end
def title?
!(@text =~ %r!title=false!i)
@text !~ %r!title=false!i
end
def info

View File

@ -90,13 +90,15 @@
{% endif %}
{% if page.image %}
{% assign seo_page_image = page.image.path | default: page.image.facebook | default: page.image %}
{% assign seo_page_image = page.image.path | default: page.image.facebook | default: page.image.twitter | default: page.image %}
{% unless seo_page_image contains "://" %}
{% assign seo_page_image = seo_page_image | absolute_url %}
{% endunless %}
{% assign seo_page_image = seo_page_image | escape %}
{% endif %}
{% assign seo_page_lang = page.lang | default: site.lang | default: "en_US" %}
{% if seo_tag.title and seo_title %}
<title>{{ seo_title }}</title>
{% endif %}
@ -109,6 +111,8 @@
<meta name="author" content="{{ seo_author_name }}" />
{% endif %}
<meta property="og:locale" content="{{ seo_page_lang | replace:'-','_' }}" />
{% if seo_description %}
<meta name="description" content="{{ seo_description }}" />
<meta property="og:description" content="{{ seo_description }}" />
@ -124,7 +128,7 @@
{% endif %}
{% if seo_page_image %}
<meta property="og:image" content="{{ seo_page_image }}" />
<meta property="og:image" content="{{ seo_page_image }}" />
{% if page.image.height %}
<meta property="og:image:height" content="{{ page.image.height }}" />
{% endif %}
@ -133,10 +137,6 @@
{% endif %}
{% endif %}
{% if page.image.twitter %}
<meta name="twitter:image" content="{{ page.image.twitter | absolute_url }}" />
{% endif %}
{% if page.date %}
<meta property="og:type" content="article" />
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}" />

View File

@ -172,7 +172,7 @@ describe Jekyll::SeoTag do
context "with relative page.image as a string" do
let(:page) { make_page("image" => "/img/foo.png") }
it "outputs the image" do
it "outputs an open graph image" do
expected = '<meta property="og:image" content="http://example.invalid/img/foo.png" />'
expect(output).to include(expected)
end
@ -181,7 +181,7 @@ describe Jekyll::SeoTag do
context "with absolute page.image" do
let(:page) { make_page("image" => "http://cdn.example.invalid/img/foo.png") }
it "outputs the image" do
it "outputs an open graph image" do
expected = '<meta property="og:image" content="http://cdn.example.invalid/img/foo.png" />'
expect(output).to include(expected)
end
@ -191,7 +191,7 @@ describe Jekyll::SeoTag do
context "when given a path" do
let(:page) { make_page("image" => { "path" => "/img/foo.png" }) }
it "outputs the image" do
it "outputs an open graph image" do
expected = %r!<meta property="og:image" content="http://example.invalid/img/foo.png" />!
expect(output).to match(expected)
end
@ -200,7 +200,7 @@ describe Jekyll::SeoTag do
context "when given a facebook image" do
let(:page) { make_page("image" => { "facebook" => "/img/facebook.png" }) }
it "outputs the image" do
it "outputs an open graph image" do
expected = %r!<meta property="og:image" content="http://example.invalid/img/facebook.png" />!
expect(output).to match(expected)
end
@ -209,17 +209,17 @@ describe Jekyll::SeoTag do
context "when given a twitter image" do
let(:page) { make_page("image" => { "twitter" => "/img/twitter.png" }) }
it "outputs the image" do
expected = %r!<meta name="twitter:image" content="http://example.invalid/img/twitter.png" />!
it "outputs an open graph image" do
expected = %r!<meta property="og:image" content="http://example.invalid/img/twitter.png" />!
expect(output).to match(expected)
end
end
context "when given the image height and width" do
let(:image) { { "facebook" => "/img/foo.png", "height" => 1, "width" => 2 } }
context "when given an image height and width" do
let(:image) { { "path" => "/img/foo.png", "height" => 1, "width" => 2 } }
let(:page) { make_page("image" => image) }
it "outputs the image" do
it "outputs an open graph image width and height" do
expected = %r!<meta property="og:image:height" content="1" />!
expect(output).to match(expected)
expected = %r!<meta property="og:image:width" content="2" />!
@ -257,6 +257,7 @@ describe Jekyll::SeoTag do
<!-- Begin Jekyll SEO tag v#{version} -->
<title>Foo</title>
<meta property="og:title" content="Foo" />
<meta property="og:locale" content="en_US" />
<link rel="canonical" href="http://example.invalid/page.html" />
<meta property="og:url" content="http://example.invalid/page.html" />
<meta property="og:site_name" content="Foo" />
@ -581,4 +582,38 @@ EOS
end
end
end
context "with locale" do
it "uses en_US when no locale is specified" do
expected = %r!<meta property="og:locale" content="en_US" />!
expect(output).to match(expected)
end
context "with site.lang" do
let(:site) { make_site("lang" => "en_US") }
it "uses site.lang if page.lang is not present" do
expected = %r!<meta property="og:locale" content="en_US" />!
expect(output).to match(expected)
end
context "with page.lang" do
let(:page) { make_page("lang" => "en_UK") }
it "uses page.lang if both site.lang and page.lang are present" do
expected = %r!<meta property="og:locale" content="en_UK" />!
expect(output).to match(expected)
end
end
end
context "with site.lang hyphenated" do
let(:site) { make_site("lang" => "en-US") }
it "coerces hyphen to underscore" do
expected = %r!<meta property="og:locale" content="en_US" />!
expect(output).to match(expected)
end
end
end
end