~mlb/linkhut

e2310b5aee4d021696fb3f6a460fe9e5dad7f4bf — Matías Larre Borges 9 months ago 8995ff8
Fixes tag links in Unread view
M lib/linkhut_web/controllers/utils.ex => lib/linkhut_web/controllers/utils.ex +4 -1
@@ 95,6 95,7 @@ defmodule LinkhutWeb.Controllers.Utils do
    |> feed_route()
  end

  defp html_route(%{view: :unread, tags: t, params: p}), do: ~p"/_/unread/#{t}?#{p}"
  defp html_route(%{view: :unread, params: p}), do: ~p"/_/unread?#{p}"
  defp html_route(%{user: u, url: l, tags: t, params: p}), do: ~p"/~#{u}/-#{l}/#{t}?#{p}"
  defp html_route(%{user: u, url: l, params: p}), do: ~p"/~#{u}/-#{l}?#{p}"


@@ 105,6 106,7 @@ defmodule LinkhutWeb.Controllers.Utils do
  defp html_route(%{tags: t, params: p}), do: ~p"/#{t}?#{p}"
  defp html_route(%{params: p}), do: ~p"/?#{p}"

  defp feed_route(%{view: :unread, tags: t, params: p}), do: ~p"/_/feed/unread/#{t}?#{p}"
  defp feed_route(%{view: :unread, params: p}), do: ~p"/_/feed/unread?#{p}"
  defp feed_route(%{user: u, url: l, tags: t, params: p}), do: ~p"/_/feed/~#{u}/-#{l}/#{t}?#{p}"
  defp feed_route(%{user: u, url: l, params: p}), do: ~p"/_/feed/~#{u}/-#{l}?#{p}"


@@ 136,7 138,8 @@ defmodule LinkhutWeb.Controllers.Utils do
  defp fetch_user(%{} = scope, ["~" <> user | _]), do: Map.put(scope, :user, user)
  defp fetch_user(%{} = scope, _), do: scope

  defp fetch_tags(%{} = scope, path), do: Map.put(scope, :tags, tags_from_path(path) |> Enum.map(&URI.decode_www_form/1))
  defp fetch_tags(%{} = scope, path),
    do: Map.put(scope, :tags, tags_from_path(path) |> Enum.map(&URI.decode_www_form/1))

  defp tags_from_path(["~" <> _ | path]), do: tags_from_path(path)
  defp tags_from_path(["-" <> _ | path]), do: tags_from_path(path)

M lib/linkhut_web/plugs/feed_redirect.ex => lib/linkhut_web/plugs/feed_redirect.ex +4 -2
@@ 10,7 10,7 @@ defmodule LinkhutWeb.Plugs.FeedRedirect do
  """

  import Phoenix.Controller, only: [redirect: 2]
  alias LinkhutWeb.Router.Helpers, as: RouteHelpers
  alias LinkhutWeb.Controllers.Utils

  @doc false
  @impl true


@@ 24,7 24,9 @@ defmodule LinkhutWeb.Plugs.FeedRedirect do

  defp call(%Plug.Conn{path_info: path_segments} = conn, "feed.xml", _) do
    conn
    |> redirect(to: RouteHelpers.feed_link_path(conn, :show, List.delete_at(path_segments, -1)))
    |> redirect(
      to: Utils.feed_path(%Plug.Conn{conn | path_info: List.delete_at(path_segments, -1)})
    )
  end

  defp call(conn, _, _), do: conn

M lib/linkhut_web/router.ex => lib/linkhut_web/router.ex +6 -1
@@ 18,7 18,10 @@ defmodule LinkhutWeb.Router do

  pipeline :token_auth do
    plug LinkhutWeb.Plugs.VerifyTokenAuth
    plug ExOauth2Provider.Plug.EnsureAuthenticated, otp_app: :linkhut, handler: LinkhutWeb.Plugs.AuthErrorHandler

    plug ExOauth2Provider.Plug.EnsureAuthenticated,
      otp_app: :linkhut,
      handler: LinkhutWeb.Plugs.AuthErrorHandler
  end

  pipeline :feed do


@@ 85,6 88,7 @@ defmodule LinkhutWeb.Router do
    pipe_through [:feed, :token_auth]

    get "/", LinkController, :unread, as: :unread
    get "/*tags", LinkController, :unread, as: :unread
  end

  scope "/_/feed", LinkhutWeb, as: :feed do


@@ 186,6 190,7 @@ defmodule LinkhutWeb.Router do
  scope "/_/unread", LinkhutWeb do
    pipe_through [:browser, :ensure_auth]
    get "/", LinkController, :unread, as: :unread
    get "/*tags", LinkController, :unread, as: :unread
  end

  scope "/", LinkhutWeb do