diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 96bb4fb66f..5709fabf81 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -780,4 +780,19 @@ def template_for file, page = true, klass = ERB template end + # Returns an excerpt of the content for usage in meta description tags + def excerpt(content) + text = content.is_a?(RDoc::Comment) ? content.text : content + + # Match from a capital letter to the first period, discarding any links, so + # that we don't end up matching badges in the README + first_paragraph_match = text.match(/[A-Z][^\.:\/]+\./) + return text[0...150].gsub(/\n/, " ").squeeze(" ") unless first_paragraph_match + + extracted_text = first_paragraph_match[0] + second_paragraph = first_paragraph_match.post_match.match(/[A-Z][^\.:\/]+\./) + extracted_text << " " << second_paragraph[0] if second_paragraph + + extracted_text[0...150].gsub(/\n/, " ").squeeze(" ") + end end diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml index 69649ad3b5..9e6fb4f94c 100644 --- a/lib/rdoc/generator/template/darkfish/_head.rhtml +++ b/lib/rdoc/generator/template/darkfish/_head.rhtml @@ -3,6 +3,28 @@