diff --git a/package-lock.json b/package-lock.json index 74ea45a..7daf787 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "jimp": "^0.16.1", "lru-cache": "^7.14.0", "mysql": "^2.18.1", + "uglify-js": "^3.17.0", "unsafe_encrypt": "^1.0.4", "ws": "^8.8.1" } @@ -1755,6 +1756,17 @@ "node": ">= 0.6" } }, + "node_modules/uglify-js": { + "version": "3.17.0", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.0.tgz", + "integrity": "sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg==", + "bin": { + "uglifyjs": "bin/uglifyjs" + }, + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/uid-safe": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", @@ -3199,6 +3211,11 @@ "mime-types": "~2.1.24" } }, + "uglify-js": { + "version": "3.17.0", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.0.tgz", + "integrity": "sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg==" + }, "uid-safe": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", diff --git a/package.json b/package.json index 6a95165..cf8c8fe 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "jimp": "^0.16.1", "lru-cache": "^7.14.0", "mysql": "^2.18.1", + "uglify-js": "^3.17.0", "unsafe_encrypt": "^1.0.4", "ws": "^8.8.1" }, diff --git a/server.js b/server.js index 9586271..7707d07 100644 --- a/server.js +++ b/server.js @@ -834,13 +834,23 @@ import LRU from "lru-cache" ejs.cache = new LRU({max:20}) +function load_var(fina) { + let out = readFileSync(fina) + if(fina.endsWith(".js")) { + return min_js(out.toString()).code + } + return out +} + +import {minify as min_js} from "uglify-js" + const global_page_variables = { - globalcss: readFileSync("./css/global.css"), - httppostjs: readFileSync("./js/httppost.js"), - addnavbar: readFileSync("./js/addnavbar.js"), - markdownjs: readFileSync("./js/markdown.js"), - htmlescapejs: readFileSync("./js/htmlescape.js"), - warnmessagejs: readFileSync("./js/warn_message.js") + globalcss: load_var("./css/global.css"), + httppostjs: load_var("./js/httppost.js"), + addnavbar: load_var("./js/addnavbar.js"), + markdownjs: load_var("./js/markdown.js"), + htmlescapejs: load_var("./js/htmlescape.js"), + warnmessagejs: load_var("./js/warn_message.js") } router.get("/*", async function(request, response) { diff --git a/views/posts.html b/views/posts.html index 17af243..cd9211b 100644 --- a/views/posts.html +++ b/views/posts.html @@ -6,7 +6,7 @@ - + @@ -39,6 +39,6 @@
- +