From d07d74c0bb053edea23c95fb82073881ccb0b435 Mon Sep 17 00:00:00 2001 From: Peter Chiu Date: Mon, 22 Jul 2024 13:24:22 +0800 Subject: [PATCH] auto update frontend show page --- event_news_mod.gemspec | 44 +++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/event_news_mod.gemspec b/event_news_mod.gemspec index 792c54a..e758175 100644 --- a/event_news_mod.gemspec +++ b/event_news_mod.gemspec @@ -28,6 +28,7 @@ if bundle_update_flag default_info_contents = JSON.parse(File.read("#{app_path}/modules/event_news_mod/info.json")) rescue {} default_event_news_index_info = default_info_contents["frontend"].sort_by{|h| h["filename"].to_f} rescue [] default_event_news_widget_info = default_info_contents["widgets"].sort_by{|h| h["filename"].to_f} rescue [] + default_event_news_show_info = default_info_contents["show"] rescue nil all_template.each do |folder| if !folder.include?('mobile') if Dir.exist?("#{folder}modules/event_news") @@ -49,15 +50,15 @@ if bundle_update_flag if flag puts "Checking event_news index" index_info = info["frontend"].sort_by{|h| h["filename"].to_i} rescue [] - update_flag = false last_index = index_info.collect{|v| v["filename"].to_s.scan(/\d+/).collect{|v1| v1.to_i}}.flatten.sort[-1] rescue nil + update_index_flag = false if !last_index.nil? idx_regex = /^(\d+[\. \t]*)|[ \t]+$/ default_event_news_index_info.each do |h| name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'') index_info_index = (index_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1) if index_info_index == -1 - update_flag = true + update_index_flag = true copy_h = h.dup h.delete("force_cover") last_index = last_index + 1 @@ -71,28 +72,22 @@ if bundle_update_flag bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{h["filename"]}.html.erb #{folder}modules/event_news_mod/#{index_info[index_info_index]["filename"]}.html.erb]} end end - if update_flag + if update_index_flag info["frontend"] = index_info puts "Writing json #{info["frontend"].count} in #{info_json_file}" - begin - info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n") - rescue - info_json = info.to_s.gsub("=>",": \n") - end - File.open(info_json_file,"w+"){|f| f.write(info_json)} end end puts "Checking event_news widgets" widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue [] - update_flag = false last_index = widget_info.collect{|v| v["filename"].to_s.scan(/\d+/).collect{|v1| v1.to_i}}.flatten.sort[-1] rescue nil + update_widget_flag = false if !last_index.nil? idx_regex = /^(\d+[\. \t]*)|[ \t]+$/ default_event_news_widget_info.each do |h| name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'') widget_info_index = (widget_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1) if widget_info_index == -1 - update_flag = true + update_widget_flag = true copy_h = h.dup h.delete("force_cover") last_index = last_index + 1 @@ -106,17 +101,30 @@ if bundle_update_flag bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/_#{h["filename"]}.html.erb #{folder}modules/event_news_mod/_#{widget_info[widget_info_index]["filename"]}.html.erb]} end end - if update_flag + if update_widget_flag info["widgets"] = widget_info puts "Writing json #{info["widgets"].count} in #{info_json_file}" - begin - info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n") - rescue - info_json = info.to_s.gsub("=>",": \n") - end - File.open(info_json_file,"w+"){|f| f.write(info_json)} end end + + update_show_flag = false + if !default_event_news_show_info.nil? + update_show_flag = info["show"] != default_event_news_show_info + info["show"] = default_event_news_show_info + default_event_news_show_info.each do |info_detail| + filename = info_detail['filename'] + bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{filename}.html.erb #{folder}modules/event_news_mod/#{filename}.html.erb]} + end + end + + if update_index_flag || update_widget_flag || update_show_flag + begin + info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n") + rescue + info_json = info.to_s.gsub("=>",": \n") + end + File.open(info_json_file,"w+"){|f| f.write(info_json)} + end end rescue => e puts e