Skip to content

Commit dcf646c

Browse files
authored
Merge pull request #166 from aarongustafson/add-locale-support
Add og:locale support
2 parents 32ec930 + 4f919b2 commit dcf646c

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
/pkg/
88
/spec/reports/
99
/tmp/
10+
/bin/
1011
*.gem

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ webmaster_verifications:
102102
yandex: 1234
103103
```
104104

105+
* `lang` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`.
106+
105107
The SEO tag will respect the following YAML front matter if included in a post, page, or document:
106108

107109
* `title` - The title of the post, page, or document
108110
* `description` - A short description of the page's content
109111
* `image` - URL to an image associated with the post, page, or document (e.g., `/assets/page-pic.jpg`)
110112
* `author` - Page-, post-, or document-specific author information (see below)
113+
* `lang` - Page-, post-, or document-specific language information
111114

112115
## Advanced usage
113116

lib/template.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
{% assign seo_page_image = seo_page_image | escape %}
9898
{% endif %}
9999

100+
{% assign seo_page_lang = page.lang | default: site.lang | default: "en_US" %}
101+
100102
{% if seo_tag.title and seo_title %}
101103
<title>{{ seo_title }}</title>
102104
{% endif %}
@@ -109,6 +111,8 @@
109111
<meta name="author" content="{{ seo_author_name }}" />
110112
{% endif %}
111113

114+
<meta property="og:locale" content="{{ seo_page_lang | replace:'-','_' }}" />
115+
112116
{% if seo_description %}
113117
<meta name="description" content="{{ seo_description }}" />
114118
<meta property="og:description" content="{{ seo_description }}" />
@@ -124,7 +128,6 @@
124128
{% endif %}
125129

126130
{% if seo_page_image %}
127-
128131
<meta property="og:image" content="{{ seo_page_image }}" />
129132
{% if page.image.height %}
130133
<meta property="og:image:height" content="{{ page.image.height }}" />

spec/jekyll_seo_tag_spec.rb

+35
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
<!-- Begin Jekyll SEO tag v#{version} -->
258258
<title>Foo</title>
259259
<meta property="og:title" content="Foo" />
260+
<meta property="og:locale" content="en_US" />
260261
<link rel="canonical" href="http://example.invalid/page.html" />
261262
<meta property="og:url" content="http://example.invalid/page.html" />
262263
<meta property="og:site_name" content="Foo" />
@@ -581,4 +582,38 @@
581582
end
582583
end
583584
end
585+
586+
context "with locale" do
587+
it "uses en_US when no locale is specified" do
588+
expected = %r!<meta property="og:locale" content="en_US" />!
589+
expect(output).to match(expected)
590+
end
591+
592+
context "with site.lang" do
593+
let(:site) { make_site("lang" => "en_US") }
594+
595+
it "uses site.lang if page.lang is not present" do
596+
expected = %r!<meta property="og:locale" content="en_US" />!
597+
expect(output).to match(expected)
598+
end
599+
600+
context "with page.lang" do
601+
let(:page) { make_page("lang" => "en_UK") }
602+
603+
it "uses page.lang if both site.lang and page.lang are present" do
604+
expected = %r!<meta property="og:locale" content="en_UK" />!
605+
expect(output).to match(expected)
606+
end
607+
end
608+
end
609+
610+
context "with site.lang hyphenated" do
611+
let(:site) { make_site("lang" => "en-US") }
612+
613+
it "coerces hyphen to underscore" do
614+
expected = %r!<meta property="og:locale" content="en_US" />!
615+
expect(output).to match(expected)
616+
end
617+
end
618+
end
584619
end

0 commit comments

Comments
 (0)