Merge pull request #151 from aav7fl/master

Add tags to JSON metadata
This commit is contained in:
Ben Balter 2017-04-06 15:02:04 -04:00 committed by GitHub
commit 11cd72c914
3 changed files with 68 additions and 0 deletions

View File

@ -78,6 +78,7 @@ The SEO tag will respect any of the following if included in your site's `_confi
* `social` - For [specifying social profiles](https://developers.google.com/structured-data/customize/social-profiles). The following properties are available:
* `name` - If the user or organization name differs from the site's name
* `links` - An array of links to social media profiles.
* `date_modified` - Manually specify the `dateModified` field in the JSON-LD output to override Jekyll's own `dateModified`. This field will take **first priority** for the `dateModified` JSON-LD output. This is useful when the file timestamp does not match the true time that the content was modified. A user may also install [Last Modified At](https://github.com/gjtorikian/jekyll-last-modified-at) which will offer an alternative way of providing for the `dateModified` field.
```yml
social:

View File

@ -65,6 +65,10 @@
{% assign seo_author_twitter = seo_author_twitter | replace:"@","" %}
{% endif %}
{% if page.date_modified or page.last_modified_at or page.date %}
{% assign seo_date_modified = page.seo.date_modified | default: page.last_modified_at %}
{% endif %}
{% if page.seo and page.seo.type %}
{% assign seo_type = page.seo.type %}
{% elsif seo_homepage_or_about %}
@ -211,6 +215,13 @@
"headline": {{ seo_page_title | jsonify }},
{% endif %}
{% if seo_author %}
"author": {
"@type": "Person",
"name": {{ seo_author | jsonify }}
},
{% endif %}
{% if seo_page_image %}
"image": {{ seo_page_image | jsonify }},
{% endif %}
@ -219,6 +230,10 @@
"datePublished": {{ page.date | date_to_xmlschema | jsonify }},
{% endif %}
{% if seo_date_modified %}
"dateModified": {{ seo_date_modified | date_to_xmlschema | jsonify }},
{% endif %}
{% if seo_description %}
"description": {{ seo_description | jsonify }},
{% endif %}
@ -226,6 +241,9 @@
{% if seo_site_logo %}
"publisher": {
"@type": "Organization",
{% if seo_author %}
"name": {{ seo_author | jsonify }},
{% endif %}
"logo": {
"@type": "ImageObject",
"url": {{ seo_site_logo | jsonify }}
@ -233,6 +251,13 @@
},
{% endif %}
{% if seo_type == "BlogPosting" or seo_type == "CreativeWork"%}
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{ page.url | replace:'/index.html','/' | absolute_url | jsonify }}
},
{% endif %}
{% if seo_links %}
"sameAs": {{ seo_links | jsonify }},
{% endif %}

View File

@ -244,6 +244,48 @@ describe Jekyll::SeoTag do
end
end
context "with site.logo and page.author" do
let(:site) { make_site("logo" => "http://cdn.example.invalid/logo.png", "url" => "http://example.invalid", "author" => "Mr. Foo") }
it "outputs the author" do
expect(json_data["publisher"]["name"]).to eql("Mr. Foo")
end
end
context "with page author" do
let(:site) { make_site("logo" => "/logo.png", "url" => "http://example.invalid") }
let(:page) { make_post("author" => "Mr. Foo") }
it "outputs the author" do
expect(json_data["author"]["@type"]).to eql("Person")
expect(json_data["author"]["name"]).to eql("Mr. Foo")
end
it "outputs the publisher author" do
expect(json_data["publisher"]["name"]).to eql("Mr. Foo")
end
end
context "with seo type is BlogPosting" do
let(:site) { make_site("url" => "http://example.invalid") }
let(:page) { make_post("seo" => { "type" => "BlogPosting" }, "permalink" => "/foo/") }
it "outputs the mainEntityOfPage" do
expect(json_data["mainEntityOfPage"]["@type"]).to eql("WebPage")
expect(json_data["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
end
end
context "with seo type is CreativeWork" do
let(:site) { make_site("url" => "http://example.invalid") }
let(:page) { make_post("seo" => { "type" => "CreativeWork" }, "permalink" => "/foo/") }
it "outputs the mainEntityOfPage" do
expect(json_data["mainEntityOfPage"]["@type"]).to eql("WebPage")
expect(json_data["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
end
end
context "with site.title" do
let(:site) { make_site("title" => "Foo", "url" => "http://example.invalid") }