mirror of
https://github.com/foo-dogsquared/website.git
synced 2025-01-31 04:58:26 +00:00
Add concurrency into the assets generation step
This commit is contained in:
parent
2c76182993
commit
9bd0a44368
24
Rakefile
24
Rakefile
@ -1,6 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rake/clean'
|
require 'rake/clean'
|
||||||
|
require 'concurrent'
|
||||||
|
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'json'
|
require 'json'
|
||||||
@ -9,7 +10,7 @@ require 'set'
|
|||||||
require 'shellwords'
|
require 'shellwords'
|
||||||
|
|
||||||
desc 'Build the site'
|
desc 'Build the site'
|
||||||
task :build, %i[context base_url] => %i[export_avatars] do |_, args|
|
task :build, %i[context base_url] => %i[clean export_content_assets export_avatars] do |_, args|
|
||||||
args.with_defaults(context: 'production')
|
args.with_defaults(context: 'production')
|
||||||
draft_args = '--environment development --buildDrafts --buildFuture --buildExpired' unless args.context == 'production'
|
draft_args = '--environment development --buildDrafts --buildFuture --buildExpired' unless args.context == 'production'
|
||||||
base_uri_args = "-b #{args.base_url}" if args.base_url
|
base_uri_args = "-b #{args.base_url}" if args.base_url
|
||||||
@ -25,14 +26,14 @@ task :export_avatars, %i[base_dir output_dir] do |_, args|
|
|||||||
args.with_defaults(base_dir: './assets/svg/', output_dir: './static/icons')
|
args.with_defaults(base_dir: './assets/svg/', output_dir: './static/icons')
|
||||||
|
|
||||||
output_dirs = Set[]
|
output_dirs = Set[]
|
||||||
|
sizes = [ 32, 64, 128, 256, 512, 1024 ].freeze
|
||||||
|
formats = [ "avif", "webp" ].freeze
|
||||||
|
|
||||||
|
job_queue = Concurrent::ThreadPoolExecutor.new(min_threads: 5, max_threads: 10)
|
||||||
Dir.glob('avatars/**/*.svg', base: args.base_dir) do |f|
|
Dir.glob('avatars/**/*.svg', base: args.base_dir) do |f|
|
||||||
dirname = File.dirname f
|
dirname = File.dirname f
|
||||||
output_dir = %(#{args.output_dir}/#{dirname})
|
output_dir = %(#{args.output_dir}/#{dirname})
|
||||||
|
|
||||||
sizes = [ 32, 64, 128 ]
|
|
||||||
formats = [ "avif", "webp" ]
|
|
||||||
|
|
||||||
if output_dirs.add?(output_dir) then
|
if output_dirs.add?(output_dir) then
|
||||||
FileUtils.mkdir_p(output_dir, verbose: true)
|
FileUtils.mkdir_p(output_dir, verbose: true)
|
||||||
|
|
||||||
@ -49,15 +50,25 @@ task :export_avatars, %i[base_dir output_dir] do |_, args|
|
|||||||
area = "#{size}x#{size}"
|
area = "#{size}x#{size}"
|
||||||
|
|
||||||
output_file = "#{output_dir}/#{area}/#{File.basename(f, '.svg')}.#{format}"
|
output_file = "#{output_dir}/#{area}/#{File.basename(f, '.svg')}.#{format}"
|
||||||
|
Concurrent::Future.execute(executor: job_queue) do
|
||||||
sh "magick #{args.base_dir}#{f} -strip -resize #{area} -quality 30 #{output_file}"
|
sh "magick #{args.base_dir}#{f} -strip -resize #{area} -quality 30 #{output_file}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Make the fallback images.
|
# Make the fallback images.
|
||||||
formats.each do |format|
|
formats.each do |format|
|
||||||
output_file = "#{output_dir}/#{File.basename(f, '.svg')}.#{format}"
|
output_file = "#{output_dir}/#{File.basename(f, '.svg')}.#{format}"
|
||||||
|
Concurrent::Future.execute(executor: job_queue) do
|
||||||
sh "magick #{args.base_dir}#{f} -strip -resize 75% -quality 30 #{output_file}"
|
sh "magick #{args.base_dir}#{f} -strip -resize 75% -quality 30 #{output_file}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
job_queue.wait_for_termination
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Export the content assets'
|
||||||
|
task :export_content_assets do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Build the webring to be embedded with the site'
|
desc 'Build the webring to be embedded with the site'
|
||||||
@ -90,6 +101,11 @@ task :update do
|
|||||||
sh 'hugo mod get ./... && hugo mod tidy'
|
sh 'hugo mod get ./... && hugo mod tidy'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Update the flake'
|
||||||
|
task :flake_update do
|
||||||
|
sh 'nix flake update --commit-lock-file --commit-lockfile-summary "Update flake inputs"'
|
||||||
|
end
|
||||||
|
|
||||||
desc 'Clean the environment'
|
desc 'Clean the environment'
|
||||||
task :clean do
|
task :clean do
|
||||||
# Remove the generated files.
|
# Remove the generated files.
|
||||||
|
Loading…
Reference in New Issue
Block a user