Skip to content

Commit f8e4762

Browse files
committed
Pass page title to opengraph image
1 parent fcb999b commit f8e4762

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

apps/components_guide_web/lib/components_guide_web/controllers/react_typescript_controller.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ defmodule ComponentsGuideWeb.ReactTypescriptController do
22
use ComponentsGuideWeb, :controller
33

44
def index(conn, _params) do
5-
render(conn, "index.html", article: "tips")
5+
conn
6+
|> assign(:page_title, "React and TypeScript")
7+
|> render("index.html", article: "tips")
68
end
79

810
@articles ["testing", "forms"]

apps/components_guide_web/lib/components_guide_web/templates/layout/root.html.leex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@
99
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
1010
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/RoyalIcing/tela@2d421cafc1ea99fab91aa4fcbf3b554160bcada5/tela.css"/>
1111

12-
<meta property="og:image" content="https://stamp.vercel.app/api/poster?source=Components.Guide">
12+
<%
13+
stamp_query = case assigns[:page_title] do
14+
nil ->
15+
"source=Components.Guide"
16+
17+
title ->
18+
URI.encode_query(source: "Components.Guide", headline: title)
19+
end
20+
%>
21+
<meta property="og:image" content="https://stamp.vercel.app/api/poster?<%= stamp_query %>">
1322

1423
<script defer type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
1524

1625
<!--<script type="module" src="http://localhost:3000/js/app.js"></script>-->
1726

18-
<script src="https://cdn.usefathom.com/script.js" site="LYHMLVID" defer></script>
27+
<%= if Mix.env() == :prod do %>
28+
<script src="https://cdn.usefathom.com/script.js" site="LYHMLVID" defer></script>
29+
<% end %>
1930
</head>
2031
<body>
2132
<%= render ComponentsGuideWeb.LayoutView, "_banner.html", path_info: @conn.path_info %>

0 commit comments

Comments
 (0)