Fix tag ordering in humanized_essential_tag_string.
* Pick the largest character or copyright tags by post count. Previously we picked the tags with the longest names, which was nonsensical. * Remove tag cateogory logic from config file. We can't avoid hardcoding some knowledge about tag categories here, so there's no point in trying. This affects tab titles on post show pages as well as filenames in downloaded images.
This commit is contained in:
@@ -24,11 +24,6 @@ class TagCategory
|
|||||||
@@short_name_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["short"],k]}]
|
@@short_name_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["short"],k]}]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a hash mapping for humanized_essential_tag_string (models/post.rb)
|
|
||||||
def humanized_mapping
|
|
||||||
@@humanized_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["humanized"]]}]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a hash mapping for split_tag_list_html (presenters/tag_set_presenter.rb)
|
# Returns a hash mapping for split_tag_list_html (presenters/tag_set_presenter.rb)
|
||||||
def header_mapping
|
def header_mapping
|
||||||
@@header_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["header"]]}]
|
@@header_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["header"]]}]
|
||||||
@@ -58,10 +53,6 @@ class TagCategory
|
|||||||
@@short_name_list ||= short_name_mapping.keys
|
@@short_name_list ||= short_name_mapping.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
def humanized_list
|
|
||||||
Danbooru.config.humanized_tag_category_list
|
|
||||||
end
|
|
||||||
|
|
||||||
def split_header_list
|
def split_header_list
|
||||||
Danbooru.config.split_tag_header_list
|
Danbooru.config.split_tag_header_list
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -218,46 +218,52 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module NameMethods
|
concerning :NameMethods do
|
||||||
def normalize_name(name)
|
def unqualified_name
|
||||||
name.to_s.mb_chars.downcase.strip.tr(" ", "_").to_s
|
name.gsub(/_\(.*\)\z/, "").tr("_", " ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_for_list(names)
|
class_methods do
|
||||||
names.map {|x| find_or_create_by_name(x).name}
|
def normalize_name(name)
|
||||||
end
|
name.to_s.mb_chars.downcase.strip.tr(" ", "_").to_s
|
||||||
|
|
||||||
def find_or_create_by_name(name, creator: CurrentUser.user)
|
|
||||||
name = normalize_name(name)
|
|
||||||
category = nil
|
|
||||||
|
|
||||||
if name =~ /\A(#{categories.regexp}):(.+)\Z/
|
|
||||||
category = $1
|
|
||||||
name = $2
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tag = find_by_name(name)
|
def create_for_list(names)
|
||||||
|
names.map {|x| find_or_create_by_name(x).name}
|
||||||
|
end
|
||||||
|
|
||||||
if tag
|
def find_or_create_by_name(name, creator: CurrentUser.user)
|
||||||
if category
|
name = normalize_name(name)
|
||||||
category_id = categories.value_for(category)
|
category = nil
|
||||||
|
|
||||||
# in case a category change hasn't propagated to this server yet,
|
if name =~ /\A(#{categories.regexp}):(.+)\Z/
|
||||||
# force an update the local cache. This may get overwritten in the
|
category = $1
|
||||||
# next few lines if the category is changed.
|
name = $2
|
||||||
tag.update_category_cache
|
|
||||||
|
|
||||||
if tag.editable_by?(creator)
|
|
||||||
tag.update(category: category_id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tag
|
tag = find_by_name(name)
|
||||||
else
|
|
||||||
Tag.new.tap do |t|
|
if tag
|
||||||
t.name = name
|
if category
|
||||||
t.category = categories.value_for(category)
|
category_id = categories.value_for(category)
|
||||||
t.save
|
|
||||||
|
# in case a category change hasn't propagated to this server yet,
|
||||||
|
# force an update the local cache. This may get overwritten in the
|
||||||
|
# next few lines if the category is changed.
|
||||||
|
tag.update_category_cache
|
||||||
|
|
||||||
|
if tag.editable_by?(creator)
|
||||||
|
tag.update(category: category_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tag
|
||||||
|
else
|
||||||
|
Tag.new.tap do |t|
|
||||||
|
t.name = name
|
||||||
|
t.category = categories.value_for(category)
|
||||||
|
t.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -921,7 +927,6 @@ class Tag < ApplicationRecord
|
|||||||
include CountMethods
|
include CountMethods
|
||||||
include CategoryMethods
|
include CategoryMethods
|
||||||
extend StatisticsMethods
|
extend StatisticsMethods
|
||||||
extend NameMethods
|
|
||||||
extend ParseMethods
|
extend ParseMethods
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -61,33 +61,22 @@ class TagSetPresenter < Presenter
|
|||||||
end.reject(&:blank?).join(" \n")
|
end.reject(&:blank?).join(" \n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def humanized_essential_tag_string(category_list: TagCategory.humanized_list, default: "")
|
def humanized_essential_tag_string(default: "")
|
||||||
strings = category_list.map do |category|
|
chartags = tags_for_category("character")
|
||||||
mapping = TagCategory.humanized_mapping[category]
|
characters = chartags.max_by(5, &:post_count).map(&:unqualified_name)
|
||||||
max_tags = mapping["slice"]
|
characters += ["#{chartags.size - 5} more"] if chartags.size > 5
|
||||||
regexmap = mapping["regexmap"]
|
characters = characters.to_sentence
|
||||||
formatstr = mapping["formatstr"]
|
|
||||||
excluded_tags = mapping["exclusion"]
|
|
||||||
|
|
||||||
type_tags = tags_for_category(category).map(&:name) - excluded_tags
|
copytags = tags_for_category("copyright")
|
||||||
next if type_tags.empty?
|
copyrights = copytags.max_by(1, &:post_count).map(&:unqualified_name)
|
||||||
|
copyrights += ["#{copytags.size - 1} more"] if copytags.size > 1
|
||||||
|
copyrights = copyrights.to_sentence
|
||||||
|
copyrights = "(#{copyrights})" if characters.present?
|
||||||
|
|
||||||
if max_tags > 0 && type_tags.length > max_tags
|
artists = tags_for_category("artist").map(&:name).grep_v("banned_artist").to_sentence
|
||||||
type_tags = type_tags.sort_by {|x| -x.size}.take(max_tags) + ["etc"]
|
artists = "drawn by #{artists}" if artists.present?
|
||||||
end
|
|
||||||
|
|
||||||
if regexmap != //
|
strings = "#{characters} #{copyrights} #{artists}"
|
||||||
type_tags = type_tags.map { |tag| tag.match(regexmap)[1] }
|
|
||||||
end
|
|
||||||
|
|
||||||
if category == "copyright" && tags_for_category("character").blank?
|
|
||||||
type_tags.to_sentence
|
|
||||||
else
|
|
||||||
formatstr % type_tags.to_sentence
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
strings = strings.compact.join(" ").tr("_", " ")
|
|
||||||
strings.blank? ? default : strings
|
strings.blank? ? default : strings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -247,7 +247,6 @@ module Danbooru
|
|||||||
"short" => "gen",
|
"short" => "gen",
|
||||||
"extra" => [],
|
"extra" => [],
|
||||||
"header" => %{<h1 class="general-tag-list">Tags</h1>},
|
"header" => %{<h1 class="general-tag-list">Tags</h1>},
|
||||||
"humanized" => nil,
|
|
||||||
"relatedbutton" => "General",
|
"relatedbutton" => "General",
|
||||||
"css" => {
|
"css" => {
|
||||||
"color" => "var(--general-tag-color)",
|
"color" => "var(--general-tag-color)",
|
||||||
@@ -259,12 +258,6 @@ module Danbooru
|
|||||||
"short" => "char",
|
"short" => "char",
|
||||||
"extra" => ["ch"],
|
"extra" => ["ch"],
|
||||||
"header" => %{<h2 class="character-tag-list">Characters</h2>},
|
"header" => %{<h2 class="character-tag-list">Characters</h2>},
|
||||||
"humanized" => {
|
|
||||||
"slice" => 5,
|
|
||||||
"exclusion" => [],
|
|
||||||
"regexmap" => /^(.+?)(?:_\(.+\))?$/,
|
|
||||||
"formatstr" => "%s"
|
|
||||||
},
|
|
||||||
"relatedbutton" => "Characters",
|
"relatedbutton" => "Characters",
|
||||||
"css" => {
|
"css" => {
|
||||||
"color" => "var(--character-tag-color)",
|
"color" => "var(--character-tag-color)",
|
||||||
@@ -276,12 +269,6 @@ module Danbooru
|
|||||||
"short" => "copy",
|
"short" => "copy",
|
||||||
"extra" => ["co"],
|
"extra" => ["co"],
|
||||||
"header" => %{<h2 class="copyright-tag-list">Copyrights</h2>},
|
"header" => %{<h2 class="copyright-tag-list">Copyrights</h2>},
|
||||||
"humanized" => {
|
|
||||||
"slice" => 1,
|
|
||||||
"exclusion" => [],
|
|
||||||
"regexmap" => //,
|
|
||||||
"formatstr" => "(%s)"
|
|
||||||
},
|
|
||||||
"relatedbutton" => "Copyrights",
|
"relatedbutton" => "Copyrights",
|
||||||
"css" => {
|
"css" => {
|
||||||
"color" => "var(--copyright-tag-color)",
|
"color" => "var(--copyright-tag-color)",
|
||||||
@@ -293,12 +280,6 @@ module Danbooru
|
|||||||
"short" => "art",
|
"short" => "art",
|
||||||
"extra" => [],
|
"extra" => [],
|
||||||
"header" => %{<h2 class="artist-tag-list">Artists</h2>},
|
"header" => %{<h2 class="artist-tag-list">Artists</h2>},
|
||||||
"humanized" => {
|
|
||||||
"slice" => 0,
|
|
||||||
"exclusion" => %w(banned_artist),
|
|
||||||
"regexmap" => //,
|
|
||||||
"formatstr" => "drawn by %s"
|
|
||||||
},
|
|
||||||
"relatedbutton" => "Artists",
|
"relatedbutton" => "Artists",
|
||||||
"css" => {
|
"css" => {
|
||||||
"color" => "var(--artist-tag-color)",
|
"color" => "var(--artist-tag-color)",
|
||||||
@@ -310,7 +291,6 @@ module Danbooru
|
|||||||
"short" => "meta",
|
"short" => "meta",
|
||||||
"extra" => [],
|
"extra" => [],
|
||||||
"header" => %{<h2 class="meta-tag-list">Meta</h2>},
|
"header" => %{<h2 class="meta-tag-list">Meta</h2>},
|
||||||
"humanized" => nil,
|
|
||||||
"relatedbutton" => nil,
|
"relatedbutton" => nil,
|
||||||
"css" => {
|
"css" => {
|
||||||
"color" => "var(--meta-tag-color)",
|
"color" => "var(--meta-tag-color)",
|
||||||
@@ -322,11 +302,6 @@ module Danbooru
|
|||||||
|
|
||||||
#TAG ORDERS
|
#TAG ORDERS
|
||||||
|
|
||||||
#Sets the order of the humanized essential tag string (models/post.rb)
|
|
||||||
def humanized_tag_category_list
|
|
||||||
@humanized_tag_category_list ||= ["character","copyright","artist"]
|
|
||||||
end
|
|
||||||
|
|
||||||
#Sets the order of the split tag header list (presenters/tag_set_presenter.rb)
|
#Sets the order of the split tag header list (presenters/tag_set_presenter.rb)
|
||||||
def split_tag_header_list
|
def split_tag_header_list
|
||||||
@split_tag_header_list ||= ["copyright","character","artist","general","meta"]
|
@split_tag_header_list ||= ["copyright","character","artist","general","meta"]
|
||||||
|
|||||||
Reference in New Issue
Block a user