mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
setting to exclude rel nofollow from particular domains
This commit is contained in:
parent
80929ead4b
commit
f68f59c24f
4 changed files with 17 additions and 3 deletions
|
@ -30,8 +30,6 @@ class SiteSetting < ActiveRecord::Base
|
|||
client_setting(:max_topic_title_length, 255)
|
||||
client_setting(:flush_timings_secs, 5)
|
||||
|
||||
|
||||
|
||||
# settings only available server side
|
||||
setting(:auto_track_topics_after, 60000)
|
||||
setting(:long_polling_interval, 15000)
|
||||
|
@ -92,6 +90,7 @@ class SiteSetting < ActiveRecord::Base
|
|||
setting(:allow_duplicate_topic_titles, false)
|
||||
|
||||
setting(:add_rel_nofollow_to_user_content, true)
|
||||
setting(:exclude_rel_nofollow_domains, '')
|
||||
setting(:post_excerpt_maxlength, 300)
|
||||
setting(:post_onebox_maxlength, 500)
|
||||
setting(:best_of_score_threshold, 15)
|
||||
|
|
|
@ -220,6 +220,7 @@ en:
|
|||
category_featured_topics: "number of topics displayed in the category list"
|
||||
popup_delay: "Length of time in ms before popups appear on the screen"
|
||||
add_rel_nofollow_to_user_content: "Add rel nofollow to all submitted user content, except for internal links (including parent domains) changing this requires you update all your baked markdown"
|
||||
exclude_rel_nofollow_domains: "A comma delimited list of domains where nofollow is not added (tld.com will automatically allow sub.tld.com as well)"
|
||||
post_excerpt_maxlength: "Maximum length in chars of a post's excerpt."
|
||||
post_onebox_maxlength: "Maximum length of a oneboxed discourse post."
|
||||
category_post_template: "The post template that appears once you create a category"
|
||||
|
|
|
@ -180,6 +180,11 @@ module PrettyText
|
|||
end
|
||||
|
||||
def self.add_rel_nofollow_to_user_content(html)
|
||||
whitelist = []
|
||||
l = SiteSetting.exclude_rel_nofollow_domains
|
||||
if l.present?
|
||||
whitelist = l.split(",")
|
||||
end
|
||||
site_uri = nil
|
||||
doc = Nokogiri::HTML.fragment(html)
|
||||
doc.css("a").each do |l|
|
||||
|
@ -188,7 +193,7 @@ module PrettyText
|
|||
uri = URI(href)
|
||||
site_uri ||= URI(Discourse.base_url)
|
||||
|
||||
if !uri.host.present? || uri.host.ends_with?(site_uri.host)
|
||||
if !uri.host.present? || uri.host.ends_with?(site_uri.host) || whitelist.any?{|u| uri.host.ends_with?(u)}
|
||||
# we are good no need for nofollow
|
||||
else
|
||||
l["rel"] = "nofollow"
|
||||
|
|
|
@ -79,6 +79,7 @@ test
|
|||
describe "rel nofollow" do
|
||||
before do
|
||||
SiteSetting.stubs(:add_rel_nofollow_to_user_content).returns(true)
|
||||
SiteSetting.stubs(:exclude_rel_nofollow_domains).returns("foo.com,bar.com")
|
||||
end
|
||||
|
||||
it "should inject nofollow in all user provided links" do
|
||||
|
@ -92,6 +93,14 @@ test
|
|||
it "should not inject nofollow in all subdomain links" do
|
||||
(PrettyText.cook("<a href='#{Discourse.base_url.sub('http://', 'http://bla.')}/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
end
|
||||
|
||||
it "should not inject nofollow for foo.com" do
|
||||
(PrettyText.cook("<a href='http://foo.com/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
end
|
||||
|
||||
it "should not inject nofollow for bar.foo.com" do
|
||||
(PrettyText.cook("<a href='http://bar.foo.com/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "Excerpt" do
|
||||
|
|
Loading…
Reference in a new issue