From cf43fc1a6936d3083532d179486ca1650e36af49 Mon Sep 17 00:00:00 2001 From: blanxi Date: Fri, 1 Jul 2022 06:08:57 +0200 Subject: [PATCH] feature(MultipleCssFiles) #22 Concat all custom styles to a single (#26) * feature(MultipleCssFiles) #22 Concat all custom styles to a single `; + return new CleanCss().minify(data).styles; }; try { if (src.indexOf('//') === -1) { path = `${options.cwd}/${src}`; if (fs.existsSync(path)) { - file = setFile(String(fs.readFileSync(path))); + inlineCss += setFile(String(fs.readFileSync(path))); } } else if (src.indexOf('//') !== -1) { - const response = responses[src]; - if (response === true) { - throw new Error('No CSS for', src); - } - file = setFile(response.data); + inlineCss += setFile(String(request('GET', path).body)); } } catch (err) { console.dir(err); } - $(element).replaceWith(file); + $(element).remove(); }); + if (inlineCss !== '') { + $('head').append(``); + } + /* youtube */ $('iframe[src*="http://www.youtube.com"],iframe[src*="https://www.youtube.com"],iframe[src*="http://youtu.be/"],iframe[src*="https://youtu.be/"]').each((index, element) => { youtube = true; diff --git a/test/styles.test.js b/test/styles.test.js index d80b18d..30cd3d6 100644 --- a/test/styles.test.js +++ b/test/styles.test.js @@ -4,8 +4,15 @@ const assert = require('./assert'); describe('inline styles', () => { test('should inject inline css into style tag', () => { assert( - '', - '', + '', + '', + { cwd: __dirname.split(path.sep).pop() }, + ); + }); + test('should inject inline css into style tag on multiple files', () => { + assert( + '', + '', { cwd: __dirname.split(path.sep).pop() }, ); }); diff --git a/test/styles1.css b/test/styles1.css new file mode 100644 index 0000000..b337be7 --- /dev/null +++ b/test/styles1.css @@ -0,0 +1,3 @@ +footer { + background-color: #FFF; +}