From 257b057d4b34d9fbef3e05b1dce5af7abd02f5d8 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Mon, 12 Aug 2024 19:11:28 -0300 Subject: [PATCH] Replace opengraph.rb with _opengraph.html.erb --- nanoc/lib/utils.rb | 2 -- nanoc/lib/utils/opengraph.rb | 28 ---------------------------- nanoc/rules/redirect.rules | 2 +- src/html/_opengraph.html.erb | 28 ++++++++++++++++++++++------ src/html/main/random.html.erb | 2 +- src/html/main/redirect.html.erb | 7 ++----- src/html/main/surah-index.html.erb | 2 +- src/html/main/surah-stream.html.erb | 2 +- 8 files changed, 28 insertions(+), 45 deletions(-) delete mode 100644 nanoc/lib/utils/opengraph.rb diff --git a/nanoc/lib/utils.rb b/nanoc/lib/utils.rb index 379d444cb..f2683267a 100644 --- a/nanoc/lib/utils.rb +++ b/nanoc/lib/utils.rb @@ -10,7 +10,6 @@ module Utils require_relative "utils/t" require_relative "utils/inline" require_relative "utils/erb" - require_relative "utils/opengraph" ## # Generic error @@ -89,7 +88,6 @@ module Utils include T include Inline include ERB - include OpenGraph private diff --git a/nanoc/lib/utils/opengraph.rb b/nanoc/lib/utils/opengraph.rb deleted file mode 100644 index e58ef4853..000000000 --- a/nanoc/lib/utils/opengraph.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module Utils::OpenGraph - def opengraph(context) - erb "_opengraph.html.erb", local_assigns(context) - end - - def local_assigns(context) - case context.filename - when "surah-stream.html.erb" - surah = context.surah - {title: t(context.locale, "TheNobleQuran"), - description: surah.name, - url: "#{base_url}/#{context.locale}/#{surah.slug}/", - image: "#{base_url}/images/og/#{surah.id}.png?v=#{commit}"} - when "redirect.html.erb", "surah-index.html.erb" - {title: t(context.locale, "TheNobleQuran"), - description: t(context.locale, "meta.index.description"), - url: "#{base_url}/#{context.locale}/", - image: "#{base_url}/images/og/0.png"} - when "random.html.erb" - {title: t(context.locale, "TheNobleQuran"), - description: t(context.locale, "meta.random.description"), - url: "#{base_url}/#{context.locale}/random/", - image: "#{base_url}/images/og/0.png"} - end - end -end diff --git a/nanoc/rules/redirect.rules b/nanoc/rules/redirect.rules index b72619c12..d2b707fb2 100644 --- a/nanoc/rules/redirect.rules +++ b/nanoc/rules/redirect.rules @@ -6,7 +6,7 @@ # to the surah index for a given locale (eg / -> /en/) compile "/html/main/redirect.html.erb" do - filter(:erb, locals: {locales:}) + filter(:erb, locals: {context: Ryo(locale: "en"), locales:}) filter(:tidy, exe: tidy) write("/index.html") end diff --git a/src/html/_opengraph.html.erb b/src/html/_opengraph.html.erb index 936247192..79d6156da 100644 --- a/src/html/_opengraph.html.erb +++ b/src/html/_opengraph.html.erb @@ -1,6 +1,22 @@ - - - - - - +<% if file == "surah-index.html.erb" || file == "redirect.html.erb" %> + + + + + + +<% elsif file == "surah-stream.html.erb" %> + + + + + + +<% elsif file == "random.html.erb" %> + + + + + + +<% end %> diff --git a/src/html/main/random.html.erb b/src/html/main/random.html.erb index 99a94e55e..51836c8b0 100644 --- a/src/html/main/random.html.erb +++ b/src/html/main/random.html.erb @@ -4,7 +4,7 @@ <%= t(locale, "TheNobleQuran") %> <%= erb("_version.html.erb") %> - <%= opengraph(context) %> + <%= erb("_opengraph.html.erb", {file: "random.html.erb", context:}) %> <%= t("en", "TheNobleQuran") %> <%= erb("_version.html.erb") %> - <%= opengraph(Ryo(filename: "redirect.html.erb", locale: "en")) %> - + <%= erb("_opengraph.html.erb", {page: "redirect.html.erb", context:}) %> + <% locales.each do |locale| %> <%= erb("_version.html.erb") %> - <%= opengraph(context) %> + <%= erb("_opengraph.html.erb", {file: "surah-index.html.erb", context:}) %> <%= erb("_version.html.erb") %> - <%= opengraph(context) %> + <%= erb("_opengraph.html.erb", {file: "stream-stream.html.erb", context:}) %>