Merge branch 'master' into User-`name`-instead-of-`property`-for-twitter

This commit is contained in:
Ashwin Maroli 2021-11-25 18:26:34 +05:30 committed by GitHub
commit 2480c785bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 279 additions and 66 deletions

103
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,103 @@
name: Continuous Integration
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
j4:
if: "!contains(github.event.commits[0].message, '[ci skip]')"
name: "Jekyll ${{ matrix.jekyll_version }} (Ruby ${{ matrix.ruby_version }})"
runs-on: 'ubuntu-latest'
env:
JEKYLL_VERSION: ${{ matrix.jekyll_version }}
strategy:
fail-fast: false
matrix:
ruby_version:
- 2.5
- 2.7
- 3.0
jekyll_version:
- "~> 4.0"
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: "Set up Ruby ${{ matrix.ruby_version }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Execute tests
run: bundle exec rspec
j3:
if: "!contains(github.event.commits[0].message, '[ci skip]')"
name: "Jekyll ${{ matrix.jekyll_version }} (Ruby ${{ matrix.ruby_version }})"
runs-on: 'ubuntu-latest'
env:
JEKYLL_VERSION: ${{ matrix.jekyll_version }}
strategy:
fail-fast: false
matrix:
ruby_version:
- 2.5
jekyll_version:
- "~> 3.9"
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: "Set up Ruby ${{ matrix.ruby_version }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Execute tests
run: bundle exec rspec
style_check:
if: "!contains(github.event.commits[0].message, '[ci skip]')"
name: "Code Style Check (Ruby ${{ matrix.ruby_version }})"
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
ruby_version:
- 2.5
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: "Set up Ruby ${{ matrix.ruby_version }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Check Style Offenses
run: bundle exec rubocop -S -D
gem_build:
if: "!contains(github.event.commits[0].message, '[ci skip]')"
name: "Test Gem build (Ruby ${{ matrix.ruby_version }})"
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
ruby_version:
- 2.5
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: "Set up Ruby ${{ matrix.ruby_version }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Test Gem build
run: bundle exec gem build jekyll-seo-tag.gemspec

4
.github/workflows/scripts/memprof vendored Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
bundle exec ruby jekyll-seo-tag/.github/workflows/scripts/memprof.rb sandbox
exit 0

View File

@ -9,8 +9,22 @@ on:
- master
jobs:
build_n_profile:
if: "!contains(github.event.commits[0].message, '[ci skip]')"
runs-on: 'ubuntu-latest'
name: "Third-Party Repo Profile with Jekyll ${{ matrix.jekyll_version }} (Ruby ${{ matrix.ruby_version }})"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
ruby_version:
- 2.7
jekyll_version:
- "~> 4.0"
- "~> 3.9"
env:
BUNDLE_GEMFILE: "sandbox/Gemfile"
BUNDLE_PATH: "vendor/bundle"
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
JEKYLL_VERSION: ${{ matrix.jekyll_version }}
steps:
- name: Checkout Jekyll SEO Tag
uses: actions/checkout@v2
@ -21,32 +35,19 @@ jobs:
uses: actions/checkout@v2
with:
repository: ashmaroli/tomjoht.github.io
ref: 'no-seo-tag'
ref: "no-seo-tag"
path: alpha-sandbox
- name: Checkout Same Third-Party Repository (WITH SEO Tag)
uses: actions/checkout@v2
with:
repository: ashmaroli/tomjoht.github.io
ref: 'seo-tag'
ref: "seo-tag"
path: sandbox
- name: Set up Ruby
uses: actions/setup-ruby@v1
- name: "Set up Ruby ${{ matrix.ruby_version }}"
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.x
- name: Set up Dependencies Cache
uses: actions/cache@v1
with:
path: sandbox/vendor/bundle
key: ubuntu-latest-gems-
restore-keys: |
ubuntu-latest-gems-
- name: Set up Dependencies
run: |
gem update --system --no-document
gem update bundler --no-document
bundle config gemfile sandbox/Gemfile
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
ruby-version: ${{ matrix.ruby_version }}
bundler-cache: true
- name: Run Jekyll Build (WITHOUT SEO Tag) 3 times
run: |
bundle exec jekyll build -s alpha-sandbox -d alpha-sandbox/_site --trace
@ -58,4 +59,4 @@ jobs:
bundle exec jekyll build -s sandbox -d sandbox/_site --trace
bundle exec jekyll build -s sandbox -d sandbox/_site --trace
- name: Memory Analysis of Jekyll Build (WITH SEO Tag)
run: bundle exec ruby jekyll-seo-tag/.github/workflows/actions/memprof.rb sandbox
run: bash jekyll-seo-tag/.github/workflows/scripts/memprof

