From 8b5d2901c262c6f9e97dcb1bfc473bd4250c5ea8 Mon Sep 17 00:00:00 2001 From: Ilgiz Mustafin Date: Fri, 8 Oct 2021 08:50:06 +0300 Subject: [PATCH] Allow setting `author.url` (#453) Merge pull request 453 --- docs/advanced-usage.md | 12 ++++++++++++ lib/jekyll-seo-tag/json_ld_drop.rb | 7 ++++++- spec/jekyll_seo_tag/json_ld_drop_spec.rb | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index a0d0a57..e534abd 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -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. diff --git a/lib/jekyll-seo-tag/json_ld_drop.rb b/lib/jekyll-seo-tag/json_ld_drop.rb index 11d04e3..c892895 100644 --- a/lib/jekyll-seo-tag/json_ld_drop.rb +++ b/lib/jekyll-seo-tag/json_ld_drop.rb @@ -41,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 diff --git a/spec/jekyll_seo_tag/json_ld_drop_spec.rb b/spec/jekyll_seo_tag/json_ld_drop_spec.rb index c40f4ed..3f1b5ff 100644 --- a/spec/jekyll_seo_tag/json_ld_drop_spec.rb +++ b/spec/jekyll_seo_tag/json_ld_drop_spec.rb @@ -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