diff --git a/config/config.exs b/config/config.exs index 6571439..3d3ab9d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -33,6 +33,10 @@ config :alchemy_pub, AlchemyPubWeb.Endpoint, config :alchemy_pub, ecto_repos: [AlchemyPub.Repo] +config :mime, :types, %{ + "image/svg+xml" => ["svg"] +} + config :alchemy_pub, :copyright, name: "AlchemyPub", url: "https://creativecommons.org/licenses/by/4.0/", diff --git a/lib/alchemy_pub_web/page_live.ex b/lib/alchemy_pub_web/page_live.ex index 6f4c72c..64a9d2b 100644 --- a/lib/alchemy_pub_web/page_live.ex +++ b/lib/alchemy_pub_web/page_live.ex @@ -41,15 +41,15 @@ defmodule AlchemyPubWeb.PageLive do @impl true def handle_params(params, uri, socket) do - uri = uri |> URI.parse() + parsed_uri = uri |> URI.parse() socket = socket |> rebuild(params) %{track_valid: track_valid} = socket.assigns Presence.update(self(), @topic, socket.id, fn map -> - Map.merge(map, %{valid: track_valid, path: uri.path, path_joined: DateTime.utc_now()}) + Map.merge(map, %{valid: track_valid, path: parsed_uri.path, path_joined: DateTime.utc_now()}) end) - {:noreply, socket} + {:noreply, socket |> assign(url: uri)} end @impl true diff --git a/lib/alchemy_pub_web/page_live.html.heex b/lib/alchemy_pub_web/page_live.html.heex index 18af22a..2d6edc7 100644 --- a/lib/alchemy_pub_web/page_live.html.heex +++ b/lib/alchemy_pub_web/page_live.html.heex @@ -18,7 +18,7 @@ name={"hero-" <> Map.get(meta, "icon", i == 0 && "home-modern" || "document")} class="size-5" /> - {raw(Map.get(meta, "title"))} + {raw(meta["title"])} <%= if Map.get(meta, "tags" , []) |> Enum.any?(fn t -> Engine.urlify(t) == @tag end) do %> <% end %> @@ -38,7 +38,7 @@ patch={"/#{date}/#{title}"} phx-click={JS.dispatch("click", to: "#menu-open")} > - {raw(Map.get(meta, "title"))} + {raw(meta["title"])} <%= if Map.get(meta, "tags" , []) |> Enum.any?(fn t -> Engine.urlify(t) == @tag end) do %> <% end %> @@ -59,7 +59,7 @@ patch={"/#{title}"} phx-click={JS.dispatch("click", to: "#menu-open")} > - {raw(Map.get(meta, "title"))} + {raw(meta["title"])} @@ -98,6 +98,15 @@ +
+
+
+
+
+
@@ -114,12 +123,12 @@ />
-
- published {Map.get(@meta, "date")} +
+ published {@meta["date"]}
{raw(@content)} diff --git a/lib/alchemy_pub_web/qr_controller.ex b/lib/alchemy_pub_web/qr_controller.ex new file mode 100644 index 0000000..57c39ce --- /dev/null +++ b/lib/alchemy_pub_web/qr_controller.ex @@ -0,0 +1,27 @@ +defmodule AlchemyPubWeb.QrController do + use AlchemyPubWeb, :controller + + alias QRCode.Render.SvgSettings + + def index(conn, %{"data" => data}) do + conn + |> put_resp_content_type("image/svg+xml") + |> send_resp(200, data |> List.wrap() |> Enum.join("/") |> qr) + end + + defp qr(s) do + svg_settings = %SvgSettings{ + background_opacity: 1, + qrcode_color: "#000000", + flatten: true, + structure: :minify + } + + {:ok, qr} = + s + |> QRCode.create() + |> QRCode.render(:svg, svg_settings) + + qr + end +end diff --git a/lib/alchemy_pub_web/router.ex b/lib/alchemy_pub_web/router.ex index 98dc0c6..1585cf8 100644 --- a/lib/alchemy_pub_web/router.ex +++ b/lib/alchemy_pub_web/router.ex @@ -24,6 +24,10 @@ defmodule AlchemyPubWeb.Router do plug(:accepts, ["xml"]) end + pipeline :svg do + plug(:accepts, ["svg"]) + end + # Other scopes may use custom stacks. # scope "/api", AlchemyPubWeb do # pipe_through :api @@ -59,6 +63,11 @@ defmodule AlchemyPubWeb.Router do get "/feed.rss", FeedController, :index end + scope "/", AlchemyPubWeb do + pipe_through(:svg) + get("/qr/*data", QrController, :index) + end + scope "/", AlchemyPubWeb do pipe_through(:browser) diff --git a/priv/pages/Deck.md b/priv/pages/Deck.md index fe9d171..f3b611f 100644 --- a/priv/pages/Deck.md +++ b/priv/pages/Deck.md @@ -1,6 +1,7 @@ --- deck: true title: LiveDeck +tags: Speaking --- Introduction