add tags to post file urls
This commit is contained in:
@@ -99,17 +99,31 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_url
|
def file_url
|
||||||
"/data/#{file_path_prefix}#{md5}.#{file_ext}"
|
if Danbooru.config.enable_seo_post_urls
|
||||||
|
# the seo tags should be stripped out by nginx
|
||||||
|
"/data/--#{seo_tags}--#{file_path_prefix}#{md5}.#{file_ext}"
|
||||||
|
else
|
||||||
|
"/data/#{file_path_prefix}#{md5}.#{file_ext}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def large_file_url
|
def large_file_url
|
||||||
if has_large?
|
if has_large?
|
||||||
"/data/sample/#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}"
|
if Danbooru.config.enable_seo_post_urls
|
||||||
|
# the seo tags should be stripped out by nginx
|
||||||
|
"/data/sample/--#{seo_tags}--#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}"
|
||||||
|
else
|
||||||
|
"/data/sample/#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
file_url
|
file_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def seo_tags
|
||||||
|
@seo_tags ||= humanized_essential_tag_string.gsub(/[^a-z0-9]+/, "-").gsub(/(^-+)|(-+$)/, "")
|
||||||
|
end
|
||||||
|
|
||||||
def preview_file_url
|
def preview_file_url
|
||||||
if !has_preview?
|
if !has_preview?
|
||||||
return "/images/download-preview.png"
|
return "/images/download-preview.png"
|
||||||
@@ -778,26 +792,37 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def essential_tag_string
|
def humanized_essential_tag_string
|
||||||
tag_array.each do |tag|
|
@humanized_essential_tag_string ||= begin
|
||||||
if tag_categories[tag] == Danbooru.config.tag_category_mapping["copyright"]
|
string = []
|
||||||
return tag
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tag_array.each do |tag|
|
if character_tags.any?
|
||||||
if tag_categories[tag] == Danbooru.config.tag_category_mapping["character"]
|
chartags = character_tags.slice(0, 5)
|
||||||
return tag
|
if character_tags.length > 5
|
||||||
|
chartags << "others"
|
||||||
|
end
|
||||||
|
chartags = chartags.map do |tag|
|
||||||
|
tag.match(/^(.+?)(?:_\(.+\))?$/)[1]
|
||||||
|
end
|
||||||
|
string << chartags.to_sentence
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
tag_array.each do |tag|
|
if copyright_tags.any?
|
||||||
if tag_categories[tag] == Danbooru.config.tag_category_mapping["artist"]
|
copytags = copyright_tags.slice(0, 5)
|
||||||
return tag
|
if copyright_tags.length > 5
|
||||||
|
copytags << "others"
|
||||||
|
end
|
||||||
|
copytags = copytags.to_sentence
|
||||||
|
string << (character_tags.any? ? "(#{copytags})" : copytags)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return tag_array.first
|
if artist_tags_excluding_hidden.any?
|
||||||
|
string << "drawn by"
|
||||||
|
string << artist_tags_excluding_hidden.to_sentence
|
||||||
|
end
|
||||||
|
|
||||||
|
string.empty? ? "##{id}" : string.join(" ").tr("_", " ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_string_copyright
|
def tag_string_copyright
|
||||||
|
|||||||
@@ -104,34 +104,7 @@ class PostPresenter < Presenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def humanized_essential_tag_string
|
def humanized_essential_tag_string
|
||||||
string = []
|
@post.humanized_essential_tag_string
|
||||||
|
|
||||||
if @post.character_tags.any?
|
|
||||||
chartags = @post.character_tags.slice(0, 5)
|
|
||||||
if @post.character_tags.length > 5
|
|
||||||
chartags << "others"
|
|
||||||
end
|
|
||||||
chartags = chartags.map do |tag|
|
|
||||||
tag.match(/^(.+?)(?:_\(.+\))?$/)[1]
|
|
||||||
end
|
|
||||||
string << chartags.to_sentence
|
|
||||||
end
|
|
||||||
|
|
||||||
if @post.copyright_tags.any?
|
|
||||||
copytags = @post.copyright_tags.slice(0, 5)
|
|
||||||
if @post.copyright_tags.length > 5
|
|
||||||
copytags << "others"
|
|
||||||
end
|
|
||||||
copytags = copytags.to_sentence
|
|
||||||
string << (@post.character_tags.any? ? "(#{copytags})" : copytags)
|
|
||||||
end
|
|
||||||
|
|
||||||
if @post.artist_tags_excluding_hidden.any?
|
|
||||||
string << "drawn by"
|
|
||||||
string << @post.artist_tags_excluding_hidden.to_sentence
|
|
||||||
end
|
|
||||||
|
|
||||||
string.empty? ? "##{@post.id}" : string.join(" ").tr("_", " ")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def categorized_tag_string
|
def categorized_tag_string
|
||||||
|
|||||||
@@ -396,6 +396,10 @@ module Danbooru
|
|||||||
def addthis_key
|
def addthis_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enable_seo_post_urls
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
# enable some (donmai-specific) optimizations for post counts
|
# enable some (donmai-specific) optimizations for post counts
|
||||||
def estimate_post_counts
|
def estimate_post_counts
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in New Issue
Block a user