mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-10 07:38:24 +01:00
add bundle app.js :3
This commit is contained in:
parent
6660b2902b
commit
355e721c6f
1 changed files with 29 additions and 7 deletions
|
@ -112,10 +112,30 @@ module.exports = function (app, config, renderTemplate) {
|
|||
}
|
||||
});
|
||||
|
||||
app.get("/static/:id", (req, res) => {
|
||||
if (req.params.id.endsWith(".css")) {
|
||||
res.redirect("/css/" + req.params.id);
|
||||
} else if (req.params.id.endsWith(".js")) {
|
||||
app.get("/static/:id", (req, res) => {
|
||||
if (req.params.id.endsWith(".css")) {
|
||||
res.redirect("/css/" + req.params.id);
|
||||
} else if (req.params.id.endsWith(".js")) {
|
||||
if (req.params.id.endsWith(".bundle.js")) {
|
||||
// Define the paths to the three input JavaScript files
|
||||
const file1Path = path.join(html_location, 'app.js');
|
||||
const file2Path = path.join(html_location, 'custom-css.js');
|
||||
const file3Path = path.join(html_location, 'emojis.js');
|
||||
|
||||
// Read the contents of the three input files
|
||||
const file1Content = fs.readFileSync(file1Path, 'utf-8');
|
||||
const file2Content = fs.readFileSync(file2Path, 'utf-8');
|
||||
const file3Content = fs.readFileSync(file3Path, 'utf-8');
|
||||
|
||||
// Combine the contents of the three files
|
||||
const combinedContent = `${file1Content}\n${file2Content}\n${file3Content}`;
|
||||
|
||||
// Serve the combined content as JavaScript
|
||||
res.header("Content-Type", "text/javascript");
|
||||
const minimizedJs = require("uglify-js").minify(combinedContent).code;
|
||||
res.send("// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" + `\n` + `// Includes app.js, emojis.js and custom-css.js. source code can be found for these 3 files in https://codeberg.org/Ashley/poketube/src/branch/main/css/` +
|
||||
`\n` + minimizedJs + `\n` +"// @license-end");
|
||||
} else {
|
||||
const filePath = path.join(html_location, req.params.id);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
res.status(404).send("File not found");
|
||||
|
@ -135,8 +155,10 @@ module.exports = function (app, config, renderTemplate) {
|
|||
`\n` +
|
||||
"// @license-end"
|
||||
);
|
||||
} else {
|
||||
res.sendFile(req.params.id, { root: html_location });
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.sendFile(req.params.id, { root: html_location });
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue