Ai
1 Star 1 Fork 0

AsdStudio/sakura-editor.github.io

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
update-google-analytics.py 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
Masaru Tsuchiyama 提交于 2018-09-22 20:30 +08:00 . script async に変更
#!/usr/bin/python
import os
import codecs
import string
import re
# <!-- Global site tag (gtag.js) - Google Analytics -->
# <script async src="https://www.googletagmanager.com/gtag/js?id=UA-120820034-1"></script>
# <script>
# window.dataLayer = window.dataLayer || [];
# function gtag() { dataLayer.push(arguments); }
# gtag('js', new Date());
# gtag('config', 'UA-120820034-1'); // kobake 所有の Google Analytics tracking code
# </script>
# <script type="text/javascript" src="/hoge/huga/hoge.js"></script>
def replace_js_file(path, out_path, js_file):
data = '''<!-- Start Google Analytics -->
<script async type="text/javascript" src="{filename}"></script>
<!-- End Google Analytics -->
'''.format(filename=js_file)
with codecs.open(out_path, 'w', 'utf-8') as f_out:
startTag = False
with codecs.open(path, 'r', 'utf-8') as f_in:
for line in f_in:
if re.search('Google Analytics', line) and re.search('<!--', line):
startTag = True
elif startTag and re.search('</script>', line):
startTag = False
f_out.write(data)
elif not startTag:
f_out.write(line)
js_file = os.path.abspath('googleanalytics.js')
scriptdir = os.path.dirname(os.path.realpath(__file__))
for dirpath, dirnames, filenames in os.walk(scriptdir):
for file in filenames:
if file.endswith('.html'):
js_relative_path = os.path.relpath(js_file, dirpath)
js_relative_path = js_relative_path.replace('\\', '/')
path = os.path.join(dirpath, file)
out_path = path + ".tmp"
replace_js_file(path, out_path, js_relative_path)
print (js_relative_path, path)
os.remove(path)
os.rename(out_path, path)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/EldersJavas/sakura-editor.github.io.git
git@gitee.com:EldersJavas/sakura-editor.github.io.git
EldersJavas
sakura-editor.github.io
sakura-editor.github.io
master

搜索帮助