From a2fc33bb7c0c611eecb00a2a7d0a87720f7e10ca Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Thu, 5 Oct 2023 15:59:05 -0300 Subject: [PATCH] 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/. --- Rules | 1 - nanoc/rules/pages/surah/id_redirect.rules | 18 ------------------ nanoc/rules/pages/surah/stream.rules | 19 +++++++++++++++---- src/html/pages/surah/id_redirect.html.erb | 22 ---------------------- src/html/pages/surah/stream.html.erb | 13 +++++++++++++ 5 files changed, 28 insertions(+), 45 deletions(-) delete mode 100644 nanoc/rules/pages/surah/id_redirect.rules delete mode 100644 src/html/pages/surah/id_redirect.html.erb diff --git a/Rules b/Rules index ba7fc03fd..00fe57835 100644 --- a/Rules +++ b/Rules @@ -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 diff --git a/nanoc/rules/pages/surah/id_redirect.rules b/nanoc/rules/pages/surah/id_redirect.rules deleted file mode 100644 index 0b58b2139..000000000 --- a/nanoc/rules/pages/surah/id_redirect.rules +++ /dev/null @@ -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 diff --git a/nanoc/rules/pages/surah/stream.rules b/nanoc/rules/pages/surah/stream.rules index a45fc8748..adac564d6 100644 --- a/nanoc/rules/pages/surah/stream.rules +++ b/nanoc/rules/pages/surah/stream.rules @@ -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 diff --git a/src/html/pages/surah/id_redirect.html.erb b/src/html/pages/surah/id_redirect.html.erb deleted file mode 100644 index 5414f487a..000000000 --- a/src/html/pages/surah/id_redirect.html.erb +++ /dev/null @@ -1,22 +0,0 @@ - - - - <%= title %> - - - - - - - - diff --git a/src/html/pages/surah/stream.html.erb b/src/html/pages/surah/stream.html.erb index a76cb6ebc..3783338d4 100644 --- a/src/html/pages/surah/stream.html.erb +++ b/src/html/pages/surah/stream.html.erb @@ -6,6 +6,19 @@ + + <% context.locales.each do |locale| %> + + <% end -%> <%= opengraph(context) %>