2023-04-25 10:59:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-05-23 11:01:27 +00:00
|
|
|
require 'fileutils'
|
2023-04-25 10:59:34 +00:00
|
|
|
require 'json'
|
|
|
|
require 'open3'
|
|
|
|
require 'shellwords'
|
|
|
|
|
|
|
|
github_api_headers = {
|
|
|
|
'Header' => 'application/vnd.github+json',
|
|
|
|
'X-GitHub-Api-Version' => '2022-11-28'
|
|
|
|
}
|
|
|
|
github_api_headers['Authorization'] = "Token #{ENV['GITHUB_API_BEARER_TOKEN']}" if ENV['GITHUB_API_BEARER_TOKEN']
|
|
|
|
|
2023-05-02 04:22:23 +00:00
|
|
|
desc 'Build the site'
|
|
|
|
task :build, [:context, :base_url] => [:export_avatars] do |_, args|
|
2023-04-25 10:59:34 +00:00
|
|
|
args.with_defaults(context: 'production')
|
|
|
|
draft_args = '--environment development --buildDrafts --buildFuture --buildExpired' unless args.context == 'production'
|
|
|
|
base_uri_args = "-b #{args.base_url}" if args.base_url
|
|
|
|
|
|
|
|
# Unfortunately, we have to pass it inside of another Nix shell since
|
|
|
|
# Asciidoctor doesn't want to be found when executed in here for whatever
|
|
|
|
# reason.
|
|
|
|
sh "nix develop -c hugo #{draft_args} #{base_uri_args} --destination public"
|
|
|
|
end
|
|
|
|
|
2023-05-01 10:26:40 +00:00
|
|
|
desc 'Export the avatar images'
|
|
|
|
task :export_avatars, [:base_dir, :output_dir, :output_extension] do |_, args|
|
2023-05-15 05:25:45 +00:00
|
|
|
args.with_defaults(base_dir: './assets/svg/', output_dir: './static/icons/', output_extension: 'avif')
|
2023-05-01 10:26:40 +00:00
|
|
|
Dir.glob('avatars/**/*.svg', base: args.base_dir) do |f|
|
2023-05-23 11:01:27 +00:00
|
|
|
dirname = File.dirname f
|
|
|
|
output_file = "#{dirname}/#{File.basename(f, '.svg')}.#{args.output_extension}"
|
|
|
|
|
|
|
|
FileUtils.mkdir_p "#{args.output_dir}#{dirname}", verbose: true
|
2023-05-15 05:25:45 +00:00
|
|
|
sh "magick #{args.base_dir}#{f} -quality 30 #{args.output_dir}#{output_file}"
|
2023-05-01 10:26:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-25 10:59:34 +00:00
|
|
|
desc 'Build the webring to be embedded with the site'
|
|
|
|
task :build_webring, [:limit, :input, :output, :file] do |_, args|
|
|
|
|
args.with_defaults(
|
|
|
|
limit: 5,
|
|
|
|
file: './data/blogs.json',
|
|
|
|
input: './assets/templates/openring-input.html',
|
|
|
|
output: './layouts/partials/openring.html'
|
|
|
|
)
|
|
|
|
|
|
|
|
File.open args.file do |f|
|
|
|
|
feeds = JSON.parse(f.read).sample(args.limit)
|
|
|
|
feeds.map! { |feed| "-s #{Shellwords.escape(feed)}" }
|
|
|
|
|
|
|
|
command = ['openring', '-n', args.limit.to_s]
|
|
|
|
command.append(*feeds)
|
|
|
|
|
|
|
|
Open3.pipeline command.join(' '), in: args.input, out: args.output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Create a web server'
|
2023-05-23 11:01:27 +00:00
|
|
|
task :serve => [:export_avatars] do
|
2023-04-25 10:59:34 +00:00
|
|
|
sh 'nix develop -c hugo serve --buildFuture --verboseLog --destination public'
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Update the Hugo modules for this project'
|
|
|
|
task :update do
|
|
|
|
sh 'hugo mod get ./... && hugo mod tidy'
|
|
|
|
end
|