-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V1.5.1 Seperate js and css, improve loading speed
- Loading branch information
Showing
10 changed files
with
65 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,58 @@ | ||
# Watch file changes and auto packup html and bundle.js | ||
# Watch file changes in './Docs' and auto packup html with js | ||
|
||
import hashlib | ||
import os | ||
import re | ||
import time | ||
|
||
html_sha = '' | ||
js_sha = '' | ||
# Detect difference by comparing MD5 | ||
html_md5 = '' | ||
js_md5 = '' | ||
css_md5 = '' | ||
|
||
# Loop forever | ||
while True: | ||
files = os.listdir('dist') | ||
files = os.listdir('docs') | ||
|
||
# Read html and bundle.js, calculate SHA256 | ||
# Read html, bundle.js and style.js | ||
for filename in files: | ||
filename = os.path.join('dist', filename) | ||
filename = os.path.join('docs', filename) | ||
if filename.endswith('.html'): | ||
with open(filename, 'rb') as f: | ||
html_txt = f.read() | ||
if filename.endswith('.js'): | ||
if filename.endswith('bundle.js'): | ||
with open(filename, 'rb') as f: | ||
js_txt = f.read() | ||
js_txt = js_txt.replace(b'\\', b'/@placeholder@/') | ||
new_html_sha = hashlib.sha256(html_txt).hexdigest() | ||
new_js_sha = hashlib.sha256(js_txt).hexdigest() | ||
if filename.endswith('style.js'): | ||
with open(filename, 'rb') as f: | ||
css_txt = f.read() | ||
|
||
# '\' will cause error, replace them | ||
js_txt = js_txt.replace(b'\\', b'/@placeholder@/') | ||
css_txt = css_txt.replace(b'\\', b'/@placeholder@/') | ||
|
||
# Calculate MD5 | ||
new_html_md5 = hashlib.md5(html_txt).hexdigest() | ||
new_js_md5 = hashlib.md5(js_txt).hexdigest() | ||
new_css_md5 = hashlib.md5(css_txt).hexdigest() | ||
|
||
# Check for difference and packup | ||
if (new_html_sha != html_sha or new_js_sha != js_sha): | ||
if (new_html_md5 != html_md5 or new_js_md5 != js_md5 or new_css_md5 != css_md5): | ||
print('Detect change. Packing...') | ||
new_html_txt = re.sub(rb'<script.*?></script>', | ||
b'<script>\n' + js_txt + b'\n</script>', | ||
html_txt) | ||
new_html_txt = new_html_txt.replace(b'/@placeholder@/', b'\\') | ||
html_txt = re.sub(rb'<script .*?bundle.*?"></script>', | ||
b'<script>\n' + js_txt + b'\n</script>', | ||
html_txt) | ||
html_txt = re.sub(rb'<script .*?style.*?"></script>', | ||
b'<script>\n' + css_txt + b'\n</script>', | ||
html_txt) | ||
html_txt = html_txt.replace(b'/@placeholder@/', b'\\') | ||
with open('TreePlaygroundPackup.html', 'wb') as f: | ||
f.write(new_html_txt) | ||
f.write(html_txt) | ||
print('Packed...') | ||
|
||
# Update SHA256 value | ||
html_sha = new_html_sha | ||
js_sha = new_js_sha | ||
# Update MD5 value | ||
html_md5 = new_html_md5 | ||
js_md5 = new_js_md5 | ||
css_md5 = new_css_md5 | ||
|
||
time.sleep(1) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
@import "./toolbars.css"; | ||
@import "./binnodes.css"; | ||
@import "./edges.css"; | ||
* { | ||
padding: 0; | ||
margin: 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import "./css/index.css"; | ||
import "./css/button.css"; | ||
import "./css/toolbars.css"; | ||
import "./css/binnodes.css"; | ||
import "./css/edges.css"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters