This commit is contained in:
@@ -44,13 +44,16 @@ namespace :nico do
|
|||||||
new_tags = datum['tags'].map { |tag| "nico:#{ tag }" }.sort
|
new_tags = datum['tags'].map { |tag| "nico:#{ tag }" }.sort
|
||||||
if current_tags != new_tags
|
if current_tags != new_tags
|
||||||
post.tags.destroy(post.tags.where(name: current_tags))
|
post.tags.destroy(post.tags.where(name: current_tags))
|
||||||
|
tags_to_add = []
|
||||||
new_tags.each do |name|
|
new_tags.each do |name|
|
||||||
post.tags << Tag.find_or_initialize_by(name:) do |tag|
|
tag = Tag.find_or_initialize_by(name:) do |t|
|
||||||
tag.category = 'nico'
|
t.category = 'nico'
|
||||||
end
|
end
|
||||||
|
tags_to_add.concat([tag] + tag.linked_tags)
|
||||||
end
|
end
|
||||||
post.tags << Tag.tagme if post.tags.size < 20 && post.tags.none?(Tag.tagme)
|
tags_to_add << Tag.tagme if post.tags.size < 20
|
||||||
post.tags << Tag.bot if post.tags.none?(Tag.bot)
|
tags_to_add << Tag.bot
|
||||||
|
post.tags.concat(tags_to_add).uniq!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user