Skip to content

Commit c49a2b9

Browse files
committed
V1.5.1 Seperate js and css, improve loading speed
1 parent 0bf5388 commit c49a2b9

File tree

10 files changed

+65
-53
lines changed

10 files changed

+65
-53
lines changed

autopackup.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,58 @@
1-
# Watch file changes and auto packup html and bundle.js
1+
# Watch file changes in './Docs' and auto packup html with js
22

33
import hashlib
44
import os
55
import re
66
import time
77

8-
html_sha = ''
9-
js_sha = ''
8+
# Detect difference by comparing MD5
9+
html_md5 = ''
10+
js_md5 = ''
11+
css_md5 = ''
1012

1113
# Loop forever
1214
while True:
13-
files = os.listdir('dist')
15+
files = os.listdir('docs')
1416

15-
# Read html and bundle.js, calculate SHA256
17+
# Read html, bundle.js and style.js
1618
for filename in files:
17-
filename = os.path.join('dist', filename)
19+
filename = os.path.join('docs', filename)
1820
if filename.endswith('.html'):
1921
with open(filename, 'rb') as f:
2022
html_txt = f.read()
21-
if filename.endswith('.js'):
23+
if filename.endswith('bundle.js'):
2224
with open(filename, 'rb') as f:
2325
js_txt = f.read()
24-
js_txt = js_txt.replace(b'\\', b'/@placeholder@/')
25-
new_html_sha = hashlib.sha256(html_txt).hexdigest()
26-
new_js_sha = hashlib.sha256(js_txt).hexdigest()
26+
if filename.endswith('style.js'):
27+
with open(filename, 'rb') as f:
28+
css_txt = f.read()
29+
30+
# '\' will cause error, replace them
31+
js_txt = js_txt.replace(b'\\', b'/@placeholder@/')
32+
css_txt = css_txt.replace(b'\\', b'/@placeholder@/')
33+
34+
# Calculate MD5
35+
new_html_md5 = hashlib.md5(html_txt).hexdigest()
36+
new_js_md5 = hashlib.md5(js_txt).hexdigest()
37+
new_css_md5 = hashlib.md5(css_txt).hexdigest()
2738

2839
# Check for difference and packup
29-
if (new_html_sha != html_sha or new_js_sha != js_sha):
40+
if (new_html_md5 != html_md5 or new_js_md5 != js_md5 or new_css_md5 != css_md5):
3041
print('Detect change. Packing...')
31-
new_html_txt = re.sub(rb'<script.*?></script>',
32-
b'<script>\n' + js_txt + b'\n</script>',
33-
html_txt)
34-
new_html_txt = new_html_txt.replace(b'/@placeholder@/', b'\\')
42+
html_txt = re.sub(rb'<script .*?bundle.*?"></script>',
43+
b'<script>\n' + js_txt + b'\n</script>',
44+
html_txt)
45+
html_txt = re.sub(rb'<script .*?style.*?"></script>',
46+
b'<script>\n' + css_txt + b'\n</script>',
47+
html_txt)
48+
html_txt = html_txt.replace(b'/@placeholder@/', b'\\')
3549
with open('TreePlaygroundPackup.html', 'wb') as f:
36-
f.write(new_html_txt)
50+
f.write(html_txt)
3751
print('Packed...')
3852

39-
# Update SHA256 value
40-
html_sha = new_html_sha
41-
js_sha = new_js_sha
53+
# Update MD5 value
54+
html_md5 = new_html_md5
55+
js_md5 = new_js_md5
56+
css_md5 = new_css_md5
4257

4358
time.sleep(1)

docs/bundle.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<meta name="git" content="https://github.com/hwc0919/TreePlayground">
1010
<link rel="Shortcut Icon" href="/favicon.ico">
1111
<title>TreePlayground - NitroMelon</title>
12+
<script src="./style.js"></script>
1213
</head>
1314

1415
<body>

