secure-scuttlebot classic

decent improvements

Changed files
+80 -18
decent
plugins
+6 -1
decent/modules_core/app.js
··· 6 gives: 'app', 7 create: function (api) { 8 return function () { 9 - document.head.appendChild(h('style', require('../style.css.json'))) 10 11 window.addEventListener('error', window.onError = function (e) { 12 document.body.appendChild(h('div.error',
··· 6 gives: 'app', 7 create: function (api) { 8 return function () { 9 + var hasStylesheet = document.querySelector('link[rel="stylesheet"][href$="style.css"]') 10 + if (!hasStylesheet) { 11 + document.head.appendChild( 12 + h('style', {'data-decent-style': 'true'}, require('../style.css.json')) 13 + ) 14 + } 15 16 window.addEventListener('error', window.onError = function (e) { 17 document.body.appendChild(h('div.error',
+1 -1
decent/package.json
··· 62 "indexhtmlify": "^1.3.1" 63 }, 64 "scripts": { 65 - "lite": "node scripts/style.js && mkdir -p build && browserify index.js | indexhtmlify --title \"Decent SSB\" > build/index.html", 66 "bundle": "node scripts/style.js && mkdir -p build && browselectrify index.js > build/bundle.js", 67 "graph": "node index.js | dot -Tsvg > graph.svg", 68 "test": "set -e; for t in test/*.js; do node $t; done"
··· 62 "indexhtmlify": "^1.3.1" 63 }, 64 "scripts": { 65 + "lite": "node scripts/style.js && mkdir -p build && browserify index.js | indexhtmlify --title \"Decent SSB\" > build/index.html && node scripts/postprocess-index.js", 66 "bundle": "node scripts/style.js && mkdir -p build && browselectrify index.js > build/bundle.js", 67 "graph": "node index.js | dot -Tsvg > graph.svg", 68 "test": "set -e; for t in test/*.js; do node $t; done"
+27
decent/scripts/postprocess-index.js
···
··· 1 + var fs = require('fs') 2 + var path = require('path') 3 + 4 + var htmlPath = path.join(__dirname, '..', 'build', 'index.html') 5 + if (!fs.existsSync(htmlPath)) process.exit(0) 6 + 7 + var html = fs.readFileSync(htmlPath, 'utf8') 8 + if (html.indexOf('decent-preload') !== -1) process.exit(0) 9 + 10 + var headClose = html.indexOf('</head>') 11 + if (headClose === -1) process.exit(0) 12 + 13 + var insert = [ 14 + '<!-- decent-preload -->', 15 + '<link rel="preconnect" href="https://fonts.googleapis.com">', 16 + '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>', 17 + '<link rel="preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css">', 18 + '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css">', 19 + '<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,400,0,0">', 20 + '<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,400,0,0">', 21 + '<link rel="preload" as="style" href="/style.css">', 22 + '<link rel="stylesheet" href="/style.css">' 23 + ].join('\n') + '\n' 24 + 25 + html = html.slice(0, headClose) + insert + html.slice(headClose) 26 + 27 + fs.writeFileSync(htmlPath, html)
+11 -1
decent/scripts/style.js
··· 1 var fs = require('fs') 2 var path = require('path') 3 4 fs.writeFileSync( 5 path.join(__dirname, '..', 'style.css.json'), 6 - JSON.stringify(fs.readFileSync(path.join(__dirname, '..', 'style.css'), 'utf8')) 7 ) 8
··· 1 var fs = require('fs') 2 var path = require('path') 3 4 + var buildDir = path.join(__dirname, '..', 'build') 5 + var stylePath = path.join(__dirname, '..', 'style.css') 6 + 7 + if (!fs.existsSync(buildDir)) 8 + fs.mkdirSync(buildDir) 9 + 10 fs.writeFileSync( 11 path.join(__dirname, '..', 'style.css.json'), 12 + JSON.stringify(fs.readFileSync(stylePath, 'utf8')) 13 ) 14 15 + fs.writeFileSync( 16 + path.join(buildDir, 'style.css'), 17 + fs.readFileSync(stylePath, 'utf8') 18 + )
-3
decent/style.css
··· 1 - @import url('https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css'); 2 - @import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,400,0,0'); 3 - 4 * { 5 box-sizing: border-box; 6 word-break: break-word;
··· 1 * { 2 box-sizing: border-box; 3 word-break: break-word;
+35 -12
plugins/decent-ui.js
··· 105 } 106 107 var filePath = path.join(decentDir, relPath) 108 - fs.stat(filePath, function (err, stat) { 109 - if (err || !stat || !stat.isFile()) { 110 - respondNotFound(res) 111 - return 112 - } 113 - 114 if (relPath === 'index.html' && req.method === 'GET') { 115 - return fs.readFile(filePath, 'utf8', function (readErr, html) { 116 if (readErr) { 117 respondNotFound(res) 118 return 119 } 120 121 var remote = getRemoteForRequest(req) 122 if (remote) { 123 - var script = '<script>window.PATCHBAY_REMOTE = ' + 124 JSON.stringify(remote) + 125 ';</script>' 126 - html = html.replace('</head>', script + '</head>') 127 } 128 129 - res.writeHead(200, {'Content-Type': getContentType(filePath)}) 130 res.end(html) 131 }) 132 } 133 134 - res.writeHead(200, {'Content-Type': getContentType(filePath)}) 135 136 if (req.method === 'HEAD') { 137 res.end() 138 return 139 } 140 141 - fs.createReadStream(filePath).pipe(res) 142 }) 143 } 144
··· 105 } 106 107 var filePath = path.join(decentDir, relPath) 108 + function serveFile (resolvedPath) { 109 if (relPath === 'index.html' && req.method === 'GET') { 110 + return fs.readFile(resolvedPath, 'utf8', function (readErr, html) { 111 if (readErr) { 112 respondNotFound(res) 113 return 114 } 115 116 + var headInsert = '' 117 + if (html.indexOf('rel="stylesheet" href="/style.css"') === -1 && 118 + html.indexOf('rel="stylesheet" href="style.css"') === -1) { 119 + headInsert += '<link rel="preload" as="style" href="/style.css">' + 120 + '<link rel="stylesheet" href="/style.css">' 121 + } 122 + 123 var remote = getRemoteForRequest(req) 124 if (remote) { 125 + headInsert += '<script>window.PATCHBAY_REMOTE = ' + 126 JSON.stringify(remote) + 127 ';</script>' 128 } 129 130 + if (headInsert) 131 + html = html.replace('</head>', headInsert + '</head>') 132 + 133 + res.writeHead(200, {'Content-Type': getContentType(resolvedPath)}) 134 res.end(html) 135 }) 136 } 137 138 + res.writeHead(200, {'Content-Type': getContentType(resolvedPath)}) 139 140 if (req.method === 'HEAD') { 141 res.end() 142 return 143 } 144 145 + fs.createReadStream(resolvedPath).pipe(res) 146 + } 147 + 148 + fs.stat(filePath, function (err, stat) { 149 + if (err || !stat || !stat.isFile()) { 150 + if (relPath === 'style.css') { 151 + var fallbackPath = path.join(__dirname, '..', 'decent', 'style.css') 152 + return fs.stat(fallbackPath, function (fallbackErr, fallbackStat) { 153 + if (fallbackErr || !fallbackStat || !fallbackStat.isFile()) { 154 + respondNotFound(res) 155 + return 156 + } 157 + serveFile(fallbackPath) 158 + }) 159 + } 160 + respondNotFound(res) 161 + return 162 + } 163 + 164 + serveFile(filePath) 165 }) 166 } 167