This commit is contained in:
bohung 2020-03-27 17:26:43 +08:00
parent b568480280
commit 83476f3f0b
1 changed files with 8 additions and 3 deletions

View File

@ -36,6 +36,7 @@ rescue
end end
change_text = '<a title="{{site_title_1}}" class="navbar-brand" href="{{home_link_1}}"><img class="site-logo" src="{{logo_url_1}}" alt="Site Logo"></a><script>$(document).ready(function(){var url =$(\'.site-logo\').eq(0).attr(\'src\');if(url == "/assets/default-site-logo.png"){$(\'.navbar-brand\').eq(0).remove();};if($(\'.navbar-brand\').length == 2){$(\'.site-logo\').css(\'height\',\'auto\')};$(\'.site-logo\').eq(0).css(\'margin-right\',0);$(\'.navbar-brand\').css(\'padding-right\',0)})</script><a title="{{site_title}}" class="navbar-brand" href="{{home_link}}"><img class="site-logo" src="{{logo_url}}" alt="Site Logo"> {{site_name}}</a>' change_text = '<a title="{{site_title_1}}" class="navbar-brand" href="{{home_link_1}}"><img class="site-logo" src="{{logo_url_1}}" alt="Site Logo"></a><script>$(document).ready(function(){var url =$(\'.site-logo\').eq(0).attr(\'src\');if(url == "/assets/default-site-logo.png"){$(\'.navbar-brand\').eq(0).remove();};if($(\'.navbar-brand\').length == 2){$(\'.site-logo\').css(\'height\',\'auto\')};$(\'.site-logo\').eq(0).css(\'margin-right\',0);$(\'.navbar-brand\').css(\'padding-right\',0)})</script><a title="{{site_title}}" class="navbar-brand" href="{{home_link}}"><img class="site-logo" src="{{logo_url}}" alt="Site Logo"> {{site_name}}</a>'
change_text_fix = '<a title="{{site_title_1}}" class="" href="{{home_link_1}}"><img class="site-logo" src="{{logo_url_1}}" alt="Site Logo"></a><script>$(document).ready(function(){var url =$(\'.site-logo\').eq(0).attr(\'src\');if(url == "/assets/default-site-logo.png"){$(\'.navbar-brand\').eq(0).remove();};if($(\'.navbar-brand\').length == 2){$(\'.site-logo\').css(\'height\',\'auto\')};$(\'.site-logo\').eq(0).css(\'margin-right\',0);$(\'.navbar-brand\').css(\'padding-right\',0)})</script><a title="{{site_title}}" class="" href="{{home_link}}"><img class="site-logo" src="{{logo_url}}" alt="Site Logo"> {{site_name}}</a>' change_text_fix = '<a title="{{site_title_1}}" class="" href="{{home_link_1}}"><img class="site-logo" src="{{logo_url_1}}" alt="Site Logo"></a><script>$(document).ready(function(){var url =$(\'.site-logo\').eq(0).attr(\'src\');if(url == "/assets/default-site-logo.png"){$(\'.navbar-brand\').eq(0).remove();};if($(\'.navbar-brand\').length == 2){$(\'.site-logo\').css(\'height\',\'auto\')};$(\'.site-logo\').eq(0).css(\'margin-right\',0);$(\'.navbar-brand\').css(\'padding-right\',0)})</script><a title="{{site_title}}" class="" href="{{home_link}}"><img class="site-logo" src="{{logo_url}}" alt="Site Logo"> {{site_name}}</a>'
change_text_fix1 = '<a title="{{site_title_1}}" class="" href="{{home_link_1}}"><img class="site-logo" src="{{logo_url_1}}" alt="Site Logo"></a><script>$(document).ready(function(){var url =$(\'.site-logo\').eq(0).attr(\'src\');if(url == "/assets/default-site-logo.png"){if($(\'.navbar-brand\').length != 0){$(\'.navbar-brand\').eq(0).remove();}else{$(\'.site-title >a\').eq(0).remove();}};if($(\'.navbar-brand\').length == 2 || $(\'.site-title >a\').length == 2){$(\'.site-logo\').css(\'height\',\'auto\')};$(\'.site-logo\').eq(0).css(\'margin-right\',0);$(\'.navbar-brand\').css(\'padding-right\',0)})</script><a title="{{site_title}}" class="" href="{{home_link}}"><img class="site-logo" src="{{logo_url}}" alt="Site Logo"> {{site_name}}</a>'
all_template.each do |folder| all_template.each do |folder|
if !folder.include?('mobile') if !folder.include?('mobile')
begin begin
@ -45,19 +46,23 @@ all_template.each do |folder|
filename = folder+'home/header.html.erb' filename = folder+'home/header.html.erb'
texts = File.read(filename) texts = File.read(filename)
texts_html = Nokogiri::HTML.parse(texts) texts_html = Nokogiri::HTML.parse(texts)
puts texts
if texts_html.css('.navbar-brand').length == 1 if texts_html.css('.navbar-brand').length == 1
new_texts = texts.gsub(texts_html.css('.navbar-brand').to_s.gsub("%7B",'{').gsub('%7D','}'),change_text) new_texts = texts.gsub(texts_html.css('.navbar-brand').to_s.gsub("%7B",'{').gsub('%7D','}'),change_text)
File.open(filename,'w') do |f| File.open(filename,'w') do |f|
f.write new_texts f.write new_texts
end end
elsif texts_html.css('.site-title >a').length == 1 && texts_html.css('.navbar-brand').length == 0 elsif texts_html.css('.site-title >a').length == 1 && texts_html.css('.navbar-brand').length == 0
new_texts = texts.gsub(texts_html.css('.site-title >a').to_s.gsub("%7B",'{').gsub('%7D','}'),change_text_fix) new_texts = texts.gsub(texts_html.css('.site-title >a').to_s.gsub("%7B",'{').gsub('%7D','}'),change_text_fix1)
File.open(filename,'w') do |f| File.open(filename,'w') do |f|
f.write new_texts f.write new_texts
end end
elsif texts_html.css('.site-title >a.navbar-brand').length == 2 elsif texts_html.css('.site-title >a.navbar-brand').length == 2
new_texts = texts.gsub(change_text,change_text_fix) new_texts = texts.gsub(change_text,change_text_fix1)
File.open(filename,'w') do |f|
f.write new_texts
end
elsif texts.include? change_text_fix
new_texts = texts.gsub(change_text_fix,change_text_fix1)
File.open(filename,'w') do |f| File.open(filename,'w') do |f|
f.write new_texts f.write new_texts
end end