al-quran.reflectslight.io/Rules

80 lines
1.7 KiB
Text
Raw Normal View History

2022-10-31 19:32:08 +01:00
#!/usr/bin/env ruby
# frozen_string_literal: true
2023-03-11 13:31:37 +01:00
require "ryo"
require "nanoc-gunzip"
require "nanoc-webpack"
2022-10-31 19:32:08 +01:00
locales = %w[ar en]
surah_id_to_name = Ryo.from(
JSON.parse(
File.read(File.join(Dir.getwd, "src", "slugs.json"))
)
)
i18n = Ryo.from(
JSON.parse(
File.read(File.join(Dir.getwd, "src", "i18n.json"))
)
)
2022-10-31 19:32:08 +01:00
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
2022-10-31 19:32:08 +01:00
##
# Require rules
require_rules "rules/assets"
2023-03-10 09:49:48 +01:00
require_rules "rules/pages/surah/redirect"
require_rules "rules/pages/surah/stream", {locales:, i18n:, surah_id_to_name:}
require_rules "rules/pages/surah/index", {locales:, i18n:}
require_rules "rules/pages/surah/random", {locales:, i18n:,surah_id_to_name:}
require_rules "rules/pages/surah/id_redirect", {locales:, i18n:,surah_id_to_name:}
2022-10-31 19:32:08 +01:00
##
2023-03-11 14:45:12 +01:00
# Inline CSS / JSON rules
compile "/i18n.json" do
filter(:minify_json)
write(nil)
end
compile "/surahs.json" do
filter(:minify_json)
write(nil)
end
compile "/slugs.json" do
filter(:minify_json)
write(nil)
end
2023-03-11 14:45:12 +01:00
compile "/css/webpackage.scss" do
filter :sass, syntax: :scss, style: :compact
filter :rainpress
write(nil)
end
2023-03-11 17:11:10 +01:00
##
# /sitemap.xml
compile "/sitemap.xml.erb" do
filter(:erb, locals: {locales:, surah_id_to_name:})
filter(:strip)
write("/sitemap.xml")
end
2022-10-31 19:32:08 +01:00
##
# Defaults
2022-10-31 19:32:08 +01:00
compile("/**/*") { write(nil) }
2022-11-02 04:49:43 +01:00
layout("**/*", :erb)