mirror of
https://github.com/danog/inline-critical.git
synced 2024-11-30 04:29:07 +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) => {
|
links.map((link) => {
|
||||||
if (o.extract) {
|
if (o.extract) {
|
||||||
const href = link.getAttribute('href');
|
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)) {
|
for (const file of files) {
|
||||||
const orig = fs.readFileSync(file);
|
if (fs.existsSync(file)) {
|
||||||
const diff = extractCss(orig, inlined, o.minify);
|
const orig = fs.readFileSync(file);
|
||||||
const filename = reaver.rev(file, diff);
|
const diff = extractCss(orig, inlined, o.minify);
|
||||||
|
const filename = reaver.rev(file, diff);
|
||||||
|
|
||||||
fs.writeFileSync(filename, diff);
|
fs.writeFileSync(filename, diff);
|
||||||
link.setAttribute('href', normalizePath(reaver.rev(href, diff)));
|
link.setAttribute('href', normalizePath(reaver.rev(href, diff)));
|
||||||
} else if (!/\/\//.test(href)) {
|
// 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.`);
|
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));
|
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 () => {
|
test('Inline css with media=print', async () => {
|
||||||
const html = await read('fixtures/index.html');
|
const html = await read('fixtures/index.html');
|
||||||
const css = await read('fixtures/critical.css');
|
const css = await read('fixtures/critical.css');
|
||||||
|
Loading…
Reference in New Issue
Block a user