From 308cf7a523df8321e2c8290e30f23309b5da3bd1 Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Fri, 31 Mar 2017 14:19:37 -0400 Subject: [PATCH 01/14] Added support for locale exposure as `og:locale` --- lib/template.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/template.html b/lib/template.html index eacff7f..50488b1 100755 --- a/lib/template.html +++ b/lib/template.html @@ -97,6 +97,10 @@ {% assign seo_page_image = seo_page_image | escape %} {% endif %} +{% if site.locale %} + {% assign seo_page_locale = page.locale | default: site.locale %} +{% endif %} + {% if seo_tag.title and seo_title %} {{ seo_title }} {% endif %} @@ -109,6 +113,10 @@ {% endif %} +{% if seo_page_locale %} + +{% endif %} + {% if seo_description %} From 59b20c7bf95a84d8031fe4ae040b5953f5cbaeb5 Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Fri, 31 Mar 2017 14:26:58 -0400 Subject: [PATCH 02/14] Added test --- spec/jekyll_seo_tag_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 1937ab9..700f524 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -581,4 +581,24 @@ EOS end end end + + context "with locale" do + let(:site) { make_site("locale" => "en_US") } + + it "uses site.locale if page.locale is not present" do + expected = %r!! + expect(output).to match(expected) + end + + context "with page.locale" do + let(:site) { make_site("locale" => "en_US") } + let(:page) { make_page("locale" => "en_UK") } + + it "uses page.locale if both site.locale and page.locale are present" do + expected = %r!! + expect(output).to match(expected) + end + end + end + end From 179530d8859688bcb30dcc40e615529e7c444130 Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Fri, 31 Mar 2017 14:31:16 -0400 Subject: [PATCH 03/14] Added documentation --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8f71d58..1f4169c 100644 --- a/README.md +++ b/README.md @@ -102,12 +102,15 @@ webmaster_verifications: yandex: 1234 ``` +* `locale` - 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) +* `locale` - Page-, post-, or document-specific language information ## Advanced usage From 2191a550eee4037be44c13b761bc4b2cff1b9643 Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Fri, 31 Mar 2017 14:41:46 -0400 Subject: [PATCH 04/14] Test cleanup --- lib/template.html | 8 ++------ spec/jekyll_seo_tag_spec.rb | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/template.html b/lib/template.html index 50488b1..8ce8a9e 100755 --- a/lib/template.html +++ b/lib/template.html @@ -97,9 +97,7 @@ {% assign seo_page_image = seo_page_image | escape %} {% endif %} -{% if site.locale %} - {% assign seo_page_locale = page.locale | default: site.locale %} -{% endif %} +{% assign seo_page_locale = page.locale | default: site.locale | default: "en_US"" %} {% if seo_tag.title and seo_title %} {{ seo_title }} @@ -113,9 +111,7 @@ {% endif %} -{% if seo_page_locale %} - -{% endif %} + {% if seo_description %} diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 700f524..38a020d 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -257,6 +257,7 @@ describe Jekyll::SeoTag do Foo + @@ -583,21 +584,27 @@ EOS end context "with locale" do - let(:site) { make_site("locale" => "en_US") } - - it "uses site.locale if page.locale is not present" do + it "uses en_US when no locale is specified" do expected = %r!! expect(output).to match(expected) end - context "with page.locale" do + context "with site.locale" do let(:site) { make_site("locale" => "en_US") } - let(:page) { make_page("locale" => "en_UK") } - - it "uses page.locale if both site.locale and page.locale are present" do - expected = %r!! + + it "uses site.locale if page.locale is not present" do + expected = %r!! expect(output).to match(expected) end + + context "with page.locale" do + let(:page) { make_page("locale" => "en_UK") } + + it "uses page.locale if both site.locale and page.locale are present" do + expected = %r!! + expect(output).to match(expected) + end + end end end From ef8fe3106cc8d7752ddec2bd32af716f07517c1a Mon Sep 17 00:00:00 2001 From: Frank Taillandier Date: Fri, 31 Mar 2017 21:31:06 +0200 Subject: [PATCH 05/14] bump and appease Rubocop --- Gemfile | 16 ++++++++-------- Rakefile | 6 +++--- jekyll-seo-tag.gemspec | 39 ++++++++++++++++++++------------------- lib/jekyll-seo-tag.rb | 2 +- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index 0919f4a..c626203 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index 4c774a2..b7e9ed5 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index 872c582..75abd13 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -1,34 +1,35 @@ # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) + +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'jekyll-seo-tag/version' +require "jekyll-seo-tag/version" Gem::Specification.new do |spec| - spec.name = 'jekyll-seo-tag' + spec.name = "jekyll-seo-tag" spec.version = Jekyll::SeoTag::VERSION - spec.authors = ['Ben Balter'] - spec.email = ['ben.balter@github.com'] + 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.license = 'MIT' + spec.homepage = "https://github.com/benbalter/jekyll-seo-tag" + spec.license = "MIT" # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or # delete this section to allow pushing this gem to any host. if spec.respond_to?(:metadata) - spec.metadata['allowed_push_host'] = 'https://rubygems.org' + spec.metadata["allowed_push_host"] = "https://rubygems.org" else - raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' + raise "RubyGems 2.0 or newer is required to protect against public gem pushes." end - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - spec.bindir = 'exe' - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] + spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) } + spec.bindir = "exe" + spec.executables = spec.files.grep(%r!^exe/!) { |f| File.basename(f) } + spec.require_paths = ["lib"] - spec.add_dependency 'jekyll', '~> 3.3' - spec.add_development_dependency 'bundler', '~> 1.10' - spec.add_development_dependency 'rake', '~> 10.0' - spec.add_development_dependency 'rspec', '~> 3.3' - spec.add_development_dependency 'html-proofer', '~> 2.5' - spec.add_development_dependency 'rubocop', '~> 0.37' + spec.add_dependency "jekyll", "~> 3.3" + spec.add_development_dependency "bundler", "~> 1.10" + spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "rspec", "~> 3.3" + spec.add_development_dependency "html-proofer", "~> 2.5" + spec.add_development_dependency "rubocop", "~> 0.48" end diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index 696daa6..7d3a736 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -44,7 +44,7 @@ module Jekyll end def title? - !(@text =~ %r!title=false!i) + @text !~ %r!title=false!i end def info From 4be96131915313478655c7c15c859c7b887099b2 Mon Sep 17 00:00:00 2001 From: Frank Taillandier Date: Fri, 31 Mar 2017 23:55:49 +0200 Subject: [PATCH 06/14] Disable Style/IndentHeredoc on specs --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index c796613..d60d44a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,10 @@ Style/Documentation: Style/FileName: Enabled: false +Style/IndentHeredoc: + Exclude: + - spec/**/* + AllCops: Exclude: - vendor/**/* From 8a5b022a89826c3e48fff37c13c42e90835530ee Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Mon, 3 Apr 2017 11:11:59 -0400 Subject: [PATCH 07/14] Adding /bin/ to mask local testing --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b7e7725..3476aa5 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ /pkg/ /spec/reports/ /tmp/ +/bin/ *.gem From abf32914b7abc056f04064aeea4404f2329d0406 Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Mon, 3 Apr 2017 11:21:48 -0400 Subject: [PATCH 08/14] Switching to site.lang & page.lang to align with jekyll-feed --- lib/template.html | 2 +- spec/jekyll_seo_tag_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/template.html b/lib/template.html index 8ce8a9e..ab25607 100755 --- a/lib/template.html +++ b/lib/template.html @@ -97,7 +97,7 @@ {% assign seo_page_image = seo_page_image | escape %} {% endif %} -{% assign seo_page_locale = page.locale | default: site.locale | default: "en_US"" %} +{% assign seo_page_locale = page.lang | default: site.lang | default: "en_US"" %} {% if seo_tag.title and seo_title %} {{ seo_title }} diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 38a020d..c516d70 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -589,18 +589,18 @@ EOS expect(output).to match(expected) end - context "with site.locale" do - let(:site) { make_site("locale" => "en_US") } + context "with site.lang" do + let(:site) { make_site("lang" => "en_US") } - it "uses site.locale if page.locale is not present" do + it "uses site.lang if page.lang is not present" do expected = %r!! expect(output).to match(expected) end - context "with page.locale" do - let(:page) { make_page("locale" => "en_UK") } + context "with page.lang" do + let(:page) { make_page("lang" => "en_UK") } - it "uses page.locale if both site.locale and page.locale are present" do + it "uses page.lang if both site.lang and page.lang are present" do expected = %r!! expect(output).to match(expected) end From b3d5db35635b99585bf455803d012e5deeb57196 Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Mon, 3 Apr 2017 11:32:31 -0400 Subject: [PATCH 09/14] Fixing Rubocop offenses --- spec/jekyll_seo_tag_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index c516d70..579e7ce 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -591,7 +591,7 @@ EOS 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!! expect(output).to match(expected) @@ -607,5 +607,4 @@ EOS end end end - end From e264a9a94bbf50cf8a0b6fb285dc5e9b46c380ff Mon Sep 17 00:00:00 2001 From: Josh Habdas Date: Tue, 4 Apr 2017 00:56:04 +0800 Subject: [PATCH 10/14] refactor(template): use og:image for twitter #77 and #78 added support for different images on Twitter and Facebook, an advanced feature of SEO Tag Gem. The implementation has led to complications updating JSON-LD data in #151. Under Pareto principal we can reasonably assume this feature is not often used, and, as such, should be removed. The result of which simplifies template logic, offers a fallback experience by leverages Twitter's use of `og:image` in place of `twitter:image` (sees twitter card tag ref) and helps unblock #151. Users can no longer specify a separate twitter and Facebook image. If both a Facebook (Open Graph) and Twitter image are provided in the `image` object, the Facebook image will take precedence. --- README.md | 13 +++++-------- lib/template.html | 9 +++------ spec/jekyll_seo_tag_spec.rb | 18 +++++++++--------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 58b17fa..3f08fe2 100644 --- a/README.md +++ b/README.md @@ -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. @@ -191,17 +191,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 ``` diff --git a/lib/template.html b/lib/template.html index 3885dd9..988c7cb 100755 --- a/lib/template.html +++ b/lib/template.html @@ -98,7 +98,7 @@ {% 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 %} @@ -132,7 +132,8 @@ {% endif %} {% if seo_page_image %} - + + {% if page.image.height %} {% endif %} @@ -141,10 +142,6 @@ {% endif %} {% endif %} -{% if page.image.twitter %} - -{% endif %} - {% if page.date %} diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 38c0360..e54b36c 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -124,7 +124,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 = '' expect(output).to include(expected) end @@ -133,7 +133,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 = '' expect(output).to include(expected) end @@ -143,7 +143,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!! expect(output).to match(expected) end @@ -152,7 +152,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!! expect(output).to match(expected) end @@ -161,17 +161,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!! + it "outputs an open graph image" do + expected = %r!! 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!! expect(output).to match(expected) expected = %r!! From e2114abbb79463f91edfb5e8447538c5d062b1c6 Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Mon, 3 Apr 2017 14:41:21 -0400 Subject: [PATCH 11/14] Fixing the documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1f4169c..f6ec5ac 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ webmaster_verifications: yandex: 1234 ``` -* `locale` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`. +* `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: @@ -110,7 +110,7 @@ The SEO tag will respect the following YAML front matter if included in a post, * `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) -* `locale` - Page-, post-, or document-specific language information +* `lang` - Page-, post-, or document-specific language information ## Advanced usage From 18ec5736c205a1267fa879335417fa022ff07ddf Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Mon, 3 Apr 2017 15:09:35 -0400 Subject: [PATCH 12/14] Variable rename --- lib/template.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/template.html b/lib/template.html index ab25607..6531d1a 100755 --- a/lib/template.html +++ b/lib/template.html @@ -97,7 +97,7 @@ {% assign seo_page_image = seo_page_image | escape %} {% endif %} -{% assign seo_page_locale = page.lang | default: site.lang | default: "en_US"" %} +{% assign seo_page_lang = page.lang | default: site.lang | default: "en_US" %} {% if seo_tag.title and seo_title %} {{ seo_title }} @@ -111,7 +111,7 @@ {% endif %} - + {% if seo_description %} From 8a8a5e98599361c7738d511cfc33242b240cf31e Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Mon, 3 Apr 2017 20:04:29 -0400 Subject: [PATCH 13/14] Added hyphen to underscore coersion --- lib/template.html | 3 +-- spec/jekyll_seo_tag_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/template.html b/lib/template.html index 38e89f6..c06665c 100755 --- a/lib/template.html +++ b/lib/template.html @@ -111,7 +111,7 @@ {% endif %} - + {% if seo_description %} @@ -128,7 +128,6 @@ {% endif %} {% if seo_page_image %} - {% if page.image.height %} diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index f738072..a96aea2 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -606,5 +606,14 @@ EOS end end end + + context "with site.lang hyphenated" do + let(:site) { make_site("lang" => "en-US") } + + it "coerces hyphen to underscore" do + expected = %r!! + expect(output).to match(expected) + end + end end end From 4f919b2aaaf398eecc4a37144279e9692095815c Mon Sep 17 00:00:00 2001 From: Aaron Gustafson Date: Mon, 3 Apr 2017 20:05:24 -0400 Subject: [PATCH 14/14] Anticitating Rubocop --- spec/jekyll_seo_tag_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index a96aea2..e2bcb0b 100755 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -606,7 +606,7 @@ EOS end end end - + context "with site.lang hyphenated" do let(:site) { make_site("lang" => "en-US") }