Add behaviours to TwitterCard, remove some dumb stuff in Formatter.truncate
This commit is contained in:
parent
2e630bea0d
commit
9aa69e12b8
3 changed files with 14 additions and 16 deletions
|
|
@ -184,21 +184,12 @@ defmodule Pleroma.Formatter do
|
|||
end)
|
||||
end
|
||||
|
||||
def truncate(text, opts \\ []) do
|
||||
max_length = opts[:max_length] || 200
|
||||
omission = opts[:omission] || "..."
|
||||
|
||||
cond do
|
||||
not String.valid?(text) ->
|
||||
text
|
||||
|
||||
String.length(text) < max_length ->
|
||||
text
|
||||
|
||||
true ->
|
||||
length_with_omission = max_length - String.length(omission)
|
||||
|
||||
"#{String.slice(text, 0, length_with_omission)}#{omission}"
|
||||
def truncate(text, max_length \\ 200, omission \\ "...") do
|
||||
if String.length(text) < max_length do
|
||||
text
|
||||
else
|
||||
length_with_omission = max_length - String.length(omission)
|
||||
String.slice(text, 0, length_with_omission) <> omission
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue