summaryrefslogtreecommitdiff
path: root/lib/rdoc/generator/darkfish.rb
diff options
context:
space:
mode:
authorVinicius Stock <[email protected]>2024-10-15 18:59:29 -0400
committergit <[email protected]>2024-10-15 22:59:33 +0000
commited993b5bcc4fcae661dd022d3211dcc770425218 (patch)
treeea1540ae474a2a1c18f1ca7fdce66ff48873109e /lib/rdoc/generator/darkfish.rb
parentf45eb3dcb9c7d849064cb802953f37e1cf9f3996 (diff)
[ruby/rdoc] Generate meta tags based on page's content
(https://github.com/ruby/rdoc/pull/1091) https://github.com/ruby/rdoc/commit/716bc16a7d
Diffstat (limited to 'lib/rdoc/generator/darkfish.rb')
-rw-r--r--lib/rdoc/generator/darkfish.rb15
1 files changed, 15 insertions, 0 deletions
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 @@ class RDoc::Generator::Darkfish
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