diff --git a/app/helpers/wiki_pages_helper.rb b/app/helpers/wiki_pages_helper.rb index 4adc6c319..0f0d2ebaa 100644 --- a/app/helpers/wiki_pages_helper.rb +++ b/app/helpers/wiki_pages_helper.rb @@ -1,9 +1,4 @@ module WikiPagesHelper - def wiki_page_excerpt(wiki_page) - text = strip_dtext(wiki_page.body).split(/\r\n|\r|\n/).first - text.truncate(160) - end - def wiki_page_other_names_list(wiki_page) names_html = wiki_page.other_names.map {|name| link_to(name, "http://www.pixiv.net/search.php?s_mode=s_tag_full&word=#{u(name)}", :class => "wiki-other-name")} names_html.join(" ").html_safe diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index ecacb4c64..6650516f0 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -262,9 +262,13 @@ class DText end # extract the first paragraph `needle` occurs in. - def self.excerpt(dtext, needle) + def self.extract_mention(dtext, needle) dtext = dtext.gsub(/\r\n|\r|\n/, "\n") excerpt = ActionController::Base.helpers.excerpt(dtext, needle, separator: "\n\n", radius: 1, omission: "") excerpt end + + def self.excerpt(text, length: 160) + strip_dtext(text).split(/\r\n|\r|\n/).first.to_s.truncate(length) + end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 6c700cf98..7df4372b6 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -20,7 +20,7 @@ class Comment < ApplicationRecord mentionable( :message_field => :body, :title => ->(user_name) {"#{creator.name} mentioned you in a comment on post ##{post_id}"}, - :body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@" + user_name)}\n[/quote]\n"} + :body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.extract_mention(body, "@" + user_name)}\n[/quote]\n"} ) api_attributes including: [:creator_name, :updater_name] diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index d32202151..84c7cf9ed 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -32,7 +32,7 @@ class ForumPost < ApplicationRecord mentionable( :message_field => :body, :title => ->(user_name) {%{#{creator.name} mentioned you in topic ##{topic_id} (#{topic.title})}}, - :body => ->(user_name) {%{@#{creator.name} mentioned you in topic ##{topic_id} ("#{topic.title}":[/forum_topics/#{topic_id}?page=#{forum_topic_page}]):\n\n[quote]\n#{DText.excerpt(body, "@" + user_name)}\n[/quote]\n}} + :body => ->(user_name) {%{@#{creator.name} mentioned you in topic ##{topic_id} ("#{topic.title}":[/forum_topics/#{topic_id}?page=#{forum_topic_page}]):\n\n[quote]\n#{DText.extract_mention(body, "@" + user_name)}\n[/quote]\n}} ) module SearchMethods diff --git a/app/views/artists/index.html.erb b/app/views/artists/index.html.erb index c03d18fa8..b707e1def 100644 --- a/app/views/artists/index.html.erb +++ b/app/views/artists/index.html.erb @@ -1,3 +1,5 @@ +<% meta_description "Search thousands of anime & hentai artists on #{Danbooru.config.app_name}." %> +