Skip to content

Commit

Permalink
Render og:locale meta only when defined explicitly (#388)
Browse files Browse the repository at this point in the history
Merge pull request 388
  • Loading branch information
ashmaroli authored Oct 8, 2020
1 parent dac459f commit 54beeaa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ The following properties are available:
yandex: 1234
baidu: 1234
```
* `lang` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`.
* `locale` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`. Takes priority
over existing config key `lang`.

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 [Advanced usage](advanced-usage.md#author-information))
* `lang` - Page-, post-, or document-specific language information
* `locale` - Page-, post-, or document-specific locale information. Takes priority over existing front matter attribute `lang`.

*Note:* Front matter defaults can be used for any of the above values as described in advanced usage with an image example.
4 changes: 4 additions & 0 deletions lib/jekyll-seo-tag/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def page_lang
@page_lang ||= page["lang"] || site["lang"] || "en_US"
end

def page_locale
@page_locale ||= (page["locale"] || site["locale"] || page_lang).tr("-", "_")
end

def canonical_url
@canonical_url ||= begin
if page["canonical_url"].to_s.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<meta name="author" content="{{ seo_tag.author.name }}" />
{% endif %}

<meta property="og:locale" content="{{ seo_tag.page_lang | replace:'-','_' }}" />
<meta property="og:locale" content="{{ seo_tag.page_locale }}" />

{% if seo_tag.description %}
<meta name="description" content="{{ seo_tag.description }}" />
Expand Down

0 comments on commit 54beeaa

Please sign in to comment.