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
@@ -66,4 +66,64 @@ defmodule FirehoseWeb.BlogControllerTest do
refute response =~ "post-status-banner"
end
end
describe "GET /blog/:blog_id/:slug - Open Graph meta tags" do
test "meta tags include og_title", %{conn: conn} do
response = conn |> get(~p"/blog/engineering/hello-world") |> html_response(200)
assert response =~ ~s(<meta property="og:title")
assert response =~ "Hello World"
end
test "meta tags include og_description", %{conn: conn} do
response = conn |> get(~p"/blog/engineering/hello-world") |> html_response(200)
assert response =~ ~s(<meta property="og:description")
end
test "meta tags include og_type article", %{conn: conn} do
response = conn |> get(~p"/blog/engineering/hello-world") |> html_response(200)
assert response =~ ~s(<meta property="og:type" content="article")
end
test "meta tags include twitter:card", %{conn: conn} do
response = conn |> get(~p"/blog/engineering/hello-world") |> html_response(200)
assert response =~ ~s(<meta name="twitter:card" content="summary_large_image")
end
test "meta tags include og_image when post has image", %{conn: conn} do
response = conn |> get(~p"/blog/engineering/why-firehose") |> html_response(200)
assert response =~ ~s(<meta property="og:image")
assert response =~ "firehose-logo.png"
end
test "meta tags have correct og_url", %{conn: conn} do
response = conn |> get(~p"/blog/engineering/hello-world") |> html_response(200)
assert response =~ ~s(<meta property="og:url" content="http://localhost:4002/blog/engineering/hello-world")
end
end
describe "GET /blog/:blog_id - Open Graph meta tags" do
test "meta tags include og_title for blog listing", %{conn: conn} do
response = conn |> get(~p"/blog/engineering") |> html_response(200)
assert response =~ ~s(<meta property="og:title")
end
test "meta tags have og_type website for blog listing", %{conn: conn} do
response = conn |> get(~p"/blog/engineering") |> html_response(200)
assert response =~ ~s(<meta property="og:type" content="website")
end
test "meta tags use summary twitter card for blog listing", %{conn: conn} do
response = conn |> get(~p"/blog/engineering") |> html_response(200)
assert response =~ ~s(<meta name="twitter:card" content="summary")
end
end
end
@@ -1,89 +1,44 @@
defmodule FirehoseWeb.BlogTagsTest do
use FirehoseWeb.ConnCase
defp goto_engineering_tag_page(conn, tag) do
path = "/blog/engineering/tag/#{tag}"
conn_res = get(conn, path)
body = html_response(conn_res, 200)
assert body =~ ~s(tagged "#{tag}")
assert body =~ "Engineering Blog"
body
end
defp goto_releases_tag_page(conn, tag) do
path = "/blog/releases/tag/#{tag}"
conn_res = get(conn, path)
body = html_response(conn_res, 200)
assert body =~ ~s(tagged "#{tag}")
assert body =~ "Release Notes"
body
end
describe "engineering blog tags" do
test "GET /blog/engineering/tag/:tag shows tag page with all posts", %{conn: conn} do
body = goto_engineering_tag_page(conn, "elixir")
test "GET /blog/engineering/tag/:tag shows tag page with filtered posts", %{conn: conn} do
body = conn |> get("/blog/engineering/tag/elixir") |> html_response(200)
assert body =~ ~s(tagged "elixir")
assert body =~ "Engineering Blog"
assert body =~ "Hello World"
end
test "GET /blog/engineering/tag/:tag page shows filtered posts", %{conn: conn} do
body = goto_engineering_tag_page(conn, "phoenix")
assert body =~ "Hello World"
end
test "GET /blog/engineering/tag/:tag page shows empty list for nonexistent tag", %{
conn: conn
} do
conn_res = get(conn, "/blog/engineering/tag/nonexistent-tag")
assert html_response(conn_res, 200) =~ ~s(tagged "nonexistent-tag")
test "GET /blog/engineering/tag/:tag shows empty list for nonexistent tag", %{conn: conn} do
body = conn |> get("/blog/engineering/tag/nonexistent-tag") |> html_response(200)
assert body =~ ~s(tagged "nonexistent-tag")
end
end
describe "release notes blog tags" do
test "GET /blog/releases/tag/:tag shows tag page with all posts", %{conn: conn} do
body = goto_releases_tag_page(conn, "release")
test "GET /blog/releases/tag/:tag shows tag page with filtered posts", %{conn: conn} do
body = conn |> get("/blog/releases/tag/release") |> html_response(200)
assert body =~ ~s(tagged "release")
assert body =~ "Release Notes"
assert body =~ "v0.1.0 Released"
end
test "GET /blog/releases/tag/:tag page shows filtered posts", %{conn: conn} do
conn_res = get(conn, "/blog/releases/tag/nonexistent-tag")
assert html_response(conn_res, 200) =~ ~s(tagged "nonexistent-tag")
end
end
describe "tag URL pattern" do
test "tag URLs follow pattern /blog/:blog_id/tag/:tag for engineering blog", %{conn: conn} do
# Test that the tag route exists and works correctly
conn_res1 = get(conn, "/blog/engineering/tag/elixir")
assert html_response(conn_res1, 200) =~ ~s(tagged "elixir")
conn_res2 = get(conn, "/blog/engineering/tag/phoenix")
assert html_response(conn_res2, 200) =~ ~s(tagged "phoenix")
end
test "tag URLs follow pattern /blog/:blog_id/tag/:tag for releases blog", %{conn: conn} do
# Test that the tag route exists and works correctly
conn_res = get(conn, "/blog/releases/tag/release")
assert html_response(conn_res, 200) =~ ~s(tagged "release")
end
test "nonexistent tags return 200 with empty post list", %{conn: conn} do
conn_res = get(conn, "/blog/engineering/tag/nonexistent-tag")
assert html_response(conn_res, 200)
test "GET /blog/releases/tag/:tag shows empty list for nonexistent tag", %{conn: conn} do
body = conn |> get("/blog/releases/tag/nonexistent-tag") |> html_response(200)
assert body =~ ~s(tagged "nonexistent-tag")
end
end
describe "tag page structure" do
test "tag page has proper layout and back link", %{conn: conn} do
body = goto_engineering_tag_page(conn, "elixir")
test "engineering tag page has proper layout and back link", %{conn: conn} do
body = conn |> get("/blog/engineering/tag/elixir") |> html_response(200)
assert body =~ "Engineering Blog"
assert body =~ ~s(tagged "elixir")
assert body =~ "All posts"
end
test "release tag page has proper layout and back link", %{conn: conn} do
body = goto_releases_tag_page(conn, "release")
body = conn |> get("/blog/releases/tag/release") |> html_response(200)
assert body =~ "Release Notes"
assert body =~ ~s(tagged "release")
assert body =~ "All posts"
+17 -34
View File
@@ -3,34 +3,35 @@
defmodule FirehoseWeb.BlogTest do
use FirehoseWeb.ConnCase
defp visit_engineering_page(conn, suffix \\ "") do
path = "/blog/engineering" <> suffix
defp visit_blog_page(conn, blog_id, suffix \\ "") do
path = "/blog/#{blog_id}" <> suffix
body = conn |> get(path) |> html_response(200)
assert body =~ "Engineering Blog"
assert body =~ "firehose"
body
end
defp visit_engineering_path(conn, suffix) do
path = "/blog/engineering" <> suffix
body = conn |> get(path) |> html_response(200)
assert body =~ "firehose"
body
end
describe "engineering blog (HTML)" do
test "GET /blog/engineering returns HTML index with layout", %{conn: conn} do
visit_engineering_page(conn)
body = visit_blog_page(conn, "engineering")
assert body =~ "Engineering Blog"
assert body =~ "firehose"
end
test "GET /blog/engineering/:slug returns HTML post with layout", %{conn: conn} do
body = visit_engineering_path(conn, "/hello-world")
body = visit_blog_page(conn, "engineering", "/hello-world")
assert body =~ "Hello World"
end
end
test "GET /blog/engineering/tag/:tag returns HTML tag page", %{conn: conn} do
body = visit_engineering_path(conn, "/tag/elixir")
assert body =~ ~s(tagged "elixir")
describe "release notes blog (HTML)" do
test "GET /blog/releases returns HTML index", %{conn: conn} do
body = visit_blog_page(conn, "releases")
assert body =~ "Release Notes"
assert body =~ "v0.1.0 Released"
end
test "GET /blog/releases/:slug returns HTML post", %{conn: conn} do
body = visit_blog_page(conn, "releases", "/v0-1-0")
assert body =~ "v0.1.0 Released"
end
end
@@ -58,24 +59,6 @@ defmodule FirehoseWeb.BlogTest do
end
end
describe "release notes blog (HTML)" do
test "GET /blog/releases returns HTML index", %{conn: conn} do
body = conn |> get("/blog/releases") |> html_response(200)
assert body =~ "Release Notes"
assert body =~ "v0.1.0 Released"
end
test "GET /blog/releases/:slug returns HTML post", %{conn: conn} do
body = conn |> get("/blog/releases/v0-1-0") |> html_response(200)
assert body =~ "v0.1.0 Released"
end
test "GET /blog/releases/tag/:tag returns HTML tag page", %{conn: conn} do
body = conn |> get("/blog/releases/tag/elixir") |> html_response(200)
assert body =~ ~s(tagged "elixir")
end
end
describe "engineering blog (JSON API)" do
test "GET /api/blog/engineering returns post index", %{conn: conn} do
assert %{"blog" => "engineering", "posts" => posts} =
@@ -16,6 +16,13 @@ defmodule FirehoseWeb.UserSessionControllerTest do
assert response =~ "Log in with email"
end
test "renders login page with password mode", %{conn: conn} do
response = conn |> get(~p"/users/log-in?mode=password") |> html_response(200)
assert response =~ "Log in"
assert response =~ ~p"/users/register"
assert response =~ "Log in with email"
end
test "renders login page with email filled in (sudo mode)", %{conn: conn, user: user} do
html =
conn
@@ -30,13 +37,6 @@ defmodule FirehoseWeb.UserSessionControllerTest do
assert html =~
~s(<input type="email" name="user[email]" id="login_form_magic_email" value="#{user.email}")
end
test "renders login page (email + password)", %{conn: conn} do
response = conn |> get(~p"/users/log-in?mode=password") |> html_response(200)
assert response =~ "Log in"
assert response =~ ~p"/users/register"
assert response =~ "Log in with email"
end
end
describe "GET /users/log-in/:token" do