Skip to content

Commit

Permalink
Merge pull request #5 from jacobherrington/jacobherrington/add-suppor…
Browse files Browse the repository at this point in the history
…t-for-og-image-alt

Add support for image alt metadata
  • Loading branch information
jaredcwhite authored Dec 18, 2021
2 parents be33a49 + edd7a44 commit eab4ecc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
{% if seo_tag.image.width %}
<meta property="og:image:width" content="{{ seo_tag.image.width }}" />
{% endif %}
{% if seo_tag.image.alt %}
<meta property="og:image:alt" content="{{ seo_tag.image.alt }}" />
{% endif %}
{% endif %}

{% if page.date %}
Expand All @@ -58,6 +61,10 @@
<meta name="twitter:card" content="summary" />
{% endif %}

{% if seo_tag.image.alt %}
<meta name="twitter:image:alt" content="{{ seo_tag.image.alt }}" />
{% endif %}

{% if seo_tag.page_title %}
<meta property="twitter:title" content="{{ seo_tag.page_title }}" />
{% endif %}
Expand Down
12 changes: 8 additions & 4 deletions spec/bridgetown_seo_tag_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,17 @@
end
end

context "when given an image height and width" do
let(:image) { { "path" => "/img/foo.png", "height" => 1, "width" => 2 } }
context "when given an image height, width, and alt text" do
let(:image) { { "path" => "/img/foo.png", "height" => 1, "width" => 2, "alt" => "foo" } }
let(:page) { make_page("image" => image) }

it "outputs an open graph image width and height" do
it "outputs an open graph image height, width, and alt text" do
expected = %r!<meta property="og:image:height" content="1" />!
expect(output).to match(expected)
expected = %r!<meta property="og:image:width" content="2" />!
expect(output).to match(expected)
expected = %r!<meta property="og:image:alt" content="foo" />!
expect(output).to match(expected)
end
end
end
Expand Down Expand Up @@ -421,11 +423,13 @@

context "with page.image" do
context "without *.twitter.card" do
let(:page) { make_page("image" => "/img/foo.png") }
let(:page) { make_page("image" => { "path" => "/img/foo.png", "alt" => "foo" }) }

it "outputs summary card with large image" do
expected = %r!<meta name="twitter:card" content="summary_large_image" />!
expect(output).to match(expected)
expected = %r!<meta name="twitter:image:alt" content="foo" />!
expect(output).to match(expected)
end
end

Expand Down

0 comments on commit eab4ecc

Please sign in to comment.