al-quran.reflectslight.io/Rules
0x1eef a2fc33bb7c Remove redirect from /en/1/ to /en/al-fatihah/
Rather than redirect /en/1/ to /en/al-fatihah/, render the surah
stream instead. A canonical `link` tag is included for the benefit
of search engines to differentiate between duplicates.

Preference is given to /en/al-fatihah/ over /en/1/.
2023-10-06 00:06:25 -03:00

89 lines
1.7 KiB
Ruby

#!/usr/bin/env ruby
# frozen_string_literal: true
require "ryo"
require "nanoc-gzip"
require "nanoc-webpack"
locales = %w[ar en]
slugs = 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"))
)
)
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
##
# 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
compile "/reciters.json" do
filter(:minify_json)
write(nil)
end
compile "/css/postman.scss" do
filter :sass, syntax: :scss, style: :compact
filter :rainpress
write("/css/postman.css")
end
##
# /sitemap.xml
compile "/sitemap.xml.erb" do
filter(:erb, locals: {locales:, slugs:})
filter(:strip)
write("/sitemap.xml")
end
##
# /robots.txt
compile "/robots.txt" do
write("/robots.txt")
end
##
# Require rules
require_rules "nanoc/rules/assets"
require_rules "nanoc/rules/pages/surah/redirect"
require_rules "nanoc/rules/pages/surah/stream", {locales:, i18n:, slugs:}
require_rules "nanoc/rules/pages/surah/index", {locales:, i18n:}
require_rules "nanoc/rules/pages/surah/random", {locales:, i18n:, slugs:}
##
# Defaults
compile("/**/*") { write(nil) }
layout("**/*", :erb)