Group locals onto 'context'

This commit is contained in:
0x1eef 2024-08-13 16:59:59 -03:00
parent 0aee18baf7
commit 0e5b8db6bf
8 changed files with 29 additions and 38 deletions

3
Rules
View file

@ -21,6 +21,7 @@ Nanoc::RuleDSL::CompilerDSL.prepend(Nanoc::Extension::RequireRules)
locales = %w[ar fa en]
name_by_id = Ryo.from_json(path: File.join(dirs.content, "json", "nameById.json"))
tdata = Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
surahs = Ryo.from_json(path: File.join(dirs.content, "json", "surahs.json"))
tidy = `which tidy || which tidy5`.chomp
buildenv = ENV["buildenv"] || "development"
@ -62,7 +63,7 @@ passthrough "/json/durations/*.json"
require_rules "nanoc/rules/assets"
require_rules "nanoc/rules/redirect", {locales:, tidy:}
require_rules "nanoc/rules/random", {locales:, tdata:, tidy:}
require_rules "nanoc/rules/surah-stream", {locales:, tdata:, name_by_id:, tidy:}
require_rules "nanoc/rules/surah-stream", {locales:, tdata:, surahs:, name_by_id:, tidy:}
require_rules "nanoc/rules/surah-index", {locales:, tdata:, tidy:}
##

View file

@ -7,8 +7,8 @@
locales.each do |locale|
compile "/html/main/random.html.erb", rep: "random/#{locale}" do
context = Ryo.from({filename: "random.html.erb", dir: tdata[locale].dir, locale:, locales:})
filter(:erb, locals: {locale:, locales:, dir: context.dir, context:})
context = Ryo.from({dir: tdata[locale].dir, locale:, locales:})
filter(:erb, locals: {context:})
filter(:tidy, exe: tidy)
write("/#{locale}/random/index.html")
end

View file

@ -7,8 +7,8 @@
locales.each do |locale|
compile "/html/main/surah-index.html.erb", rep: "/#{locale}/surah/index" do
context = Ryo.from(filename: "surah-index.html.erb", dir: tdata[locale].dir, locale:, locales:)
filter(:erb, {locals: {locale:, locales:, dir: context.dir, context:}})
context = Ryo.from(dir: tdata[locale].dir, locale:, locales:)
filter(:erb, {locals: {context:}})
filter(:tidy, exe: tidy)
write "/#{locale}/index.html"
end

View file

@ -15,19 +15,9 @@ end
Ryo.each(name_by_id) do |id, slug|
write_file = ->(locale, pathname:) do
name = tdata[locale].surahs.names[id.to_i - 1]
context = Ryo.from(
filename: "surah-stream.html.erb",
locale:,
locales:,
surah: {id:, name:, slug:},
dir: tdata[locale].dir
)
locals = {
locale: context.locale, locales: context.locales,
surah: context.surah, dir: context.dir, context:
}
filter(:erb, locals:)
surah = surahs[locale][id.to_i - 1]
context = Ryo.from(locale:, locales:, surah:, dir: tdata[locale].dir)
filter(:erb, locals: {context:})
filter(:tidy, exe: tidy)
write "/#{locale}/#{pathname}/index.html"
end

View file

@ -1,15 +1,15 @@
<!DOCTYPE html>
<html lang="<%= locale %>" dir="<%= dir %>">
<html lang="<%= context.locale %>" dir="<%= context.dir %>">
<head>
<title><%= t(locale, "TheNobleQuran") %></title>
<meta name="description" content="<%= t(locale, 'meta.random.description') %>">
<title><%= t(context.locale, "TheNobleQuran") %></title>
<meta name="description" content="<%= t(context.locale, 'meta.random.description') %>">
<%= erb("_version.html.erb") %>
<%= erb("_opengraph.html.erb", {file: "random.html.erb", context:}) %>
<link
rel="canonical"
href="<%= base_url %>/<%= locale %>/random/"
href="<%= base_url %>/<%= context.locale %>/random/"
/>
<% locales.each do |locale| %>
<% context.locales.each do |locale| %>
<link
rel="alternate"
href="<%= base_url %>/<%= locale %>/random/"

View file

@ -1,18 +1,18 @@
<!DOCTYPE html>
<html lang="<%= locale %>" dir="<%= dir %>">
<html lang="<%= context.locale %>" dir="<%= context.dir %>">
<head>
<title><%= t(locale, "TheNobleQuran") %></title>
<title><%= t(context.locale, "TheNobleQuran") %></title>
<%= inline_css('/css/vendor/postman.css') %>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta charset="UTF-8">
<meta name="description" content="<%= t(locale, 'meta.index.description') %>">
<meta name="description" content="<%= t(context.locale, 'meta.index.description') %>">
<%= erb("_version.html.erb") %>
<%= erb("_opengraph.html.erb", {file: "surah-index.html.erb", context:}) %>
<link
rel="canonical"
href="<%= base_url %>/<%= locale %>/"
href="<%= base_url %>/<%= context.locale %>/"
/>
<% locales.each do |locale| %>
<% context.locales.each do |locale| %>
<link rel="alternate"
href="<%= base_url %>/<%= locale %>/"
hreflang="<%= locale %>" />
@ -20,7 +20,7 @@
<%= erb("_favicon.html.erb") %>
</head>
<body>
<%= erb("_postman.html.erb", {locale:, dir:}) %>
<%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
<div class="root h-full"></div>
<script src="/js/loaders/surah-index-loader.js?v=<%= commit %>"></script>
</body>

View file

@ -1,28 +1,28 @@
<!DOCTYPE html>
<html lang="<%= locale %>" dir="<%= dir %>">
<html lang="<%= context.locale %>" dir="<%= context.dir %>">
<head>
<title><%= surah.name %></title>
<title><%= context.surah.name %></title>
<%= inline_css('/css/vendor/postman.css') %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<meta name="description" content="<%= t(locale, 'meta.stream.description') %>">
<meta name="description" content="<%= t(context.locale, 'meta.stream.description') %>">
<%= erb("_version.html.erb") %>
<%= erb("_opengraph.html.erb", {file: "stream-stream.html.erb", context:}) %>
<link
rel="canonical"
href="<%= base_url %>/<%= locale %>/<%= surah.urlName %>/"
href="<%= base_url %>/<%= context.locale %>/<%= context.surah.urlName %>/"
/>
<% locales.each do |locale| %>
<% context.locales.each do |locale| %>
<link rel="alternate"
href="<%= base_url %>/<%= locale %>/<%= surah.urlName %>/"
href="<%= base_url %>/<%= locale %>/<%= context.surah.urlName %>/"
hreflang="<%= locale %>" />
<% end %>
<%= erb("_favicon.html.erb") %>
</head>
<body>
<%= erb("_postman.html.erb", {locale:, dir:}) %>
<%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
<div class="root"
data-surah-id="<%= surah.id %>"
data-surah-id="<%= context.surah.id %>"
data-audio-base-url="<%= audio_base_url %>">
</div>
<script src="/js/loaders/surah-stream-loader.js?v=<%= commit %>"></script>