Skip to content

Commit 11cd72c

Browse files
authored
Merge pull request #151 from aav7fl/master
Add tags to JSON metadata
2 parents 2744aba + 5b2e8f3 commit 11cd72c

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The SEO tag will respect any of the following if included in your site's `_confi
7878
* `social` - For [specifying social profiles](https://developers.google.com/structured-data/customize/social-profiles). The following properties are available:
7979
* `name` - If the user or organization name differs from the site's name
8080
* `links` - An array of links to social media profiles.
81+
* `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.
8182

8283
```yml
8384
social:

lib/template.html

+25
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
{% assign seo_author_twitter = seo_author_twitter | replace:"@","" %}
6666
{% endif %}
6767

68+
{% if page.date_modified or page.last_modified_at or page.date %}
69+
{% assign seo_date_modified = page.seo.date_modified | default: page.last_modified_at %}
70+
{% endif %}
71+
6872
{% if page.seo and page.seo.type %}
6973
{% assign seo_type = page.seo.type %}
7074
{% elsif seo_homepage_or_about %}
@@ -211,6 +215,13 @@
211215
"headline": {{ seo_page_title | jsonify }},
212216
{% endif %}
213217

218+
{% if seo_author %}
219+
"author": {
220+
"@type": "Person",
221+
"name": {{ seo_author | jsonify }}
222+
},
223+
{% endif %}
224+
214225
{% if seo_page_image %}
215226
"image": {{ seo_page_image | jsonify }},
216227
{% endif %}
@@ -219,20 +230,34 @@
219230
"datePublished": {{ page.date | date_to_xmlschema | jsonify }},
220231
{% endif %}
221232

233+
{% if seo_date_modified %}
234+
"dateModified": {{ seo_date_modified | date_to_xmlschema | jsonify }},
235+
{% endif %}
236+
222237
{% if seo_description %}
223238
"description": {{ seo_description | jsonify }},
224239
{% endif %}
225240

226241
{% if seo_site_logo %}
227242
"publisher": {
228243
"@type": "Organization",
244+
{% if seo_author %}
245+
"name": {{ seo_author | jsonify }},
246+
{% endif %}
229247
"logo": {
230248
"@type": "ImageObject",
231249
"url": {{ seo_site_logo | jsonify }}
232250
}
233251
},
234252
{% endif %}
235253

254+
{% if seo_type == "BlogPosting" or seo_type == "CreativeWork"%}
255+
"mainEntityOfPage": {
256+
"@type": "WebPage",
257+
"@id": {{ page.url | replace:'/index.html','/' | absolute_url | jsonify }}
258+
},
259+
{% endif %}
260+
236261
{% if seo_links %}
237262
"sameAs": {{ seo_links | jsonify }},
238263
{% endif %}

spec/jekyll_seo_tag_spec.rb

+42
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,48 @@
244244
end
245245
end
246246

247+
context "with site.logo and page.author" do
248+
let(:site) { make_site("logo" => "http://cdn.example.invalid/logo.png", "url" => "http://example.invalid", "author" => "Mr. Foo") }
249+
250+
it "outputs the author" do
251+
expect(json_data["publisher"]["name"]).to eql("Mr. Foo")
252+
end
253+
end
254+
255+
context "with page author" do
256+
let(:site) { make_site("logo" => "/logo.png", "url" => "http://example.invalid") }
257+
let(:page) { make_post("author" => "Mr. Foo") }
258+
259+
it "outputs the author" do
260+
expect(json_data["author"]["@type"]).to eql("Person")
261+
expect(json_data["author"]["name"]).to eql("Mr. Foo")
262+
end
263+
264+
it "outputs the publisher author" do
265+
expect(json_data["publisher"]["name"]).to eql("Mr. Foo")
266+
end
267+
end
268+
269+
context "with seo type is BlogPosting" do
270+
let(:site) { make_site("url" => "http://example.invalid") }
271+
let(:page) { make_post("seo" => { "type" => "BlogPosting" }, "permalink" => "/foo/") }
272+
273+
it "outputs the mainEntityOfPage" do
274+
expect(json_data["mainEntityOfPage"]["@type"]).to eql("WebPage")
275+
expect(json_data["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
276+
end
277+
end
278+
279+
context "with seo type is CreativeWork" do
280+
let(:site) { make_site("url" => "http://example.invalid") }
281+
let(:page) { make_post("seo" => { "type" => "CreativeWork" }, "permalink" => "/foo/") }
282+
283+
it "outputs the mainEntityOfPage" do
284+
expect(json_data["mainEntityOfPage"]["@type"]).to eql("WebPage")
285+
expect(json_data["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
286+
end
287+
end
288+
247289
context "with site.title" do
248290
let(:site) { make_site("title" => "Foo", "url" => "http://example.invalid") }
249291

0 commit comments

Comments
 (0)