src/: add src/js/pages/redirect-to-surah-slug.ts
This commit is contained in:
parent
e31fac44bb
commit
296aa9a165
3 changed files with 17 additions and 13 deletions
7
Rules
7
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) }
|
||||
|
|
|
@ -7,18 +7,6 @@
|
|||
<script class="surah-id-to-slug" type="application/json">
|
||||
<%= File.read(File.join(Dir.getwd, "src", "slugs.json")) %>
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var parts = location.pathname
|
||||
.split("/")
|
||||
.filter(function(s) { return s.length })
|
||||
.slice(-2);
|
||||
var el = document.querySelector(".surah-id-to-slug");
|
||||
var locale = parts[0];
|
||||
var surahId = parts[1];
|
||||
var slugs = JSON.parse(el.innerText);
|
||||
location.replace(["", locale, slugs[surahId]].join("/"));
|
||||
})();
|
||||
</script>
|
||||
<script src="/js/pages/redirect-to-surah-slug.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
9
src/js/pages/redirect-to-surah-slug.ts
Normal file
9
src/js/pages/redirect-to-surah-slug.ts
Normal file
|
@ -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("/"));
|
||||
})();
|
Loading…
Reference in a new issue