diff --git a/Rules b/Rules index d97ac2b21..547f1873d 100644 --- a/Rules +++ b/Rules @@ -1,16 +1,16 @@ #!/usr/bin/env ruby # frozen_string_literal: true +require "ryo" LOCALES = %w[ar en] +SURAH_ID_TO_SLUG = Ryo.from( + JSON.parse( + File.read(File.join(Dir.getwd, "src", "slugs.json")) + ) +) ## -# ///index.html -compile "/surah.html" do - 1.upto(114) do |surahno| - LOCALES.each { write(File.join("/", _1, surahno.to_s, "index.html")) } - end -end - +# Root path (/) compile "/index.html" do write("/index.html") end @@ -21,6 +21,26 @@ end LOCALES.each { passthrough "/#{_1}/#{surahno}/surah.json" } end +## +# ///index.html +compile "/slug_redirect.html.erb" do + filter :erb + 1.upto(114) do |surahno| + LOCALES.each { write(File.join("/", _1, surahno.to_s, "index.html")) } + end +end + +## +# //surah_slug>/index.html +Ryo.each(SURAH_ID_TO_SLUG) do |surah_id, slug| + LOCALES.each do |locale| + compile "/surah.html", rep: "#{locale}/#{slug}" 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 diff --git a/src/js/pages/TheSurahPage.tsx b/src/js/pages/TheSurahPage.tsx index f81b94aeb..e2b6c21f9 100644 --- a/src/js/pages/TheSurahPage.tsx +++ b/src/js/pages/TheSurahPage.tsx @@ -54,6 +54,8 @@ function TheSurahPage ({ locale, surahId }: PageProps) { ); } -const [locale, surahId] = location.pathname.split('/').filter((e) => e); -const root = ReactDOM.createRoot(document.querySelector('.surah')); -root.render(); +const el = document.querySelector('.surah'); +const locale = el.getAttribute('data-locale'); +const surahId = parseInt(el.getAttribute('data-surah-id')); +const root = ReactDOM.createRoot(el); +root.render(); diff --git a/src/slug_redirect.html.erb b/src/slug_redirect.html.erb new file mode 100644 index 000000000..e0500f2c5 --- /dev/null +++ b/src/slug_redirect.html.erb @@ -0,0 +1,24 @@ + + + + + + + + + + diff --git a/src/slugs.json b/src/slugs.json new file mode 100644 index 000000000..184064f60 --- /dev/null +++ b/src/slugs.json @@ -0,0 +1 @@ +{"1":"al-fatihah","2":"al-baqarah","3":"ali-imran","4":"an-nisa","5":"al-maidah","6":"al-anam","7":"al-araf","8":"al-anfal","9":"at-tawbah","10":"yunus","11":"hud","12":"yusuf","13":"ar-rad","14":"ibrahim","15":"al-hijr","16":"an-nahl","17":"al-isra","18":"al-kahf","19":"maryam","20":"taha","21":"al-anbya","22":"al-hajj","23":"al-muminun","24":"an-nur","25":"al-furqan","26":"ash-shuara","27":"an-naml","28":"al-qasas","29":"al-ankabut","30":"ar-rum","31":"luqman","32":"as-sajdah","33":"al-ahzab","34":"saba","35":"fatir","36":"ya-sin","37":"as-saffat","38":"sad","39":"az-zumar","40":"ghafir","41":"fussilat","42":"ash-shuraa","43":"az-zukhruf","44":"ad-dukhan","45":"al-jathiyah","46":"al-ahqaf","47":"muhammad","48":"al-fath","49":"al-hujurat","50":"qaf","51":"adh-dhariyat","52":"at-tur","53":"an-najm","54":"al-qamar","55":"ar-rahman","56":"al-waqiah","57":"al-hadid","58":"al-mujadila","59":"al-hashr","60":"al-mumtahanah","61":"as-saf","62":"al-jumuah","63":"al-munafiqun","64":"at-taghabun","65":"at-talaq","66":"at-tahrim","67":"al-mulk","68":"al-qalam","69":"al-haqqah","70":"al-maarij","71":"nuh","72":"al-jinn","73":"al-muzzammil","74":"al-muddaththir","75":"al-qiyamah","76":"al-insan","77":"al-mursalat","78":"an-naba","79":"an-naziat","80":"abasa","81":"at-takwir","82":"al-infitar","83":"al-mutaffifin","84":"al-inshiqaq","85":"al-buruj","86":"at-tariq","87":"al-ala","88":"al-ghashiyah","89":"al-fajr","90":"al-balad","91":"ash-shams","92":"al-layl","93":"ad-duhaa","94":"ash-sharh","95":"at-tin","96":"al-alaq","97":"al-qadr","98":"al-bayyinah","99":"az-zalzalah","100":"al-adiyat","101":"al-qariah","102":"at-takathur","103":"al-asr","104":"al-humazah","105":"al-fil","106":"quraysh","107":"al-maun","108":"al-kawthar","109":"al-kafirun","110":"an-nasr","111":"al-masad","112":"al-ikhlas","113":"al-falaq","114":"an-nas"} \ No newline at end of file diff --git a/src/surah.html b/src/surah.html index d8c24a759..57a8e3ec2 100644 --- a/src/surah.html +++ b/src/surah.html @@ -6,7 +6,7 @@ -
+