From 34246f734592ee3867a10365a2f639f1576d8139 Mon Sep 17 00:00:00 2001
From: virusdefender <1670873886@qq.com>
Date: Sun, 13 Sep 2015 10:58:48 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E6=97=B6=E9=97=B4?=
=?UTF-8?q?=E6=88=B3=E7=9A=84=20Python=20=E8=84=9A=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
static/release/fis-conf.js | 13 ----------
tools/static_md5.py | 51 ++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 13 deletions(-)
delete mode 100644 static/release/fis-conf.js
create mode 100644 tools/static_md5.py
diff --git a/static/release/fis-conf.js b/static/release/fis-conf.js
deleted file mode 100644
index f0935c30..00000000
--- a/static/release/fis-conf.js
+++ /dev/null
@@ -1,13 +0,0 @@
-/**
- * Created by virusdefender on 8/25/15.
- */
-
-fis.match('*.{js,css,png,gif}', {
- useHash: true // 开启 md5 戳
-});
-
-fis.config.set(
-'roadmap.path',
-[{reg:'*.html',isHtmlLike : true}
-])
-;
\ No newline at end of file
diff --git a/tools/static_md5.py b/tools/static_md5.py
new file mode 100644
index 00000000..db1b2811
--- /dev/null
+++ b/tools/static_md5.py
@@ -0,0 +1,51 @@
+# coding=utf-8
+import hashlib
+import re
+import os
+import shutil
+
+template_src_path = "template/src/"
+template_release_path = "template/release/"
+
+static_src_path = "static/src/"
+static_release_path = "static/release/"
+
+# 删除模板的 release 文件夹
+shutil.rmtree(template_release_path)
+# 复制一份模板文件夹到 release
+shutil.copytree(template_src_path, template_release_path)
+
+# 删除静态文件的 release 文件夹
+shutil.rmtree(static_release_path)
+# 复制一份静态文件文件夹到 release
+shutil.copytree(static_src_path, static_release_path)
+
+r = re.compile(r'')
+
+name_map = {}
+
+
+def do(match):
+ js_path = match.group(1).lstrip("/static/")
+
+ if not os.path.exists(static_release_path + js_path):
+ return match.group(0)
+
+ if js_path in name_map:
+ md5 = name_map[js_path]
+ else:
+ # rename
+ md5 = hashlib.md5(open(static_release_path + js_path, "r").read()).hexdigest()
+ os.rename(static_release_path + js_path, static_release_path + js_path + "?v=" + md5)
+ return '' % (js_path + "?v=" + md5,)
+
+
+for root, dirs, files in os.walk(template_release_path):
+ for name in files:
+ html_path = os.path.join(root, name)
+ html_content = open(html_path, "r").read()
+ replaced_html_content = re.sub(r, do, html_content)
+
+ f = open(html_path, "w")
+ f.write(replaced_html_content)
+ f.close()