From 296aa9a1650efa9154dd541f6e65669117cc4ebc Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 6 Nov 2022 06:51:28 -0300 Subject: [PATCH] src/: add src/js/pages/redirect-to-surah-slug.ts --- Rules | 7 +++++++ src/html/redirect-to-surah-slug.html.erb | 14 +------------- src/js/pages/redirect-to-surah-slug.ts | 9 +++++++++ 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 src/js/pages/redirect-to-surah-slug.ts diff --git a/Rules b/Rules index 3ee821807..95b80ed8d 100644 --- a/Rules +++ b/Rules @@ -59,6 +59,13 @@ compile "/js/pages/redirect-to-random-surah.ts" do 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, exe: "./node_modules/webpack/bin/webpack.js" + write "/js/pages/redirect-to-surah-slug.js" +end + ## # CSS compile("/css/_*.scss") { write(nil) } diff --git a/src/html/redirect-to-surah-slug.html.erb b/src/html/redirect-to-surah-slug.html.erb index b12da54ad..91bd6d618 100644 --- a/src/html/redirect-to-surah-slug.html.erb +++ b/src/html/redirect-to-surah-slug.html.erb @@ -7,18 +7,6 @@ - + diff --git a/src/js/pages/redirect-to-surah-slug.ts b/src/js/pages/redirect-to-surah-slug.ts new file mode 100644 index 000000000..8319a77d7 --- /dev/null +++ b/src/js/pages/redirect-to-surah-slug.ts @@ -0,0 +1,9 @@ +(function() { + const [locale, surahId] = location.pathname + .split("/") + .filter(function(s) { return s.length }) + .slice(-2); + const el: HTMLElement = document.querySelector(".surah-id-to-slug"); + const slugs = JSON.parse(el.innerText); + location.replace(["", locale, slugs[surahId]].join("/")); +})();