Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use site.name if site.title is not present #25

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions lib/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@
{% 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 %}
{% endif %}
{% 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 %}
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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 }}
}
Expand Down
14 changes: 14 additions & 0 deletions spec/jekyll_seo_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@
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 = {
Expand Down