al-quran.reflectslight.io/Rules
2023-03-10 07:48:47 -03:00

42 lines
1.1 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: true
require "ryo"
require "nanoc-gunzip"
require "nanoc-webpack"
locales = %w[ar en]
surah_id_to_name = Ryo.from(
JSON.parse(
File.read(File.join(Dir.getwd, "src", "slugs.json"))
)
)
def require_rules(rules, locals = {}, target = binding)
locals.each { target.local_variable_set(_1, _2) }
path = File.join(Dir.getwd, rules)
target.eval(
if File.readable?(path)
File.read(path)
elsif File.readable?("#{path}.rb")
File.read("#{path}.rb")
elsif File.readable?("#{path}.rules")
File.read("#{path}.rules")
else
raise LoadError, "#{path} is not readable"
end
)
end
##
# Require rules
require_rules "rules/assets"
require_rules "rules/pages/surah/random", {locales:, surah_id_to_name:}
require_rules "rules/pages/surah/stream", {locales:, surah_id_to_name:}
require_rules "rules/pages/surah/index", {locales:}
require_rules "rules/pages/surah/redirect"
require_rules "rules/pages/surah/id_redirect", {locales:}
##
# Defaults
compile("/**/*") { write(nil) }
layout("**/*", :erb)