X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fostatus%2Fmetadata.ex;h=792b4a4bd6ab3b3513eb74842e3a36a101a4bd5a;hb=b5de7c4c4d90d1049b59381953cbd76e79b77e66;hp=dd099e2ad7dd5aad4aaef5f73e80d09e75314008;hpb=9b3a6cdb07383631c9ac11ce5de51306f6c4a464;p=akkoma diff --git a/lib/pleroma/web/ostatus/metadata.ex b/lib/pleroma/web/ostatus/metadata.ex index dd099e2ad..792b4a4bd 100644 --- a/lib/pleroma/web/ostatus/metadata.ex +++ b/lib/pleroma/web/ostatus/metadata.ex @@ -1,14 +1,10 @@ defmodule Pleroma.Web.Metadata do alias Phoenix.HTML - alias Pleroma.{Web, Formatter} - alias Pleroma.{User, Activity} + alias Pleroma.{Formatter, User} alias Pleroma.Web.MediaProxy - def build_tags(activity, user, url) do - Enum.concat([ - if(meta_enabled?(:opengraph), do: opengraph_tags(activity, user), else: []), - if(meta_enabled?(:oembed), do: oembed_links(url), else: []) - ]) + def build_tags(params) 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") @@ -19,6 +15,44 @@ defmodule Pleroma.Web.Metadata do Keyword.get(config, type, false) end + # opengraph for single status + defp opengraph_tags(%{activity: activity, user: user}) do + with truncated_content = Formatter.truncate(activity.data["object"]["content"]) do + [ + {:meta, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" + ], []}, + {:meta, [property: "og:url", content: activity.data["id"]], []}, + {:meta, [property: "og:description", content: truncated_content], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + + # opengraph for user card + defp opengraph_tags(%{user: user}) do + with truncated_bio = Formatter.truncate(user.bio) do + [ + {:meta, + [ + property: "og:title", + content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) profile" + ], []}, + {:meta, [property: "og:url", content: User.profile_url(user)], []}, + {:meta, [property: "og:description", content: truncated_bio], []}, + {:meta, [property: "og:image", content: user_avatar_url(user)], []}, + {:meta, [property: "og:image:width", content: 120], []}, + {:meta, [property: "og:image:height", content: 120], []}, + {:meta, [property: "twitter:card", content: "summary"], []} + ] + end + end + def to_tag(data) do with {name, attrs, _content = []} <- data do HTML.Tag.tag(name, attrs) @@ -31,36 +65,11 @@ defmodule Pleroma.Web.Metadata do end end - defp oembed_links(url) do - Enum.map(["xml", "json"], fn format -> - href = HTML.raw(oembed_path(url, format)) - { :link, [ type: ["application/#{format}+oembed"], href: href, rel: 'alternate'], [] } - end) - end - - defp opengraph_tags(activity, user) do - with image = User.avatar_url(user) |> MediaProxy.url(), - truncated_content = Formatter.truncate(activity.data["object"]["content"]), - domain = Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") do - [ - {:meta, - [ - property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{domain}) post ##{activity.id}" - ], []}, - {:meta, [property: "og:url", content: activity.data["id"]], []}, - {:meta, [property: "og:description", content: truncated_content], - []}, - {:meta, [property: "og:image", content: image], []}, - {:meta, [property: "og:image:width", content: 120], []}, - {:meta, [property: "og:image:height", content: 120], []}, - {:meta, [property: "twitter:card", content: "summary"], []} - ] - end + defp user_avatar_url(user) do + User.avatar_url(user) |> MediaProxy.url() end - defp oembed_path(url, format) do - query = URI.encode_query(%{url: url, format: format}) - "#{Web.base_url()}/oembed?#{query}" + def pleroma_domain do + Pleroma.Config.get([:instance, :domain], "UNKNOWN_DOMAIN") end -end \ No newline at end of file +end