From 8745c8c9908ab21ee68e176ab085219df0d49d7b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 18:34:47 +0300 Subject: [PATCH] remove useless newlines after every tag. Make domain.com/username provide opengraph too --- lib/pleroma/web/metadata.ex | 4 +++- lib/pleroma/web/router.ex | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 8591db6b5..f8906e03f 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata do if(meta_enabled?(:opengraph), do: opengraph_tags(params), else: []) |> Enum.map(&to_tag/1) |> Enum.map(&HTML.safe_to_string/1) - |> Enum.join("\n") + |> Enum.join() end def meta_enabled?(type) do @@ -57,9 +57,11 @@ defmodule Pleroma.Web.Metadata do ] end end + defp opengraph_tags(_) do [] end + def to_tag(data) do with {name, attrs, _content = []} <- data do HTML.Tag.tag(name, attrs) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 6cf689ce2..25e866c48 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -505,7 +505,8 @@ defmodule Pleroma.Web.Router do scope "/", Fallback do get("/registration/:token", RedirectController, :registration_page) - get("/*path", RedirectController, :redirector_with_meta) + get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta) + get("/*path", RedirectController, :redirector) options("/*path", RedirectController, :empty) end @@ -514,6 +515,7 @@ end defmodule Fallback.RedirectController do use Pleroma.Web, :controller alias Pleroma.Web.Metadata + alias Pleroma.User def redirector(conn, _params) do conn @@ -521,6 +523,15 @@ defmodule Fallback.RedirectController do |> send_file(200, index_file_path()) end + def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do + with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do + redirector_with_meta(conn, %{user: user}) + else + nil -> + redirector(conn, params) + end + end + def redirector_with_meta(conn, params) do {:ok, index_content} = File.read(index_file_path()) tags = Metadata.build_tags(params)