Add behaviours to TwitterCard, remove some dumb stuff in Formatter.truncate
[akkoma] / lib / pleroma / formatter.ex
index d80ae6576cd071b3e9b49a35a0bdb43c25d2699c..63e0acb21e29e5d923263cf797677058121ba44b 100644 (file)
@@ -183,4 +183,13 @@ defmodule Pleroma.Formatter do
       String.replace(result_text, uuid, replacement)
     end)
   end
+
+  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