al-quran.reflectslight.io/Rules
2024-05-02 11:29:46 -03:00

71 lines
1.5 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: true
##
# requires
require "ryo"
require "ryo/json"
require "nanoc-gzip"
require "nanoc-webpack"
require "nanoc-tidy"
##
# DSL extensions
Nanoc::RuleDSL::CompilationRuleContext.prepend(Nanoc::RuleDSL::Filter)
Nanoc::RuleDSL::CompilerDSL.prepend(Nanoc::RuleDSL::RequireRules)
##
# variables
locales = %w[ar en]
json_dir = File.join(Dir.getwd, "src", "json")
name_by_id = Ryo.from_json_file("#{json_dir}/nameById.json")
tdata = Ryo.from_json_file("#{json_dir}/t.json")
buildenv = ENV["buildenv"] || "development"
##
# plugins
Nanoc::Webpack
.default_argv
.concat ["--config", "webpack.#{buildenv}.js"]
Nanoc::Tidy
.default_argv
.concat ["-upper"]
##
# 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"
##
# require rules
require_rules "nanoc/rules/assets"
require_rules "nanoc/rules/redirect"
require_rules "nanoc/rules/random", {locales:}
require_rules "nanoc/rules/stream", {locales:, tdata:, name_by_id:}
require_rules "nanoc/rules/index", {locales:, tdata:}
##
# defaults
compile("/**/*") { write(nil) }
layout("**/*", :erb)