Use site.name if site.title is not present

This commit is contained in:
Pat Hawks 2016-01-11 17:30:26 -08:00
parent 85934ae5de
commit 99340a927f
No known key found for this signature in database
GPG Key ID: F1746FF5F18B3D1B
2 changed files with 32 additions and 9 deletions

View File

@ -6,15 +6,21 @@
{% assign seo_url = site.github.url %}
{% endif %}
{% if site.title %}
{% assign seo_site_title = site.title %}
{% elsif site.name %}
{% assign seo_site_title = site.name %}
{% endif %}
{% if page.title %}
{% assign seo_title = page.title %}
{% assign seo_page_title = page.title %}
{% if site.title %}
{% assign seo_title = seo_title | append:" - " | append: site.title %}
{% if seo_site_title %}
{% assign seo_title = seo_title | append:" - " | append: seo_site_title %}
{% endif %}
{% elsif site.title %}
{% assign seo_title = site.title %}
{% assign seo_page_title = site.title %}
{% elsif seo_site_title %}
{% assign seo_title = seo_site_title %}
{% assign seo_page_title = seo_site_title %}
{% if site.description %}
{% assign seo_title = seo_title | append:" - " | append: site.description %}
{% endif %}
@ -22,6 +28,9 @@
{% if seo_title %}
{% assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once %}
{% endif %}
{% if seo_site_title %}
{% assign seo_site_title = seo_site_title | markdownify | strip_html | strip_newlines | escape_once %}
{% endif %}
{% if seo_page_title %}
{% assign seo_page_title = seo_page_title | markdownify | strip_html | strip_newlines | escape_once %}
{% endif %}
@ -53,13 +62,13 @@
<meta property='og:url' content='{{ page.url | prepend: seo_url | replace:'/index.html','/' }}' />
{% endif %}
{% if site.title %}
<meta property="og:site_name" content="{{ site.title }}" />
{% if seo_site_title %}
<meta property="og:site_name" content="{{ seo_site_title }}" />
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "WebSite",
"name" : {{ site.title | jsonify }},
"name" : {{ seo_site_title | jsonify }},
"url" : {{ seo_url | jsonify }}
}
</script>
@ -118,7 +127,7 @@
{
"@context" : "http://schema.org",
"@type" : "{% if site.social.type %}{{ site.social.type }}{% else %}person{% endif %}",
"name" : "{% if site.social.name %}{{ site.social.name }}{% else %}{{ site.title }}{% endif %}",
"name" : "{% if site.social.name %}{{ site.social.name }}{% else %}{{ seo_site_title }}{% endif %}",
"url" : {{ seo_url | jsonify }},
"sameAs" : {{ site.social.links | jsonify }}
}

View File

@ -165,6 +165,20 @@ describe Jekyll::SeoTag do
expect(subject.render(context)).to match(expected)
end
it "uses site.name if site.title is not present" do
site = site({"name" => "Site Name", "title" => nil })
context = context({ :site => site })
expected = %r!<meta property="og:site_name" content="Site Name" />!
expect(subject.render(context)).to match(expected)
end
it "uses site.tile if both site.title and site.name are present" do
site = site({"name" => "Site Name", "title" => "Site Title" })
context = context({ :site => site })
expected = %r!<meta property="og:site_name" content="Site Title" />!
expect(subject.render(context)).to match(expected)
end
it "outputs valid HTML" do
site.process
options = {