Re-implement id_redirect.ts without a JS redirect

This commit is contained in:
0x1eef 2023-03-11 13:46:42 -03:00
parent 3f3032dfcb
commit c1d23f27c7
3 changed files with 5 additions and 21 deletions

View file

@ -8,13 +8,10 @@
1.upto(114) do |id|
locales.each do |locale|
compile "/html/pages/surah/id_redirect.html.erb", rep: "redirect_id/#{locale}/#{id}" do
filter(:erb, locals: {locale:, surah_name: surah_id_to_name[id]})
surah_name = surah_id_to_name[id]
redirect_url = "https://al-quran.reflectslight.io/#{locale}/#{surah_name}/"
filter(:erb, {locals: {redirect_url:}})
write("/#{locale}/#{id}/index.html")
end
end
end
compile "/js/pages/surah/id_redirect.ts" do
filter(:webpack)
write("/js/pages/surah/id_redirect.js")
end

View file

@ -2,12 +2,9 @@
<html>
<head>
<title>Al-Quran: redirect</title>
<link
rel="canonical"
href="https://al-quran.reflectslight.io/<%= locale %>/<%= surah_name %>/">
<link rel="canonical" href="<%= redirect_url %>">
<meta http-equiv="refresh" content="0; url=<%= redirect_url %>">
</head>
<body>
<%= inline_json('/slugs.json') %>
<script src="/js/pages/surah/id_redirect.js"></script>
</body>
</html>

View file

@ -1,10 +0,0 @@
(function () {
const [locale, surahId] = location.pathname
.split('/')
.filter(function (s) { return s.length; })
.slice(-2);
const el: HTMLElement = document.querySelector('.json.slugs')!;
const slugs = JSON.parse(el.innerText);
const path = ['', locale, slugs[surahId]].join('/');
location.replace([path, location.search].join(''));
})();