File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ class Pipeline
3131 autoload :TableOfContentsFilter , 'html/pipeline/toc_filter'
3232 autoload :SVGTeX , 'html/pipeline/svgtex'
3333 autoload :SyntaxHighlightFilter , 'html/pipeline/syntax_highlight_filter'
34+ autoload :NoFollowLinksFilter , 'html/pipeline/no_follow_links_filter'
3435 autoload :RelativeLinksFilter , 'html/pipeline/relative_links_filter'
3536 autoload :CustomLinksFilter , 'html/pipeline/custom_links_filter'
3637 autoload :SanitizationFilter , 'html/pipeline/sanitization_filter'
Original file line number Diff line number Diff line change 1- # encoding: utf-8
21module HTML
32 class Pipeline
43
@@ -8,20 +7,21 @@ class LinuxFr
87 toc_header : "<h2 class=\" sommaire\" >Sommaire</h2>\n " ,
98 svgtex_url : "http://localhost:16000" ,
109 host : "linuxfr.org"
11- }
10+ } . freeze
1211
13- def self . render ( text )
12+ def self . render ( text , context = { } )
1413 pipeline = HTML ::Pipeline . new [
1514 HTML ::Pipeline ::SVGTeX ::PreFilter ,
1615 HTML ::Pipeline ::MarkdownFilter ,
1716 HTML ::Pipeline ::SanitizationFilter ,
1817 HTML ::Pipeline ::TableOfContentsFilter ,
1918 HTML ::Pipeline ::SVGTeX ::PostFilter ,
2019 HTML ::Pipeline ::SyntaxHighlightFilter ,
20+ HTML ::Pipeline ::NoFollowLinksFilter ,
2121 HTML ::Pipeline ::RelativeLinksFilter ,
2222 HTML ::Pipeline ::CustomLinksFilter ,
2323 ] , CONTEXT
24- result = pipeline . call text
24+ result = pipeline . call text , context
2525 result [ :output ] . to_s
2626 end
2727
Original file line number Diff line number Diff line change 1+ module HTML
2+ class Pipeline
3+
4+ # Add rel="nofollow" to <a> links if enabled in the context to avoid giving
5+ # SEO juice to potential spam links.
6+ class NoFollowLinksFilter < Filter
7+
8+ def call
9+ return doc unless context [ :nofollow ]
10+
11+ doc . css ( "a[href]" ) . each do |element |
12+ element [ 'rel' ] = 'nofollow'
13+ end
14+ doc
15+ end
16+
17+ end
18+
19+ end
20+ end
You can’t perform that action at this time.
0 commit comments