Update mixin.rb
This commit is contained in:
parent
401464c615
commit
51e507e649
10 changed files with 51 additions and 36 deletions
|
@ -7,19 +7,44 @@ module Mixin
|
||||||
require_relative "mixin/erb"
|
require_relative "mixin/erb"
|
||||||
require_relative "mixin/opengraph"
|
require_relative "mixin/opengraph"
|
||||||
|
|
||||||
def app_version
|
##
|
||||||
@app_version ||= begin
|
# @return [Ryo::Object]
|
||||||
ver = File.read File.join(Dir.getwd, "VERSION")
|
# Returns common directory paths as a Ryo object
|
||||||
ver.gsub(/[^\d.]/, "")
|
def dirs
|
||||||
end
|
@dirs ||= Ryo(
|
||||||
|
root:,
|
||||||
|
build: nanoc.output_dir,
|
||||||
|
content: File.join(root, nanoc.data_sources[0].content_dir)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def revision
|
##
|
||||||
@rev ||= cmd("git", "rev-parse", "HEAD").stdout.strip
|
# @return [Ryo::Object]
|
||||||
|
# Returns the contents of nanoc.yaml as a Ryo object
|
||||||
|
def nanoc
|
||||||
|
@nanoc ||= Ryo.from_yaml(path: File.join(root, "nanoc.yaml"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_dir
|
##
|
||||||
nanoc.output_dir
|
# @return [String]
|
||||||
|
# Returns an absolute path to the root directory of the website
|
||||||
|
def root
|
||||||
|
@root ||= File.realpath(File.join(__dir__, "..", "..", "."))
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# @return [String]
|
||||||
|
# Returns the website version
|
||||||
|
def version
|
||||||
|
@version ||= File.read(File.join(dirs.root, "VERSION"))
|
||||||
|
.gsub(/[^\d.]/, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# @return [String]
|
||||||
|
# Returns the most recent git commit hash
|
||||||
|
def commit
|
||||||
|
@commit ||= cmd("git", "rev-parse", "HEAD").stdout.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -44,13 +69,6 @@ module Mixin
|
||||||
nanoc.server.base_url
|
nanoc.server.base_url
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# @return [Ryo::Object]
|
|
||||||
# Returns the contents of nanoc.yaml as a Ryo object
|
|
||||||
def nanoc
|
|
||||||
@nanoc ||= Ryo.from_yaml(path: File.join(Dir.getwd, "nanoc.yaml"))
|
|
||||||
end
|
|
||||||
|
|
||||||
include T
|
include T
|
||||||
include Inline
|
include Inline
|
||||||
include ERB
|
include ERB
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Mixin::ERB
|
module Mixin::ERB
|
||||||
def erb(path, local_assigns = {})
|
def erb(file, local_assigns = {})
|
||||||
erb = File.binread File.join(Dir.getwd, "src", "html", path)
|
erb = File.binread File.join(dirs.content, "html", file)
|
||||||
scope = binding
|
ctx = binding
|
||||||
local_assigns.each { scope.local_variable_set(_1, _2) }
|
local_assigns.each { ctx.local_variable_set(_1, _2) }
|
||||||
::ERB.new(erb).result(scope)
|
::ERB.new(erb).result(ctx)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Mixin::OpenGraph
|
||||||
{title: t(context.locale, "TheNobleQuran"),
|
{title: t(context.locale, "TheNobleQuran"),
|
||||||
description: surah.name,
|
description: surah.name,
|
||||||
url: "#{base_url}/#{context.locale}/#{surah.slug}/",
|
url: "#{base_url}/#{context.locale}/#{surah.slug}/",
|
||||||
image: "#{base_url}/images/og/#{surah.id}.png?v=#{revision}"}
|
image: "#{base_url}/images/og/#{surah.id}.png?v=#{commit}"}
|
||||||
when "redirect.html.erb", "surah-index.html.erb"
|
when "redirect.html.erb", "surah-index.html.erb"
|
||||||
{title: t(context.locale, "TheNobleQuran"),
|
{title: t(context.locale, "TheNobleQuran"),
|
||||||
description: t(context.locale, "meta.index.description"),
|
description: t(context.locale, "meta.index.description"),
|
||||||
|
|
|
@ -7,9 +7,6 @@ module Mixin::T
|
||||||
end
|
end
|
||||||
|
|
||||||
def tdata
|
def tdata
|
||||||
@tdata ||= begin
|
@tdata ||= Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
|
||||||
path = File.join(Dir.getwd, "src", "json", "t.json")
|
|
||||||
Ryo.from_json(path:)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
<meta name="version" content="<%= app_version %>">
|
|
||||||
<meta name="revision" content="<%= revision %>">
|
|
2
src/html/_version.html.erb
Normal file
2
src/html/_version.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<meta name="version" content="<%= version %>">
|
||||||
|
<meta name="revision" content="<%= commit %>">
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<title><%= t(locale, "TheNobleQuran") %></title>
|
<title><%= t(locale, "TheNobleQuran") %></title>
|
||||||
<meta name="description" content="<%= t(locale, 'meta.random.description') %>">
|
<meta name="description" content="<%= t(locale, 'meta.random.description') %>">
|
||||||
<%= erb("_revision.html.erb") %>
|
<%= erb("_version.html.erb") %>
|
||||||
<%= opengraph(context) %>
|
<%= opengraph(context) %>
|
||||||
<link
|
<link
|
||||||
rel="canonical"
|
rel="canonical"
|
||||||
|
@ -18,6 +18,6 @@
|
||||||
<%= erb("_favicon.html.erb") %>
|
<%= erb("_favicon.html.erb") %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script src="/js/main/random.js?v=<%= revision %>"></script>
|
<script src="/js/main/random.js?v=<%= commit %>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<html lang="en" dir="ltr">
|
<html lang="en" dir="ltr">
|
||||||
<head>
|
<head>
|
||||||
<title><%= t("en", "TheNobleQuran") %></title>
|
<title><%= t("en", "TheNobleQuran") %></title>
|
||||||
<%= erb("_revision.html.erb") %>
|
<%= erb("_version.html.erb") %>
|
||||||
<%= opengraph(Ryo(filename: "redirect.html.erb", locale: "en")) %>
|
<%= opengraph(Ryo(filename: "redirect.html.erb", locale: "en")) %>
|
||||||
<link
|
<link
|
||||||
rel="canonical"
|
rel="canonical"
|
||||||
|
@ -17,6 +17,6 @@
|
||||||
<%= erb("_favicon.html.erb") %>
|
<%= erb("_favicon.html.erb") %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script src="/js/main/redirect.js?v=<%= revision %>"></script>
|
<script src="/js/main/redirect.js?v=<%= commit %>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="description" content="<%= t(locale, 'meta.index.description') %>">
|
<meta name="description" content="<%= t(locale, 'meta.index.description') %>">
|
||||||
<%= erb("_revision.html.erb") %>
|
<%= erb("_version.html.erb") %>
|
||||||
<%= opengraph(context) %>
|
<%= opengraph(context) %>
|
||||||
<link
|
<link
|
||||||
rel="canonical"
|
rel="canonical"
|
||||||
|
@ -22,6 +22,6 @@
|
||||||
<body>
|
<body>
|
||||||
<%= erb("_postman.html.erb", {locale:, dir:}) %>
|
<%= erb("_postman.html.erb", {locale:, dir:}) %>
|
||||||
<div class="root h-full"></div>
|
<div class="root h-full"></div>
|
||||||
<script src="/js/loaders/surah-index-loader.js?v=<%= revision %>"></script>
|
<script src="/js/loaders/surah-index-loader.js?v=<%= commit %>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="description" content="<%= t(locale, 'meta.stream.description', {surah_name: surah.name}) %>">
|
<meta name="description" content="<%= t(locale, 'meta.stream.description', {surah_name: surah.name}) %>">
|
||||||
<%= erb("_revision.html.erb") %>
|
<%= erb("_version.html.erb") %>
|
||||||
<%= opengraph(context) %>
|
<%= opengraph(context) %>
|
||||||
<link
|
<link
|
||||||
rel="canonical"
|
rel="canonical"
|
||||||
|
@ -25,6 +25,6 @@
|
||||||
data-surah-id="<%= surah.id %>"
|
data-surah-id="<%= surah.id %>"
|
||||||
data-audio-base-url="<%= audio_base_url %>">
|
data-audio-base-url="<%= audio_base_url %>">
|
||||||
</div>
|
</div>
|
||||||
<script src="/js/loaders/surah-stream-loader.js?v=<%= revision %>"></script>
|
<script src="/js/loaders/surah-stream-loader.js?v=<%= commit %>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue