Feature: OG Social media cards

Not Original Gangsta, but ObjectGraph

Reason: images were showing on LinkedIn, but small.
This commit is contained in:
2026-05-10 21:34:07 +01:00
parent 764585c642
commit 061787e897
13 changed files with 300 additions and 105 deletions
+14
View File
@@ -58,6 +58,20 @@ defmodule Blogex.PostTest do
assert post.published == false
end
test "preserves image from frontmatter" do
attrs = Map.put(valid_attrs(), :image, "/images/cover.png")
post = Post.build("x/2026/01-01-x.md", attrs, "<p>x</p>")
assert post.image == "/images/cover.png"
end
test "defaults image to nil when not in frontmatter" do
post = Post.build("x/2026/01-01-x.md", valid_attrs(), "<p>x</p>")
assert post.image == nil
end
end
defp valid_attrs do
+59
View File
@@ -6,6 +6,8 @@ defmodule Blogex.SEOTest do
defmodule StubBlog do
def base_path, do: "/blog/eng"
def title, do: "Engineering Blog"
def description, do: "Our engineering insights"
end
@base_url "https://example.com"
@@ -38,6 +40,63 @@ defmodule Blogex.SEOTest do
assert meta.article_published_time == "2026-06-15"
assert meta.article_tags == ["a", "b"]
end
test "includes og_image when post has an image" do
post = build(image: "/images/cover.png")
meta = SEO.meta_tags(post, @base_url, StubBlog)
assert meta.og_image == "https://example.com/images/cover.png"
end
test "og_image is nil when post has no image" do
post = build()
meta = SEO.meta_tags(post, @base_url, StubBlog)
assert meta.og_image == nil
end
test "og_image uses absolute URL with base_url prefix" do
post = build(image: "/assets/post-hero.jpg")
meta = SEO.meta_tags(post, "https://myapp.dev", StubBlog)
assert meta.og_image == "https://myapp.dev/assets/post-hero.jpg"
end
end
describe "meta_tags_for_blog/2" do
test "returns website type" do
meta = SEO.meta_tags_for_blog(StubBlog, @base_url)
assert meta.og_type == "website"
end
test "includes blog title and description" do
meta = SEO.meta_tags_for_blog(StubBlog, @base_url)
assert meta.og_title == "Engineering Blog"
assert meta.og_description == "Our engineering insights"
end
test "has no og_image for blog listing" do
meta = SEO.meta_tags_for_blog(StubBlog, @base_url)
assert meta.og_image == nil
end
test "builds correct blog URL" do
meta = SEO.meta_tags_for_blog(StubBlog, @base_url)
assert meta.og_url == "https://example.com/blog/eng"
end
test "uses summary twitter card for blog listing" do
meta = SEO.meta_tags_for_blog(StubBlog, @base_url)
assert meta.twitter_card == "summary"
end
end
describe "sitemap/2" do