Merge pull request #104 from ReflectsLight/sitemap_xml
Add src/sitemap.xml.erb
This commit is contained in:
commit
9e51676d2a
6 changed files with 51 additions and 20 deletions
10
Rules
10
Rules
|
@ -35,7 +35,7 @@ require_rules "rules/pages/surah/random", {locales:, surah_id_to_name:}
|
|||
require_rules "rules/pages/surah/stream", {locales:, surah_id_to_name:}
|
||||
require_rules "rules/pages/surah/index", {locales:}
|
||||
require_rules "rules/pages/surah/redirect"
|
||||
require_rules "rules/pages/surah/id_redirect", {locales:}
|
||||
require_rules "rules/pages/surah/id_redirect", {locales:, surah_id_to_name:}
|
||||
|
||||
##
|
||||
# Inline CSS / JSON rules
|
||||
|
@ -60,6 +60,14 @@ compile "/css/webpackage.scss" do
|
|||
write(nil)
|
||||
end
|
||||
|
||||
##
|
||||
# /sitemap.xml
|
||||
compile "/sitemap.xml.erb" do
|
||||
filter(:erb, locals: {locales:, surah_id_to_name:})
|
||||
filter(:strip)
|
||||
write("/sitemap.xml")
|
||||
end
|
||||
|
||||
##
|
||||
# Defaults
|
||||
compile("/**/*") { write(nil) }
|
||||
|
|
10
lib/nanoc/filters/strip.rb
Normal file
10
lib/nanoc/filters/strip.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Nanoc::Filters::Strip < Nanoc::Filter
|
||||
identifier :strip
|
||||
type text: :text
|
||||
|
||||
def run(content, options = {})
|
||||
content.each_line.reject { _1.strip.empty? }.join
|
||||
end
|
||||
end
|
|
@ -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)
|
||||
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
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<title>Al-Quran: redirect</title>
|
||||
<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>
|
||||
|
|
|
@ -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(''));
|
||||
})();
|
26
src/sitemap.xml.erb
Normal file
26
src/sitemap.xml.erb
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
||||
<% locales.each do |locale| %>
|
||||
<url>
|
||||
<loc>https://al-quran.reflectslight.io/<%= locale %>/</loc>
|
||||
<% locales.each do |locale| %>
|
||||
<xhtml:link
|
||||
rel="alternate"
|
||||
hreflang="<%= locale %>"
|
||||
href="https://al-quran.reflectslight.io/<%= locale %>/"/>
|
||||
<% end %>
|
||||
</url>
|
||||
<% Ryo.each(surah_id_to_name) do |_id, name| %>
|
||||
<url>
|
||||
<loc>https://al-quran.reflectslight.io/<%= locale %>/<%= name %>/</loc>
|
||||
<% locales.each do |locale| %>
|
||||
<xhtml:link
|
||||
rel="alternate"
|
||||
hreflang="<%= locale %>"
|
||||
href="https://al-quran.reflectslight.io/<%= locale %>/<%= name %>/"/>
|
||||
<% end %>
|
||||
</url>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</urlset>
|
Loading…
Reference in a new issue