View File

@ -5,15 +5,38 @@ inherit_gem:
rubocop-jekyll: .rubocop.yml
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.5
SuggestExtensions: false
Exclude:
- vendor/**/*
Layout/LineEndStringConcatenationIndentation:
Enabled: true
Layout/LineLength:
Exclude:
- spec/**/*
- jekyll-seo-tag.gemspec
Lint/EmptyInPattern:
Enabled: false
Metrics/BlockLength:
Exclude:
- spec/**/*
Naming/InclusiveLanguage:
Enabled: false
Performance/MapCompact:
Enabled: true
Performance/RedundantEqualityComparisonBlock:
Enabled: true
Performance/RedundantSplitRegexpArgument:
Enabled: true
Style/InPatternThen:
Enabled: false
Style/MultilineInPatternThen:
Enabled: false
Style/QuotedSymbols:
Enabled: true

View File

@ -1,13 +1,46 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude`
# on 2020-03-20 11:41:46 +0100 using RuboCop version 0.80.1.
# on 2021-09-17 06:40:32 UTC using RuboCop version 1.18.4.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Exclude:
- 'lib/jekyll-seo-tag/version.rb'
# Offense count: 3
Lint/NoReturnInBeginEndBlocks:
Exclude:
- 'lib/jekyll-seo-tag/author_drop.rb'
- 'lib/jekyll-seo-tag/drop.rb'
# Offense count: 1
# Cop supports --auto-correct.
Lint/ToJSON:
Exclude:
- 'lib/jekyll-seo-tag/json_ld_drop.rb'
# Offense count: 1
# Configuration parameters: IgnoredMethods, Max.
Metrics/PerceivedComplexity:
Exclude:
- 'lib/jekyll-seo-tag/drop.rb'
# Offense count: 1
# Configuration parameters: MinSize.
Performance/CollectionLiteralInLoop:
Exclude:
- 'spec/jekyll_seo_tag/author_drop_spec.rb'
# Offense count: 9
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'lib/jekyll-seo-tag.rb'
- 'lib/jekyll-seo-tag/author_drop.rb'
- 'lib/jekyll-seo-tag/drop.rb'
- 'lib/jekyll-seo-tag/image_drop.rb'

View File

@ -1,18 +0,0 @@
language: ruby
cache: bundler
rvm:
- 2.5
- 2.7
before_install:
- gem update --system
- gem install bundler
script: script/cibuild
env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
matrix:
- JEKYLL_VERSION="~> 3.9"
- JEKYLL_VERSION="~> 4.0"

View File

@ -3,6 +3,20 @@
### Minor Enhancements
* Allow to set type for author (#427)
* Allow setting `author.url` (#453)
* Implement Facebook domain verification (#455)
* Add `og:image:alt` and `twitter:image:alt` (#438)
### Development Fixes
* Fix typo in source code comment (#449)
* Set up Continuous Integration via GH Actions (#450)
* Bump RuboCop to v1.18.x (#452)
### Bug Fixes
* Set the default og:type to 'website' (#391)
* Template: Remove double new line (#454)
## 2.7.1 / 2020-10-18

View File

@ -68,6 +68,18 @@ There are several ways to convey this author-specific information. Author inform
author: benbalter
```
#### Setting author url
Starting from August 6, 2021 [Google recommends](https://developers.google.com/search/updates) to set the `author.url` property. This property helps Google to disambiguate the correct author of the article.
You can set it the same way as the other author properties. For example, you can put it in an `author` object, in the site's `_config.yml`, e.g.:
```yml
author:
name: My Name
url: https://example.com/
```
### Customizing JSON-LD output
The following options can be set for any particular page. While the default options are meant to serve most users in the most common circumstances, there may be situations where more precise control is necessary.
@ -86,6 +98,7 @@ For most users, setting `image: [path-to-image]` on a per-page basis should be e
* `path` - The relative path to the image. Same as `image: [path-to-image]`
* `height` - The height of the Open Graph (`og:image`) image
* `width` - The width of the Open Graph (`og:image`) image
* `alt` - The alternative image text for Open Graph (`og:image:alt`) and Twitter (`twitter:image:alt`)
You can use any of the above, optional properties, like so:
@ -94,6 +107,7 @@ image:
path: /img/twitter.png
height: 100
width: 100
alt: Twitter Logo
```
### Setting a default image
@ -146,7 +160,7 @@ Which will generate following canonical_url:
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:
For example:
```yml
seo_paginator_message: "%<current>s / %<total>s | "

View File

@ -65,6 +65,7 @@ The following properties are available:
alexa: 1234
yandex: 1234
baidu: 1234
facebook: 1234
```
* `locale` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`. Takes priority
over existing config key `lang`.

View File

@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
end
spec.required_ruby_version = ">= 2.4.0"
spec.required_ruby_version = ">= 2.5.0"
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
spec.bindir = "exe"
@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
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.11"
spec.add_development_dependency "rubocop-jekyll", "~> 0.12.0"
end

View File

@ -41,8 +41,7 @@ module Jekyll
private
attr_reader :page
attr_reader :site
attr_reader :site, :page
# Finds the page author in the page.author, page.authors, or site.author
#
@ -75,9 +74,10 @@ module Jekyll
# or an empty hash, if the author cannot be resolved
def author_hash
@author_hash ||= begin
if resolved_author.is_a? Hash
case resolved_author
when Hash
resolved_author
elsif resolved_author.is_a? String
when String
{ "name" => resolved_author }.merge!(site_data_hash)
else
{}

View File

@ -34,17 +34,17 @@ module Jekyll
private
attr_accessor :page
attr_accessor :context
attr_accessor :page, :context
# The normalized image hash with a `path` key (which may be nil)
def image_hash
@image_hash ||= begin
image_meta = page["image"]
if image_meta.is_a?(Hash)
case image_meta
when Hash
{ "path" => nil }.merge!(image_meta)
elsif image_meta.is_a?(String)
when String
{ "path" => image_meta }
else
{ "path" => nil }

View File

@ -16,9 +16,8 @@ module Jekyll
def_delegator :page_drop, :type, :type
# Expose #type and #logo as private methods and #@type as a public method
alias_method :"@type", :type
private :type
private :logo
alias_method :@type, :type
private :type, :logo
VALID_ENTITY_TYPES = %w(BlogPosting CreativeWork).freeze
VALID_AUTHOR_TYPES = %w(Organization Person).freeze
@ -42,10 +41,15 @@ module Jekyll
author_type = page_drop.author["type"]
return if author_type && !VALID_AUTHOR_TYPES.include?(author_type)
{
hash = {
"@type" => author_type || "Person",
"name" => page_drop.author["name"],
}
author_url = page_drop.author["url"]
hash["url"] = author_url if author_url
hash
end
def image
@ -84,7 +88,7 @@ module Jekyll
private :main_entity
def to_json
to_h.reject { |_k, v| v.nil? }.to_json
to_h.compact.to_json
end
private

View File

@ -8,8 +8,8 @@ module Jekyll
# Determines if the given string is an absolute URL
#
# Returns true if an absolute URL.
# Retruns false if it's a relative URL
# Returns true if an absolute URL
# Returns false if it's a relative URL
# Returns nil if it is not a string or can't be parsed as a URL
def absolute_url?(string)
return unless string

View File

@ -37,11 +37,16 @@
{% if seo_tag.image.width %}
<meta property="og:image:width" content="{{ seo_tag.image.width }}" />
{% endif %}
{% if seo_tag.image.alt %}
<meta property="og:image:alt" content="{{ seo_tag.image.alt }}" />
{% endif %}
{% endif %}
{% if page.date %}
<meta property="og:type" content="article" />
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}" />
{% else %}
<meta property="og:type" content="website" />
{% endif %}
{% if paginator.previous_page %}
@ -51,7 +56,6 @@
<link rel="next" href="{{ paginator.next_page_path | absolute_url }}" />
{% endif %}
{% if seo_tag.image %}
<meta name="twitter:card" content="{{ page.twitter.card | default: site.twitter.card | default: "summary_large_image" }}" />
<meta name="twitter:image" content="{{ seo_tag.image.path }}" />
@ -59,6 +63,10 @@
<meta name="twitter:card" content="summary" />
{% endif %}
{% if seo_tag.image.alt %}
<meta name="twitter:image:alt" content="{{ seo_tag.image.alt }}" />
{% endif %}
{% if seo_tag.page_title %}
<meta name="twitter:title" content="{{ seo_tag.page_title }}" />
{% endif %}
@ -105,6 +113,10 @@
{% if site.webmaster_verifications.baidu %}
<meta name="baidu-site-verification" content="{{ site.webmaster_verifications.baidu }}" />
{% endif %}
{% if site.webmaster_verifications.facebook %}
<meta name="facebook-domain-verification" content="{{ site.webmaster_verifications.facebook }}" />
{% endif %}
{% elsif site.google_site_verification %}
<meta name="google-site-verification" content="{{ site.google_site_verification }}" />
{% endif %}

View File

@ -69,6 +69,7 @@ RSpec.describe Jekyll::SeoTag::JSONLDDrop do
expect(subject["author"]).to have_key("name")
expect(subject["author"]["name"]).to be_a(String)
expect(subject["author"]["name"]).to eql("author")
expect(subject["author"]["url"]).to be nil
end
end
end
@ -95,6 +96,20 @@ RSpec.describe Jekyll::SeoTag::JSONLDDrop do
expect(subject["author"]).to be nil
end
end
context "when url is present" do
let(:author) { { "name" => "author", "url" => "https://example.com" } }
it "returns the author with url" do
expect(subject).to have_key("author")
expect(subject["author"]).to be_a(Hash)
expect(subject["author"]).to have_key("url")
expect(subject["author"]["url"]).to eql("https://example.com")
expect(subject["author"]).to have_key("name")
expect(subject["author"]["name"]).to be_a(String)
expect(subject["author"]["name"]).to eql("author")
end
end
end
context "image" do

View File

@ -26,7 +26,8 @@ RSpec.describe Jekyll::SeoTag do
end
it "outputs meta generator" do
expect(output).to match(%r!Jekyll v#{Jekyll::VERSION}!i)
version = Jekyll::VERSION
expect(output).to match(%r!Jekyll v#{version}!i)
end
it "outputs valid HTML" do
@ -613,10 +614,11 @@ RSpec.describe Jekyll::SeoTag do
context "with site.webmaster_verifications" do
let(:site_verifications) do
{
"google" => "foo",
"bing" => "bar",
"alexa" => "baz",
"yandex" => "bat",
"google" => "foo",
"bing" => "bar",
"alexa" => "baz",
"yandex" => "bat",
"facebook" => "bas",
}
end
@ -641,6 +643,11 @@ RSpec.describe Jekyll::SeoTag do
expected = %r!<meta name="yandex-verification" content="bat" />!
expect(output).to match(expected)
end
it "outputs facebook verification meta" do
expected = %r!<meta name="facebook-domain-verification" content="bas" />!
expect(output).to match(expected)
end
end
context "with site.google_site_verification" do