Split up customJS into customHTML and customJS for better organisation (#5981)
* WIP * fixed customJS not actually working in footer * Moving scripts to footer, #5980 * Added upgrade scripts for #5980v1.18.x
parent
a1a87c7ca1
commit
cd6dcff38b
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
var meta = require('../../meta');
|
||||
|
||||
module.exports = {
|
||||
name: 'Generate customHTML block from old customJS setting',
|
||||
timestamp: Date.UTC(2017, 9, 12),
|
||||
method: function (callback) {
|
||||
var newHTML = meta.config.customJS;
|
||||
var newJS = [];
|
||||
|
||||
// Forgive me for parsing HTML with regex...
|
||||
var scriptMatch = /^<script\s?(?!async|deferred)?>([\s\S]+?)<\/script>/m;
|
||||
var match = scriptMatch.exec(newHTML);
|
||||
|
||||
while (match) {
|
||||
if (match[1]) {
|
||||
// Append to newJS array
|
||||
newJS.push(match[1].trim());
|
||||
|
||||
// Remove the match from the existing value
|
||||
newHTML = ((match.index > 0 ? newHTML.slice(0, match.index) : '') + newHTML.slice(match.index + match[0].length)).trim();
|
||||
}
|
||||
|
||||
match = scriptMatch.exec(newHTML);
|
||||
}
|
||||
|
||||
// Combine newJS array
|
||||
newJS = newJS.join('\n\n');
|
||||
|
||||
// Write both values to config
|
||||
meta.configs.setMultiple({
|
||||
customHTML: newHTML,
|
||||
customJS: newJS,
|
||||
}, callback);
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue