mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 22:23:00 +08:00
FIX: use excerpt instead of the summary
This commit is contained in:
parent
dec881ac9d
commit
929ff00741
|
@ -2,7 +2,6 @@ require_dependency 'email'
|
||||||
require_dependency 'email_token'
|
require_dependency 'email_token'
|
||||||
require_dependency 'trust_level'
|
require_dependency 'trust_level'
|
||||||
require_dependency 'pbkdf2'
|
require_dependency 'pbkdf2'
|
||||||
require_dependency 'summarize'
|
|
||||||
require_dependency 'discourse'
|
require_dependency 'discourse'
|
||||||
require_dependency 'post_destroyer'
|
require_dependency 'post_destroyer'
|
||||||
require_dependency 'user_name_suggester'
|
require_dependency 'user_name_suggester'
|
||||||
|
|
|
@ -10,8 +10,8 @@ class UserProfile < ActiveRecord::Base
|
||||||
|
|
||||||
BAKED_VERSION = 1
|
BAKED_VERSION = 1
|
||||||
|
|
||||||
def bio_excerpt
|
def bio_excerpt(length=350)
|
||||||
excerpt = PrettyText.excerpt(bio_cooked, 350)
|
excerpt = PrettyText.excerpt(bio_cooked, length)
|
||||||
return excerpt if excerpt.blank? || (user.has_trust_level?(TrustLevel[1]) && !user.suspended?)
|
return excerpt if excerpt.blank? || (user.has_trust_level?(TrustLevel[1]) && !user.suspended?)
|
||||||
PrettyText.strip_links(excerpt)
|
PrettyText.strip_links(excerpt)
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@ class UserProfile < ActiveRecord::Base
|
||||||
|
|
||||||
def bio_summary
|
def bio_summary
|
||||||
return nil unless bio_cooked.present?
|
return nil unless bio_cooked.present?
|
||||||
Summarize.new(bio_cooked).summary
|
bio_excerpt(500)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recook_bio
|
def recook_bio
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
# Summarize a HTML field into regular text. Used currently
|
|
||||||
# for meta tags
|
|
||||||
|
|
||||||
require 'sanitize'
|
|
||||||
|
|
||||||
class Summarize
|
|
||||||
|
|
||||||
def initialize(text)
|
|
||||||
@text = text
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.max_length
|
|
||||||
500
|
|
||||||
end
|
|
||||||
|
|
||||||
def summary
|
|
||||||
return nil if @text.blank?
|
|
||||||
|
|
||||||
result = Sanitize.clean(@text)
|
|
||||||
result.gsub!(/\n/, ' ')
|
|
||||||
result.strip!
|
|
||||||
|
|
||||||
return result if result.length <= Summarize.max_length
|
|
||||||
"#{result[0..Summarize.max_length]}..."
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,7 +1,6 @@
|
||||||
require_dependency 'guardian'
|
require_dependency 'guardian'
|
||||||
require_dependency 'topic_query'
|
require_dependency 'topic_query'
|
||||||
require_dependency 'filter_best_posts'
|
require_dependency 'filter_best_posts'
|
||||||
require_dependency 'summarize'
|
|
||||||
require_dependency 'gaps'
|
require_dependency 'gaps'
|
||||||
|
|
||||||
class TopicView
|
class TopicView
|
||||||
|
@ -115,7 +114,7 @@ class TopicView
|
||||||
def summary
|
def summary
|
||||||
return nil if desired_post.blank?
|
return nil if desired_post.blank?
|
||||||
# TODO, this is actually quite slow, should be cached in the post table
|
# TODO, this is actually quite slow, should be cached in the post table
|
||||||
Summarize.new(desired_post.cooked).summary
|
desired_post.excerpt(500)
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_url
|
def image_url
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
require 'summarize'
|
|
||||||
|
|
||||||
describe Summarize do
|
|
||||||
|
|
||||||
it "is blank when the input is nil" do
|
|
||||||
Summarize.new(nil).summary.should be_blank
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is blank when the input is an empty string" do
|
|
||||||
Summarize.new("").summary.should be_blank
|
|
||||||
end
|
|
||||||
|
|
||||||
it "removes html tags" do
|
|
||||||
Summarize.new("hello <b>robin</b>").summary.should == "hello robin"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "removes doctype entries" do
|
|
||||||
# this is not valid html but this is just testing DOCTYPE entries
|
|
||||||
Summarize.new("<!DOCTYPE html>Discourse").summary.should == "Discourse"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "strips leading and trailing space" do
|
|
||||||
Summarize.new("\t \t hello \t ").summary.should == "hello"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "trims long strings and adds an ellipsis" do
|
|
||||||
Summarize.stubs(:max_length).returns(11)
|
|
||||||
Summarize.new("discourse is a cool forum").summary.should == "discourse is..."
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user