109 lines
2.4 KiB
Ruby
109 lines
2.4 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_SLUG = Ryo.from(
|
|
JSON.parse(
|
|
File.read(File.join(Dir.getwd, "src", "slugs.json"))
|
|
)
|
|
)
|
|
|
|
##
|
|
# Root path (/)
|
|
# Redirects to a random surah no
|
|
compile "/html/redirect-to-random-surah.html.erb" do
|
|
filter(:erb)
|
|
write("/index.html")
|
|
end
|
|
|
|
##
|
|
# /<locale>/<surahno>/surah.json
|
|
# Provides the JSON for a given surah no
|
|
compile "/*/*/surah.json" do
|
|
write(item.identifier.to_s)
|
|
if File.size(item.raw_filename) > (1024 * 10)
|
|
filter :gzip_text
|
|
write("#{item.identifier}.gz")
|
|
end
|
|
end
|
|
|
|
##
|
|
# /<locale>/<surahno>/index.html
|
|
# Redirects to a slug URL (eg /en/al-fatihah/)
|
|
compile "/html/redirect-to-surah-slug.html.erb" do
|
|
filter(:erb)
|
|
1.upto(114) do |surahno|
|
|
LOCALES.each { write(File.join("/", _1, surahno.to_s, "index.html")) }
|
|
end
|
|
end
|
|
|
|
##
|
|
# /<locale>/surah_slug>/index.html
|
|
# For reading a given surah
|
|
Ryo.each(SURAH_ID_TO_SLUG) do |surah_id, slug|
|
|
LOCALES.each do |locale|
|
|
compile "/html/TheSurahPage.html.erb", rep: "/#{locale}/#{slug}/index.html" do
|
|
filter :erb, locals: {locale: locale, surah_id: surah_id}
|
|
write "/#{locale}/#{slug}/index.html"
|
|
end
|
|
end
|
|
end
|
|
|
|
##
|
|
# /js/pages/surah.js
|
|
compile "/js/pages/TheSurahPage.tsx" do
|
|
filter :webpack, depend_on: "/js/{lib,components,hooks}/**/*.{ts,tsx,js}"
|
|
write "/js/pages/surah.js"
|
|
filter :gzip_text
|
|
write "/js/pages/surah.js.gz"
|
|
end
|
|
|
|
compile "/js/pages/TheSurahPage/package.ts" do
|
|
filter :webpack
|
|
write "/js/pages/TheSurahPage/package.js"
|
|
end
|
|
|
|
##
|
|
# /js/pages/redirect-to-random-surah.js
|
|
compile "/js/pages/redirect-to-random-surah.ts" do
|
|
filter :webpack
|
|
write "/js/pages/redirect-to-random-surah.js"
|
|
end
|
|
|
|
##
|
|
# /js/pages/redirect-to-surah-slug.js
|
|
compile "/js/pages/redirect-to-surah-slug.ts" do
|
|
filter :webpack
|
|
write "/js/pages/redirect-to-surah-slug.js"
|
|
end
|
|
|
|
##
|
|
# CSS
|
|
compile("/css/_*.scss") { write(nil) }
|
|
compile "/css/*.scss" do
|
|
filter :sass, syntax: :scss, style: :compact
|
|
filter :rainpress
|
|
write item.identifier.without_ext + ".css"
|
|
end
|
|
|
|
##
|
|
# Fonts
|
|
compile "/fonts/*" do
|
|
write(item.identifier.to_s)
|
|
filter :gzip_binary
|
|
write("#{item.identifier}.gz")
|
|
end
|
|
|
|
##
|
|
# Images
|
|
compile "/images/*.svg" do
|
|
write(item.identifier.to_s)
|
|
filter :gzip_binary
|
|
write("#{item.identifier}.gz")
|
|
end
|
|
|
|
compile("/**/*") { write(nil) }
|
|
layout("**/*", :erb)
|