summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/assets.rake26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake
index 563dfad..e778021 100644
--- a/lib/tasks/assets.rake
+++ b/lib/tasks/assets.rake
@@ -1,7 +1,9 @@
1namespace :assets do 1namespace :assets do
2 desc "Regenerate ImageMagick variants for every image asset from its stored original -- rerun whenever a new style is added to FileAttachment::STYLES after assets already exist. Scope to one asset first with ASSET_ID=123." 2 desc "Regenerate ImageMagick variants for every image asset from its stored original -- rerun whenever a new style is added to FileAttachment::STYLES after assets already exist. Scope to one asset first with ASSET_ID=123."
3 task :regenerate_variants => :environment do 3 task :regenerate_variants => :environment do
4 scope = Asset.images 4 scope = Asset.where(upload_content_type: FileAttachment::IMAGE_CONTENT_TYPES +
5 FileAttachment::VECTOR_CONTENT_TYPES +
6 FileAttachment::RASTERIZED_CONTENT_TYPES)
5 scope = scope.where(id: ENV["ASSET_ID"]) if ENV["ASSET_ID"].present? 7 scope = scope.where(id: ENV["ASSET_ID"]) if ENV["ASSET_ID"].present?
6 8
7 scope.find_each do |asset| 9 scope.find_each do |asset|
@@ -12,8 +14,28 @@ namespace :assets do
12 next 14 next
13 end 15 end
14 16
15 asset.send(:generate_variants, original_path) 17 asset.send(:generate_all_variants, original_path)
16 puts "Regenerated variants for Asset##{asset.id} (#{asset.name})" 18 puts "Regenerated variants for Asset##{asset.id} (#{asset.name})"
17 end 19 end
18 end 20 end
21
22desc "One-shot: flag each live page's current first-by-position image as its headline"
23 task backfill_headline: :environment do
24 count = 0
25 page_ids = (Node.where.not(head_id: nil).pluck(:head_id) +
26 Node.where.not(draft_id: nil).pluck(:draft_id)).uniq
27
28 Page.where(id: page_ids).find_each do |page|
29 next if page.related_assets.where(headline: true).exists?
30
31 first_image = page.related_assets.joins(:asset).merge(Asset.images).order(:position).first
32 next unless first_image
33
34 first_image.update!(headline: true)
35 count += 1
36 end
37
38 puts "Flagged #{count} pages' current first image as headline."
39 end
40
19end 41end