Remove redirect from /en/1/ to /en/al-fatihah/

Rather than redirect /en/1/ to /en/al-fatihah/, render the surah
stream instead. A canonical `link` tag is included for the benefit
of search engines to differentiate between duplicates.

Preference is given to /en/al-fatihah/ over /en/1/.
This commit is contained in:
0x1eef 2023-10-05 15:59:05 -03:00
parent a6b55b64b7
commit a2fc33bb7c
5 changed files with 28 additions and 45 deletions

1
Rules
View file

@ -82,7 +82,6 @@ require_rules "nanoc/rules/pages/surah/redirect"
require_rules "nanoc/rules/pages/surah/stream", {locales:, i18n:, slugs:}
require_rules "nanoc/rules/pages/surah/index", {locales:, i18n:}
require_rules "nanoc/rules/pages/surah/random", {locales:, i18n:, slugs:}
require_rules "nanoc/rules/pages/surah/id_redirect", {locales:, i18n:, slugs:}
##
# Defaults

View file

@ -1,18 +0,0 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# Rules for a redirect from a surah id to a surah name
# (eg /en/1/ -> /en/al-fatihah/)
1.upto(114) do |id|
locales.each do |locale|
compile "/html/pages/surah/id_redirect.html.erb", rep: "redirect_id/#{locale}/#{id}" do
slug = slugs[id]
redirect_url = "https://al-quran.reflectslight.io/#{locale}/#{slug}/"
title = i18n[locale].TheNobleQuran
filter(:erb, {locals: {title:, redirect_url:, locale:}})
write("/#{locale}/#{id}/index.html")
end
end
end

View file

@ -14,12 +14,23 @@ compile "/*/*/surah.json" do
end
Ryo.each(slugs) do |id, slug|
writer = ->(locale, identifier:) do
name = i18n[locale].surahs.names[id.to_i - 1]
context = Ryo.from(
filename: "stream.html.erb",
locale:,
locales:,
surah: {id:, name:, slug:}
)
filter(:erb, locals: {context:})
write "/#{locale}/#{identifier}/index.html"
end
locales.each do |locale|
compile "/html/pages/surah/stream.html.erb", rep: "/#{locale}/#{slug}/index.html" do
name = i18n[locale].surahs.names[id.to_i - 1]
context = Ryo.from(filename: "stream.html.erb", locale:, surah: {id:, name:, slug:})
filter(:erb, locals: {context:})
write "/#{locale}/#{slug}/index.html"
instance_exec(locale, identifier: slug, &writer)
end
compile "/html/pages/surah/stream.html.erb", rep: "/#{locale}/#{id}/index.html" do
instance_exec(locale, identifier: id, &writer)
end
end
end

View file

@ -1,22 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel="canonical" href="<%= redirect_url %>">
<link rel="icon" href="/favicon.png">
<noscript>
<meta http-equiv="refresh" content="0; url=<%= redirect_url %>">
</noscript>
</head>
<body>
<script>
(function() {
var el = document.createElement("meta");
var url = "<%= redirect_url %>" + document.location.search;
el.setAttribute("http-equiv", "refresh");
el.setAttribute("content", "0; url=" + url);
document.head.append(el);
})();
</script>
</body>
</html>

View file

@ -6,6 +6,19 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<meta name="description" content="<%= t(context.locale, 'meta.stream.description') %>">
<link
rel="canonical"
hreflang="<%= context.locale %>"
href="/<%= context.locale %>/<%= context.surah.slug %>/"
/>
<% context.locales.each do |locale| %>
<link
rel="alternate"
type="text/html"
hreflang="<%= locale %>"
href="/<%= locale %>/<%= context.surah.slug %>/"
/>
<% end -%>
<%= opengraph(context) %>
<link rel="icon" href="/favicon.png">
</head>