# frozen_string_literal: true ## # The {Utils Utils} module provides methods that are # available at build time. ERB templates, the Rules file # and Rakefile.rb all have access to the methods of this # module module Utils require "test-cmd" require_relative "utils/t" require_relative "utils/inline" require_relative "utils/erb" require_relative "utils/opengraph" ## # @return [Ryo::Object] # Returns common directory paths as a Ryo object def dirs @dirs ||= Ryo( root:, build: File.join(root, nanoc.output_dir), content: File.join(root, nanoc.data_sources[0].content_dir) ) end ## # @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 ## # @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 ## # @note # This method returns the website version in # case git fails or is unavailable # @return [String] # Returns the most recent git commit hash def commit @commit ||= begin r = cmd("git", "rev-parse", "HEAD") r.success? ? r.stdout.strip : version end end ## # The URL for an audio file is resolved # by joining `nanoc.audio.base_url` and # `//.mp3`. # # @return [String] # Returns the base url for audio requests. # The default (https://al-quran.reflectslight.io/audio/alafasy) # works out of the box. def audio_base_url nanoc.audio.base_url end ## # @return [String] # Returns the base URL for use with opengraph, # tags, /sitemap.xml, etc. The default is # https://al-quran.reflectslight.io. def base_url nanoc.server.base_url end include T include Inline include ERB include OpenGraph end use_helper(Utils) if respond_to?(:use_helper)