Merge pull request #76 from jekyll/pr/absolute-image
Add support for page images with absolute URLs
This commit is contained in:
commit
efc303e94f
|
@ -68,7 +68,7 @@ The SEO tag will respect any of the following if included in your site's `_confi
|
|||
publisher: 1234
|
||||
```
|
||||
|
||||
* `logo` - Relative URL to a site-wide logo (e.g., `/assets/your-company-logo.png`)
|
||||
* `logo` - URL to a site-wide logo (e.g., `/assets/your-company-logo.png`)
|
||||
* `social` - For [specifying social profiles](https://developers.google.com/structured-data/customize/social-profiles). The following properties are available:
|
||||
* `name` - If the user or organization name differs from the site's name
|
||||
* `links` - An array of links to social media profiles.
|
||||
|
@ -78,7 +78,7 @@ The SEO tag will respect the following YAML front matter if included in a post,
|
|||
|
||||
* `title` - The title of the post, page, or document
|
||||
* `description` - A short description of the page's content
|
||||
* `image` - Relative URL to an image associated with the post, page, or document (e.g., `/assets/page-pic.jpg`)
|
||||
* `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)
|
||||
|
||||
## Advanced usage
|
||||
|
|
|
@ -85,11 +85,20 @@
|
|||
{% endif %}
|
||||
|
||||
{% if site.logo %}
|
||||
{% assign seo_site_logo = site.logo | prepend: seo_url | escape %}
|
||||
{% assign seo_site_logo = site.logo %}
|
||||
{% unless seo_site_logo contains "://" %}
|
||||
{% assign seo_site_logo = seo_site_logo | prepend: seo_url %}
|
||||
{% endunless %}
|
||||
{% assign seo_site_logo = seo_site_logo | escape %}
|
||||
{% endif %}
|
||||
|
||||
{% if page.image %}
|
||||
{% assign seo_page_image = page.image.path | default: page.image.facebook | default: page.image | prepend: seo_url | escape %}
|
||||
{% assign seo_page_image = page.image.path | default: page.image.facebook |
|
||||
default: page.image %}
|
||||
{% unless seo_page_image contains "://" %}
|
||||
{% assign seo_page_image = seo_page_image | prepend: seo_url %}
|
||||
{% endunless %}
|
||||
{% assign seo_page_image = seo_page_image | escape %}
|
||||
{% endif %}
|
||||
|
||||
{% if seo_tag.title and seo_title %}
|
||||
|
|
|
@ -110,12 +110,21 @@ describe Jekyll::SeoTag do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with page.image as a string' do
|
||||
context 'with relative page.image as a string' do
|
||||
let(:page) { make_page('image' => '/img/foo.png') }
|
||||
|
||||
it 'outputs the image' do
|
||||
expected = %r{<meta property="og:image" content="http://example.invalid/img/foo.png" />}
|
||||
expect(output).to match(expected)
|
||||
expected = '<meta property="og:image" content="http://example.invalid/img/foo.png" />'
|
||||
expect(output).to include(expected)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with absolute page.image' do
|
||||
let(:page) { make_page('image' => 'http://cdn.example.invalid/img/foo.png') }
|
||||
|
||||
it 'outputs the image' do
|
||||
expected = '<meta property="og:image" content="http://cdn.example.invalid/img/foo.png" />'
|
||||
expect(output).to include(expected)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -168,6 +177,14 @@ describe Jekyll::SeoTag do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with absolute site.logo' do
|
||||
let(:site) { make_site('logo' => 'http://cdn.example.invalid/logo.png', 'url' => 'http://example.invalid') }
|
||||
|
||||
it 'outputs the logo' do
|
||||
expect(json_data['logo']).to eql('http://cdn.example.invalid/logo.png')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with site.title' do
|
||||
let(:site) { make_site('title' => 'Foo', 'url' => 'http://example.invalid') }
|
||||
|
||||
|
|
Loading…
Reference in New Issue