Merge pull request #166 from aarongustafson/add-locale-support

Add og:locale support
This commit is contained in:
Ben Balter 2017-04-04 09:40:54 -04:00 committed by GitHub
commit dcf646c8d0
4 changed files with 43 additions and 1 deletions

1
.gitignore vendored
View File

@ -7,4 +7,5 @@
/pkg/
/spec/reports/
/tmp/
/bin/
*.gem

View File

@ -102,12 +102,15 @@ webmaster_verifications:
yandex: 1234
```
* `lang` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`.
The SEO tag will respect the following YAML front matter if included in a post, page, or document:
* `title` - The title of the post, page, or document
* `description` - A short description of the page's content
* `image` - URL to an image associated with the post, page, or document (e.g., `/assets/page-pic.jpg`)
* `author` - Page-, post-, or document-specific author information (see below)
* `lang` - Page-, post-, or document-specific language information
## Advanced usage

View File

@ -97,6 +97,8 @@
{% assign seo_page_image = seo_page_image | escape %}
{% endif %}
{% assign seo_page_lang = page.lang | default: site.lang | default: "en_US" %}
{% if seo_tag.title and seo_title %}
<title>{{ seo_title }}</title>
{% endif %}
@ -109,6 +111,8 @@
<meta name="author" content="{{ seo_author_name }}" />
{% endif %}
<meta property="og:locale" content="{{ seo_page_lang | replace:'-','_' }}" />
{% if seo_description %}
<meta name="description" content="{{ seo_description }}" />
<meta property="og:description" content="{{ seo_description }}" />
@ -124,7 +128,6 @@
{% endif %}
{% if seo_page_image %}
<meta property="og:image" content="{{ seo_page_image }}" />
{% if page.image.height %}
<meta property="og:image:height" content="{{ page.image.height }}" />

View File

@ -257,6 +257,7 @@ describe Jekyll::SeoTag do
<!-- Begin Jekyll SEO tag v#{version} -->
<title>Foo</title>
<meta property="og:title" content="Foo" />
<meta property="og:locale" content="en_US" />
<link rel="canonical" href="http://example.invalid/page.html" />
<meta property="og:url" content="http://example.invalid/page.html" />
<meta property="og:site_name" content="Foo" />
@ -581,4 +582,38 @@ EOS
end
end
end
context "with locale" do
it "uses en_US when no locale is specified" do
expected = %r!<meta property="og:locale" content="en_US" />!
expect(output).to match(expected)
end
context "with site.lang" do
let(:site) { make_site("lang" => "en_US") }
it "uses site.lang if page.lang is not present" do
expected = %r!<meta property="og:locale" content="en_US" />!
expect(output).to match(expected)
end
context "with page.lang" do
let(:page) { make_page("lang" => "en_UK") }
it "uses page.lang if both site.lang and page.lang are present" do
expected = %r!<meta property="og:locale" content="en_UK" />!
expect(output).to match(expected)
end
end
end
context "with site.lang hyphenated" do
let(:site) { make_site("lang" => "en-US") }
it "coerces hyphen to underscore" do
expected = %r!<meta property="og:locale" content="en_US" />!
expect(output).to match(expected)
end
end
end
end