Feature: OG Social media cards
Not Original Gangsta, but ObjectGraph Reason: images were showing on LinkedIn, but small.
This commit is contained in:
@@ -12,6 +12,27 @@ defmodule FirehoseWeb.Layouts do
|
||||
|
||||
embed_templates "layouts/*"
|
||||
|
||||
@doc """
|
||||
Stores content in the connection for later rendering in layouts.
|
||||
|
||||
Used to inject dynamic meta tags into the `<head>` section.
|
||||
"""
|
||||
def put_content_for(conn, key, content) do
|
||||
content_for = Map.get(conn.assigns, :content_for, %{})
|
||||
new_content_for = Map.update(content_for, key, [content], &(&1 ++ [content]))
|
||||
Plug.Conn.assign(conn, :content_for, new_content_for)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Retrieves content stored via `put_content_for/3`.
|
||||
|
||||
Can be called from HEEx templates with `get_content_for(assigns, :meta_tags)`.
|
||||
"""
|
||||
def get_content_for(assigns, key) do
|
||||
content_for = assigns[:content_for]
|
||||
if is_map(content_for), do: Map.get(content_for, key, []), else: []
|
||||
end
|
||||
|
||||
@doc """
|
||||
Shows the flash group with standard titles and content.
|
||||
|
||||
|
||||
@@ -31,6 +31,16 @@
|
||||
window.addEventListener("phx:set-theme", (e) => setTheme(e.target.dataset.phxTheme));
|
||||
})();
|
||||
</script>
|
||||
<%= for meta <- get_content_for(assigns, :meta_tags) do %>
|
||||
<meta property="og:title" content={meta.og_title} />
|
||||
<meta property="og:description" content={meta.og_description} />
|
||||
<meta property="og:type" content={meta.og_type} />
|
||||
<meta property="og:url" content={meta.og_url} />
|
||||
<%= if meta.og_image do %>
|
||||
<meta property="og:image" content={meta.og_image} />
|
||||
<% end %>
|
||||
<meta name="twitter:card" content={meta.twitter_card} />
|
||||
<% end %>
|
||||
</head>
|
||||
<body>
|
||||
{@inner_content}
|
||||
|
||||
Reference in New Issue
Block a user