diff --git a/README.md b/README.md index f713ce8..96e2042 100644 --- a/README.md +++ b/README.md @@ -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` - Relative 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: * `type` - Either `person` or `organization` (defaults to `person`) * `name` - If the user or organization name differs from the site's name @@ -79,7 +79,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` - Relative 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) ### Disabling `` output diff --git a/lib/template.html b/lib/template.html index e21d56b..45d3aae 100644 --- a/lib/template.html +++ b/lib/template.html @@ -84,7 +84,7 @@ {% endif %} {% if page.image %} - <meta property="og:image" content="{{ page.image | prepend: "/" | prepend: seo_url | escape }}" /> + <meta property="og:image" content="{{ page.image | prepend: seo_url | escape }}" /> {% endif %} {% if page.date %} @@ -118,7 +118,7 @@ <meta name="twitter:description" content="{{ seo_description }}" /> {% if page.image %} - <meta name="twitter:image" content="{{ page.image | escape }}" /> + <meta name="twitter:image" content="{{ page.image | prepend: seo_url | escape }}" /> {% endif %} {% if seo_author_twitter %} diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 1753804..880a5f8 100644 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -111,10 +111,10 @@ describe Jekyll::SeoTag do end context 'with page.image' do - let(:page) { make_page('image' => 'foo.png') } + let(:page) { make_page('image' => '/img/foo.png') } it 'outputs the image' do - expected = %r{<meta property="og:image" content="http://example.invalid/foo.png" />} + expected = %r{<meta property="og:image" content="http://example.invalid/img/foo.png" />} expect(output).to match(expected) end end @@ -247,6 +247,16 @@ describe Jekyll::SeoTag do expect(output).to match(expected) end end + + context 'with page.image' do + let(:site) { make_site('twitter' => site_twitter, 'url' => 'http://example.invalid') } + let(:page) { make_page('image' => '/img/foo.png') } + + it 'outputs the image' do + expected = %r{<meta name="twitter:image" content="http://example.invalid/img/foo.png" />} + expect(output).to match(expected) + end + end end end