mirror of
https://github.com/danog/inline-critical.git
synced 2024-11-26 12:04:38 +01:00
Try fixing query string stylesheets
This commit is contained in:
parent
b12a0dad33
commit
972f0d2ace
23
index.js
23
index.js
@ -148,16 +148,23 @@ function inline(html, styles, options) {
|
||||
links.map((link) => {
|
||||
if (o.extract) {
|
||||
const href = link.getAttribute('href');
|
||||
const file = path.resolve(path.join(o.basePath || process.cwd, href));
|
||||
const fileOrig = path.resolve(path.join(o.basePath || process.cwd, href));
|
||||
const files = [fileOrig, fileOrig.replace(/\?.*/, '')];
|
||||
|
||||
if (fs.existsSync(file)) {
|
||||
const orig = fs.readFileSync(file);
|
||||
const diff = extractCss(orig, inlined, o.minify);
|
||||
const filename = reaver.rev(file, diff);
|
||||
for (const file of files) {
|
||||
if (fs.existsSync(file)) {
|
||||
const orig = fs.readFileSync(file);
|
||||
const diff = extractCss(orig, inlined, o.minify);
|
||||
const filename = reaver.rev(file, diff);
|
||||
|
||||
fs.writeFileSync(filename, diff);
|
||||
link.setAttribute('href', normalizePath(reaver.rev(href, diff)));
|
||||
} else if (!/\/\//.test(href)) {
|
||||
fs.writeFileSync(filename, diff);
|
||||
link.setAttribute('href', normalizePath(reaver.rev(href, diff)));
|
||||
// eslint-disable-next-line array-callback-return
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!/\/\//.test(href)) {
|
||||
throw new Error(`Error: file "${href}" not found in "${o.basePath || process.cwd}". Specify base path.`);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,14 @@ test('Inline css', async () => {
|
||||
expect(strip(out.toString())).toBe(strip(expected));
|
||||
});
|
||||
|
||||
test('Inline css with query string link', async () => {
|
||||
const html = await read('fixtures/index-query.html');
|
||||
const css = await read('fixtures/critical.css');
|
||||
const expected = await read('expected/index-inlined-async-query.html');
|
||||
const out = inline(html, css, {minify: false, polyfill: true});
|
||||
expect(strip(out.toString())).toBe(strip(expected));
|
||||
});
|
||||
|
||||
test('Inline css with media=print', async () => {
|
||||
const html = await read('fixtures/index.html');
|
||||
const css = await read('fixtures/critical.css');
|
||||
|
Loading…
Reference in New Issue
Block a user