diff --git a/lib/phx_tools_web.ex b/lib/phx_tools_web.ex
index 5c1c845a4..529e54cf3 100644
--- a/lib/phx_tools_web.ex
+++ b/lib/phx_tools_web.ex
@@ -73,6 +73,7 @@ defmodule PhxToolsWeb do
use Phoenix.Component
alias PhxToolsWeb.Components.SharedComponents
+ alias PhxToolsWeb.SeoMetaTagComponent
# Import convenience functions from controllers
import Phoenix.Controller,
diff --git a/lib/phx_tools_web/components/layouts/root.html.heex b/lib/phx_tools_web/components/layouts/root.html.heex
index b7e0eef62..3f4ec7c8e 100644
--- a/lib/phx_tools_web/components/layouts/root.html.heex
+++ b/lib/phx_tools_web/components/layouts/root.html.heex
@@ -4,6 +4,7 @@
+
<.live_title>
<%= assigns[:page_title] || "PhxTools" %>
diff --git a/lib/phx_tools_web/components/seo_meta_tag_component.ex b/lib/phx_tools_web/components/seo_meta_tag_component.ex
new file mode 100644
index 000000000..efa2a543e
--- /dev/null
+++ b/lib/phx_tools_web/components/seo_meta_tag_component.ex
@@ -0,0 +1,80 @@
+defmodule PhxToolsWeb.SeoMetaTagComponent do
+ @moduledoc false
+
+ use PhxToolsWeb, :html
+
+ alias PhxToolsWeb.Endpoint
+
+ @type assigns :: map()
+ @type rendered :: rendered()
+
+ @default_description """
+ Phx.tools is a shell script for Linux and macOS that configures
+ the development environment for you in a few easy steps.
+ Once you finish running the script, you'll be able to start the database server,
+ create a new Phoenix application, and launch the server...
+ """
+
+ attr :attributes, :map
+
+ @spec seo_meta_tags(assigns()) :: rendered()
+ def seo_meta_tags(assigns) do
+ assigns =
+ assigns
+ |> assign_new(:description, fn -> String.trim(@default_description) end)
+ |> assign_new(:image_url, fn -> static_url(Endpoint, ~p"/images/phx_tools.png") end)
+ |> assign_new(:url, fn
+ %{attributes: %{url: url}} -> url
+ _assigns -> url(~p"/")
+ end)
+
+ ~H"""
+ <.open_graph_meta_tags description={@description} image_url={@image_url} url={@url} />
+ <.other_meta_tags
+ description={@description}
+ keywords="elixir, erlang, homebrew, mise, phoenix, postgres, postgresql"
+ />
+ <.twitter_meta_tags description={@description} image_url={@image_url} url={@url} />
+ """
+ end
+
+ attr :description, :string, required: true
+ attr :image_url, :string, required: true
+ attr :url, :string, required: true
+
+ defp open_graph_meta_tags(assigns) do
+ ~H"""
+
+
+
+
+
+ """
+ end
+
+ attr :description, :string, required: true
+ attr :keywords, :string, required: true
+
+ defp other_meta_tags(assigns) do
+ ~H"""
+
+
+ """
+ end
+
+ attr :description, :string, required: true
+ attr :image_url, :string, required: true
+ attr :url, :string, required: true
+
+ defp twitter_meta_tags(assigns) do
+ ~H"""
+
+
+
+
+
+
+
+ """
+ end
+end
diff --git a/lib/phx_tools_web/live/phx_tools_live/index.ex b/lib/phx_tools_web/live/phx_tools_live/index.ex
index 751618626..fc8753bf1 100644
--- a/lib/phx_tools_web/live/phx_tools_live/index.ex
+++ b/lib/phx_tools_web/live/phx_tools_live/index.ex
@@ -6,11 +6,27 @@ defmodule PhxToolsWeb.PhxToolsLive.Index do
alias PhxToolsWeb.PhxToolsLive.LandingComponent
@impl Phoenix.LiveView
- def mount(_params, session, socket), do: {:ok, assign_os(socket, session)}
+ def mount(_params, session, socket) do
+ {:ok,
+ socket
+ |> assign(:seo_attributes, %{})
+ |> assign_os(session)}
+ end
defp assign_os(socket, %{"operating_system" => operating_system}),
do: assign(socket, :operating_system, operating_system)
@impl Phoenix.LiveView
- def handle_params(_params, _uri, socket), do: {:noreply, socket}
+ def handle_params(_params, _uri, socket),
+ do: {:noreply, apply_action(socket, socket.assigns.live_action)}
+
+ defp apply_action(socket, :linux) do
+ assign(socket, seo_attributes: %{url: url(~p"/linux")})
+ end
+
+ defp apply_action(socket, :macOS) do
+ assign(socket, seo_attributes: %{url: url(~p"/macOS")})
+ end
+
+ defp apply_action(socket, _index), do: socket
end
diff --git a/priv/static/images/phx_tools.png b/priv/static/images/phx_tools.png
new file mode 100644
index 000000000..c12d222cf
Binary files /dev/null and b/priv/static/images/phx_tools.png differ
diff --git a/test/phx_tools_web/components/seo_meta_tag_component_test.exs b/test/phx_tools_web/components/seo_meta_tag_component_test.exs
new file mode 100644
index 000000000..67106c3b2
--- /dev/null
+++ b/test/phx_tools_web/components/seo_meta_tag_component_test.exs
@@ -0,0 +1,60 @@
+defmodule PhxToolsWeb.SeoMetaTagComponentTest do
+ use PhxToolsWeb.ConnCase, async: true
+
+ import Phoenix.LiveViewTest
+
+ alias PhxToolsWeb.SeoMetaTagComponent
+
+ describe "seo_meta_tags/1" do
+ test "renders meta tags with default values" do
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: nil) =~
+ ""
+ end
+
+ test "renders meta tags with the values passed" do
+ assigns = %{url: "http://sample.link"}
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: assigns) =~
+ ""
+
+ assert render_component(&SeoMetaTagComponent.seo_meta_tags/1, attributes: assigns) =~
+ ""
+ end
+ end
+end