docs/style.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import Vue from "../node_modules/vue/dist/vue"
1+
import "./js/cycle.js";
2+
import Vue from "../node_modules/vue/dist/vue.min"
23
import IntrBinnode from "./components/binnode.vue"
34
import ExtrBinnode from "./components/extr-binnode.vue"
45
import TopBinnode from "./components/top-binnode.vue"
@@ -223,7 +224,7 @@ var tp = new Vue({
223224
if (this.isAnyLocked()) return false;
224225
this.tree.removeBelow(node);
225226
this.update();
226-
this.alertAsync(`Remove Below ${node.data}`);
227+
this.showMessage(`Remove Below ${node.data}`);
227228
},
228229
// Remove one node
229230
onRemoveOne(node) {

src/css/index.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
@import "./toolbars.css";
2-
@import "./binnodes.css";
3-
@import "./edges.css";
41
* {
52
padding: 0;
63
margin: 0;

src/css/toolbars.css

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
justify-content: center;
55
align-items: center;
66
margin-top: 25px;
7-
height: 70px;
7+
height: 50px;
88
width: 100vw;
9-
background-color: rgba(255, 255, 255, 0.8);
109
}
1110

1211
.top-toolbar-item {
13-
margin: 5px 10px;
12+
margin: 2px 10px;
1413
}
1514

1615
.top-toolbar button {
@@ -33,7 +32,6 @@
3332
}
3433

3534
.left-toolbar {
36-
background-color: rgba(255, 255, 255, 0.8);
3735
position: fixed;
3836
display: flex;
3937
flex-direction: column;
@@ -42,7 +40,6 @@
4240
top: 150px;
4341
left: 50px;
4442
width: 100px;
45-
z-index: 10;
4643
}
4744

4845
.left-toolbar #tree-type-selector {
@@ -88,10 +85,10 @@
8885
flex-wrap: wrap;
8986
justify-content: left;
9087
width: 350px;
91-
/* height: 130px; */
88+
height: 80px;
9289
left: 50%;
93-
transform: translateX(-50%);
94-
transform-origin: center;
90+
transform: translateX(-50%) scale(0.9);
91+
transform-origin: top;
9592
}
9693
#interval-ranger {
9794
width: 110px;
@@ -100,9 +97,10 @@
10097
width: 350px;
10198
padding: 0;
10299
left: 50%;
103-
top: 130px;
104-
transform: translateX(-50%);
105-
height: 60px;
100+
top: 105px;
101+
transform: translateX(-50%) scale(0.9);
102+
transform-origin: top;
103+
height: 50px;
106104
flex-direction: row;
107105
justify-content: left;
108106
align-items: center;
@@ -134,19 +132,19 @@
134132
/* Phone */
135133
@media screen and (max-width: 376px) {
136134
.top-toolbar {
137-
width: 300px !important;
135+
width: 300px;
138136
transform: translateX(-50%) scale(0.8);
139137
}
140138
.top-toolbar-item {
141-
margin: 5px 5px;
139+
margin: 0px 5px;
142140
}
143141
#interval-ranger {
144142
width: 100px;
145143
}
146144
.left-toolbar {
147145
width: 300px;
148146
transform: translateX(-50%) scale(0.8);
149-
top: 110px;
147+
top: 90px;
150148
}
151149
.left-toolbar-item {
152150
margin: 5px 5px;
@@ -159,6 +157,7 @@
159157
/* Horizontally */
160158
@media screen and (max-height: 500px) {
161159
.left-toolbar {
160+
left: 20px;
162161
top: 100px;
163162
}
164163
.left-toolbar #tree-scale-ranger input {

src/main.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/style.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "./css/index.css";
2+
import "./css/button.css";
3+
import "./css/toolbars.css";
4+
import "./css/binnodes.css";
5+
import "./css/edges.css";

webpack.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const VueLoaderPlugin = require('vue-loader/lib/plugin');
22

33
module.exports = {
4-
entry: [__dirname + "/src/main.js"],
4+
entry: {
5+
"bundle": __dirname + "/src/app.js",
6+
"style": __dirname + "/src/style.js"
7+
},
58
output: {
69
path: __dirname + "/docs", // for github-page
7-
filename: "bundle.js"
10+
filename: "[name].js"
811
},
912
watch: true,
1013
// mode: "development",

0 commit comments

Comments
 (0)