Module: FetchUtil::Regulatory::TrustTxt
- Included in:
- FetchUtil::Regulatory
- Defined in:
- lib/fetch_util/regulatory/trust_txt.rb
Instance Method Summary collapse
Instance Method Details
#extract_trusttxt_signals(body) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fetch_util/regulatory/trust_txt.rb', line 17 def extract_trusttxt_signals(body) preference = nil body.to_s.gsub("\r\n", "\n").gsub("\r", "\n").each_line do |line| content = line.sub(/\s*#.*\z/, "").strip next if content.empty? key, raw_value = content.split("=", 2) next unless raw_value next unless key.to_s.strip.casecmp?("datatrainingallowed") preference = case raw_value.to_s.strip.downcase when "yes" "allow" when "no" "disallow" end end return [] unless preference [ build_signal( preference, "ai-training", path: "/*", conditions: { "label" => "datatrainingallowed" } ) ] end |
#trusttxt_record(requested_uri) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/fetch_util/regulatory/trust_txt.rb', line 6 def trusttxt_record(requested_uri) fetch_record( "trusttxt:#{origin_key(requested_uri)}", [trusttxt_uri(requested_uri), trusttxt_well_known_uri(requested_uri)], fallback: { "signals" => [] } ) do |body| signals = extract_trusttxt_signals(body) { "signals" => sort_usage_preference_signals(signals) } end end |