about summary refs log tree commit diff
path: root/app/helpers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-11-16 22:57:49 -0600
committermultiple creatures <dev@multiple-creature.party>2019-11-16 22:57:49 -0600
commit46acfb7f3c6d6cc84cc6182933b055898a360d28 (patch)
treea36ed76d60c3d9cd5ea96acbeaafbac09dcf9af6 /app/helpers
parentd463ce4fe7b5f9ccc23322224506b67765af3f72 (diff)
Include all tags in normalized text. Deduplicate and move them to the front.
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/text_helper.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/app/helpers/text_helper.rb b/app/helpers/text_helper.rb
index 614158c1b..998473036 100644
--- a/app/helpers/text_helper.rb
+++ b/app/helpers/text_helper.rb
@@ -21,11 +21,18 @@ module TextHelper
     t.gsub!(/[ \t]+\n/, "\n")
     t.gsub!(/\n\n+/, "\n")
 
-    t.unaccent_via_split_map.strip
+    return t.strip.unaccent_via_split_map unless '#'.in?(t)
+
+    tags = Extractor.extract_hashtags(t).uniq
+    t.gsub!(/^(?:#[\w:._·\-]+\s*)+/, '')
+    t.gsub!(/(?:#[\w:._·\-]+\s*)+$/, '')
+
+    t.delete!('#')
+
+    "#{tags.join(' ')}\n#{t.lstrip}".strip.unaccent_via_split_map
   end
 
   def normalize_status(status, cache: true, skip_cache: true)
-    return normalize_text("#{status.spoiler_text}\n#{status.text}") unless status.local?
-    normalize_text("#{status.spoiler_text}\n#{Formatter.instance.format(status, skip_cache: skip_cache, cache: cache)}")
+    normalize_text("#{status.tags.pluck(:name).join(' ')}\n#{status.spoiler_text}\n#{status.local? ? Formatter.instance.format(status, skip_cache: skip_cache, cache: cache) : status.text}")
   end
 end