[Ads] Support keyword targets

Basically a redo of b61856af6d which was removed in 0842a50ad5
This commit is contained in:
Earlopain 2023-09-03 18:44:42 +02:00
parent 9203dcdb82
commit 17e9c052cd
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
8 changed files with 27 additions and 4 deletions

View File

@ -1,11 +1,15 @@
module PostSets
class Base
def tag_string
nil
""
end
def public_tag_string
nil
""
end
def ad_tag_string
""
end
def fill_tag_types(posts)

View File

@ -22,6 +22,10 @@ module PostSets
@public_tag_string ||= public_tag_array.uniq.join(" ")
end
def ad_tag_string
TagQuery.ad_tag_string(public_tag_array)
end
def humanized_tag_string
public_tag_array.slice(0, 25).join(" ").tr("_", " ")
end

View File

@ -98,6 +98,10 @@ class TagQuery
tags.select { |tag| tag_array.include?(tag) }
end
def self.ad_tag_string(tag_array)
fetch_tags(tag_array, *Danbooru.config.ads_keyword_tags).join(" ")
end
private
METATAG_SEARCH_TYPE = {

View File

@ -826,6 +826,10 @@ class Post < ApplicationRecord
TagQuery.fetch_tags(tag_array, *)
end
def ad_tag_string
TagQuery.ad_tag_string(tag_array)
end
def add_tag(tag)
set_tag_string("#{tag_string} #{tag}")
end

View File

@ -21,6 +21,8 @@
return;
el.setAttribute("data-revive-zoneid", zone.zone.toString());
el.setAttribute("data-revive-id", zone.revive_id);
// We run our own ad network. Tags are not logged anywhere, and are only used for filtering ads based on tags.
el.setAttribute("data-revive-tags", <%= raw(tag_string.to_json) %>);
var s = document.createElement('script');
s.async = true;
s.src = "//ads.dragonfru.it/www/delivery/asyncjs.php";

View File

@ -19,7 +19,7 @@
</aside>
<section id="content">
<%= render "ads/leaderboard" %>
<%= render "ads/leaderboard", tag_string: @post_set.ad_tag_string %>
<!-- TODO: Fix tag array with forced -status:deleted -->

View File

@ -72,7 +72,7 @@
<% end %>
</div>
<%= render "ads/leaderboard" %>
<%= render "ads/leaderboard", tag_string: @post.ad_tag_string %>
<%= tag.section(id: "image-container", **PostPresenter.data_attributes(@post, include_post: true)) do -%>
<div id="note-container"></div>

View File

@ -650,6 +650,11 @@ module Danbooru
false
end
# These tags will be sent to the revive server to do filtering on
def ads_keyword_tags
[]
end
def ads_zone_desktop
{zone: nil, revive_id: nil, checksum: nil}
end