Metadata/Utils: use summary as description if set
When generating OpenGraph and TwitterCard metadata for a post, the summary field will be used first if it is set to generate the post description.
This commit is contained in:
parent
257601d67d
commit
4477c6baff
3 changed files with 81 additions and 3 deletions
|
|
@ -8,8 +8,8 @@ defmodule Pleroma.Web.Metadata.Utils do
|
|||
alias Pleroma.Formatter
|
||||
alias Pleroma.HTML
|
||||
|
||||
def scrub_html_and_truncate(%{data: %{"content" => content}} = object) do
|
||||
content
|
||||
defp scrub_html_and_truncate_object_field(field, object) do
|
||||
field
|
||||
# html content comes from DB already encoded, decode first and scrub after
|
||||
|> HtmlEntities.decode()
|
||||
|> String.replace(~r/<br\s?\/?>/, " ")
|
||||
|
|
@ -19,6 +19,17 @@ defmodule Pleroma.Web.Metadata.Utils do
|
|||
|> Formatter.truncate()
|
||||
end
|
||||
|
||||
def scrub_html_and_truncate(%{data: %{"summary" => summary}} = object)
|
||||
when is_binary(summary) and summary != "" do
|
||||
summary
|
||||
|> scrub_html_and_truncate_object_field(object)
|
||||
end
|
||||
|
||||
def scrub_html_and_truncate(%{data: %{"content" => content}} = object) do
|
||||
content
|
||||
|> scrub_html_and_truncate_object_field(object)
|
||||
end
|
||||
|
||||
def scrub_html_and_truncate(content, max_length \\ 200) when is_binary(content) do
|
||||
content
|
||||
|> scrub_html
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue