FEATURE: Allow manual excerpt to be specified anywhere in the post and override max excerpt length

This commit is contained in:
David McClure
2014-09-03 22:03:12 -07:00
parent 0513d02e23
commit d567093756
2 changed files with 13 additions and 9 deletions

View File

@ -2,6 +2,8 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
attr_reader :excerpt
SPAN_REGEX = /<\s*span[^>]*class\s*=\s*['|"]excerpt['|"][^>]*>/
def initialize(length, options=nil)
@length = length
@excerpt = ""
@ -14,10 +16,14 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
end
def self.get_excerpt(html, length, options)
me = self.new(length,options)
html ||= ''
if (html.include? 'excerpt') && (SPAN_REGEX === html)
length = html.length
end
me = self.new(length, options)
parser = Nokogiri::HTML::SAX::Parser.new(me)
catch(:done) do
parser.parse(html) unless html.nil?
parser.parse(html)
end
me.excerpt.strip!
me.excerpt