Add "jsondir"

This commit is contained in:
0x1eef 2024-05-19 20:46:37 -03:00
parent 716096e911
commit d7c140bca1

View file

@ -1,14 +1,14 @@
# frozen_string_literal: true
namespace :t do
jsondir = File.join(Dir.getwd, "src", "json")
desc "Generate /json/<locale>/<surahid>/info.json from surahs.json"
task :"surahs.json" do
require "json"
path = File.join(Dir.getwd, "src", "json", "surahs.json")
surahs = JSON.parse(File.read(path))
surahs = JSON.parse File.read(File.join(jsondir, "surahs.json"))
surahs.keys.each do |locale|
surahs[locale].each.with_index(1) do |surah, index|
target = File.join(Dir.getwd, "src", "json", locale, index.to_s, "info.json")
target = File.join(jsondir, locale, index.to_s, "info.json")
File.write(target, JSON.pretty_generate(surah))
end
end