greglebreton 4e8a693745
Some checks failed
continuous-integration/drone/push Build is failing
add garagenum exp + maj url site projets
2023-01-08 16:50:31 +01:00

33 lines
603 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = minifyJson;
/* Minify JSON inside <script> tags */
function minifyJson(tree) {
// Match all <script> tags which have JSON mime type
tree.match({
tag: 'script',
attrs: {
type: /(\/|\+)json/
}
}, node => {
let content = (node.content || []).join('');
if (!content) {
return node;
}
try {
content = JSON.stringify(JSON.parse(content));
} catch (error) {
return node;
}
node.content = [content];
return node;
});
return tree;
}