'#106' into main
| @@ -56,6 +56,12 @@ class Tag < ApplicationRecord | |||
| end | |||
| end | |||
| def self.no_deerjikist | |||
| @no_deerjikist ||= Tag.find_or_initialize_by(name: 'ニジラー情報不詳') do |tag| | |||
| tag.category = 'meta' | |||
| end | |||
| end | |||
| def self.normalise_tags tag_names, with_tagme: true | |||
| tags = tag_names.map do |name| | |||
| pf, cat = CATEGORY_PREFIXES.find { |p, _| name.start_with?(p) } || ['', nil] | |||
| @@ -68,6 +74,7 @@ class Tag < ApplicationRecord | |||
| end | |||
| end | |||
| tags << Tag.tagme if with_tagme && tags.size < 10 && tags.none?(Tag.tagme) | |||
| tags << Tag.no_deerjikist if tags.all? { |t| t.category != 'deerjikist' } | |||
| tags.uniq | |||
| end | |||
| @@ -1,9 +1,11 @@ | |||
| namespace :nico do | |||
| desc 'ニコニコ DB 同期' | |||
| task sync: :environment do | |||
| require 'json' | |||
| require 'nokogiri' | |||
| require 'open3' | |||
| require 'open-uri' | |||
| require 'nokogiri' | |||
| require 'set' | |||
| fetch_thumbnail = -> url do | |||
| html = URI.open(url, read_timeout: 60, 'User-Agent' => 'Mozilla/5.0').read | |||
| @@ -87,6 +89,9 @@ namespace :nico do | |||
| if kept_non_nico_ids.to_set != desired_non_nico_ids.to_set | |||
| desired_all_ids << Tag.bot.id | |||
| end | |||
| unless Tag.where(id: desired_all_ids).where(category: 'deerjikist').exists? | |||
| desired_all_ids << Tag.no_deerjikist.id | |||
| end | |||
| desired_all_ids.uniq! | |||
| sync_post_tags!(post, desired_all_ids) | |||