al-quran.reflectslight.io/Rules
2024-06-21 23:27:45 -03:00

73 lines
1.8 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Requires
require "ryo"
require "ryo/json"
require "ryo/yaml"
require "nanoc-gzip"
require "nanoc-webpack"
require "nanoc-tidy"
##
# Extensions
[Nanoc::RuleDSL::CompilationRuleContext, Nanoc::RuleDSL::CompilerDSL].each { _1.prepend(Mixin) }
Nanoc::RuleDSL::CompilationRuleContext.prepend(Nanoc::Extension::AnonymousFilter)
Nanoc::RuleDSL::CompilerDSL.prepend(Nanoc::Extension::RequireRules)
##
# Locals
locales = %w[ar fa en]
name_by_id = Ryo.from_json(path: File.join(dirs.content, "json", "nameById.json"))
tdata = Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
tidy = `which tidy || which tidy5`.chomp
buildenv = ENV["buildenv"] || "development"
##
# Plugins
Nanoc::Webpack
.default_argv
.replace([*Nanoc::Webpack.default_argv, "--config", "webpack.#{buildenv}.js"].uniq)
Nanoc::Tidy
.default_argv
.replace([*Nanoc::Tidy.default_argv, "--config", "webpack.#{buildenv}.js"].uniq)
##
# See packages/typescript/postman
compile "/css/vendor/postman.scss" do
filter :sass, syntax: :scss, style: :compact
filter :rainpress
write("/css/vendor/postman.css")
end
##
# /sitemap.xml
compile "/sitemap.xml.erb" do
filter(:erb, locals: {locales:, name_by_id:})
filter proc { _1.each_line.reject { |s| s.strip.empty? }.join }
write("/sitemap.xml")
end
##
# /robots.txt
compile "/robots.txt" do
write("/robots.txt")
end
##
# /json/durations/*/*.json
passthrough "/json/durations/*.json"
##
# Rules
require_rules "nanoc/rules/assets"
require_rules "nanoc/rules/redirect", {locales:, tidy:}
require_rules "nanoc/rules/random", {locales:, tdata:, tidy:}
require_rules "nanoc/rules/stream", {locales:, tdata:, name_by_id:, tidy:}
require_rules "nanoc/rules/index", {locales:, tdata:, tidy:}
##
# Catch-all
compile("/**/*") { write(nil) }
layout("**/*", :erb)