aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/formatter.ex
diff options
context:
space:
mode:
authorraeno <just.raeno@gmail.com>2018-12-10 23:08:02 +0400
committerraeno <just.raeno@gmail.com>2018-12-13 22:17:53 +0100
commit8902942128e3aee814c215d700e2eaee21b491e9 (patch)
treed7a4cacd3d91a89550589e46ea2faefbf8f5e491 /lib/pleroma/formatter.ex
parent21afdf6d9966265de95df860d90d250c76bdbe08 (diff)
downloadpleroma-8902942128e3aee814c215d700e2eaee21b491e9.tar.gz
WIP. Implement oembed route and handle both json/xml for "Note" type activity
Diffstat (limited to 'lib/pleroma/formatter.ex')
-rw-r--r--lib/pleroma/formatter.ex16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 133683794..b63f592fb 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -163,4 +163,20 @@ defmodule Pleroma.Formatter do
String.replace(result_text, uuid, replacement)
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}"
+ end
+ end
end