Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't download URLs end with ?... #467

Open
WinterSilence opened this issue Nov 3, 2021 · 1 comment
Open

Can't download URLs end with ?... #467

WinterSilence opened this issue Nov 3, 2021 · 1 comment

Comments

@WinterSilence
Copy link

Links contain version passed by GET parameter: <link href="/themes/mastershop/mastershop.css?v2.4.2.150" rel="stylesheet"><link href="/plugins/productsets/css/frontend.min.css?2.5.4" rel="stylesheet">. uncss can't download that's files. How fix it?

@WinterSilence
Copy link
Author

WinterSilence commented Nov 3, 2021

Solution

if (src && path.isAbsolute(src)) {

replace path.isAbsolute(src) to isURL(src)

const uncss = require('uncss');
const fs = require('fs');
const files = ['https://site.com/foo/', 'https://site.com/bar/'];
const options = {
    banner: false,
    csspath: 'https://site.com',
    htmlroot: 'https://site.com',
    ignoreSheets : [
        /fonts\.googleapis/,
        /fontawesome\.com/
    ],
    inject: function(window) {
        window.document.querySelectorAll('[href],[src]').forEach(function(tag) {
            const attributeName = tag.hasAttribute('href') ? 'href' : 'src';
            let attributeValue = tag.getAttribute(attributeName);
            if (attributeValue.indexOf('?') !== -1) {
                tag.setAttribute(attributeName, attributeValue.split('?')[0]);
            }
        });
    },
    timeout: 1200,
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0'
    // Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)
};
uncss(files, options, function (error, output) {
    fs.writeFileSync('optimized.css', output);
    if (error) {
        console.err(error);
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant