作者在 2019-05-05 18:55:15 发布以下内容
官方的离线版默认是放在根目录的,所以js引用都是这种形式:
<script src="/js/extra.js"></script>
注意红色的反斜线,这样如果不是放在根目录,那么就会出现js引用的错误。
废话少说,用一段ruby代码即可解决:
files = `ag 'src="/js' -l`.split("\n")
files.each do |f|
s = open(f).read
if f.scan(/\//).count == 0
s = s.gsub(/\<script\s+src=\"\/js/, '<script src="js')
elsif f.scan(/\//).count == 1
s = s.gsub(/\<script\s+src=\"\/js/, '<script src="../js')
elsif f.scan(/\//).count == 2
s = s.gsub(/\<script\s+src=\"\/js/, '<script src="../../js')
elsif f.scan(/\//).count == 3
s = s.gsub(/\<script\s+src=\"\/js/, '<script src="../../../js')
else
puts 11111111111111111111111111111111111111111111111
puts f.scan(/\//).count
end
File.open(f, 'w') { |f1| f1.write(s) }
end
files = `find . | ag html$`.split("\n")
files.each do |f|
if not File.file? f
next
end
s = open(f).read
if f.scan(/\//).count == 2
s = s.gsub(/href=\"css\//, 'href="../css/')
elsif f.scan(/\//).count == 3
s = s.gsub(/href=\"css\//, 'href="../../css/')
elsif f.scan(/\//).count == 4
s = s.gsub(/href=\"css\//, 'href="../../../css/')
end
File.open(f, 'w') { |f1| f1.write(s) }
end
保存为ruby脚本文件,放在文档的根目录运行即可。
上面的脚本也可以在线下载:
地址1:
https://doc.bccnsoft.com/docs/ruby_2_6_3_core/zzz_change_js_src.rb
地址2: