lib/millstone.js
function localizeCartoURIs(s,cb) {
            // Get all unique URIs in stylesheet
            // TODO - avoid finding non url( uris?
            var matches = s.data.match(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi);
            var URIs = _.uniq(matches || []);
            var CartoURIs = [];
            // remove any matched urls that are not clearly
            // part of a carto style
            // TODO - consider moving to carto so we can also avoid
            // downloading commented out code
            URIs.forEach(function(u) {
                var idx = s.data.indexOf(u);
                if (idx > -1) {
                    var pre_url = s.data.slice(idx-5,idx);
                    if (pre_url.indexOf('url(') > -1) {
                        CartoURIs.push(u);
                        // Update number of async calls so that we don't
                        // call this() too soon (before everything is done)
                        remaining += 1;
                    }
                }
            });

            CartoURIs.forEach(function(u) {
                var uri = url.parse(encodeURI(u));
                // URL.
                if (uri.protocol && (uri.protocol == 'http:' || uri.protocol == 'https:')) {
                    var filepath = path.join(cache, cachepath(u));
                    localize(uri.href, {filepath:filepath,name:s.id}, function(err, file) {
                        if (err) {
                            cb(err);
                        } else {
                            var extname = path.extname(file);
                            if (!extname) {
                                readExtension(file, function(error, ext) {
                                    // note - we ignore any readExtension errors
                                    if (ext) {
                                        var new_filename = file + ext;
                                        fs.rename(file, new_filename, function(err) {
                                            s.data = s.data.split(u).join(new_filename);
                                            cb(err);
                                        });
                                    } else {
                                        s.data = s.data.split(u).join(file);
                                        cb(err);
                                    }
                                });
                            } else {
                                s.data = s.data.split(u).join(file);
                                cb(err);
                            }
                        }
                    });
                } else {
                    cb();
                }
            });
            cb();
        }
function localizeCartoURIs(s,cb) {
            // Get all unique URIs in stylesheet
            // TODO - avoid finding non url( uris?
            var matches = s.data.match(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi);
            var URIs = _.uniq(matches || []);
            var CartoURIs = [];
            // remove any matched urls that are not clearly
            // part of a carto style
            // TODO - consider moving to carto so we can also avoid
            // downloading commented out code
            URIs.forEach(function(u) {
                var idx = s.data.indexOf(u);
                if (idx > -1) {
                    var pre_url = s.data.slice(idx-5,idx);
                    if (pre_url.indexOf('url(') > -1) {
                        CartoURIs.push(u);
                        // Update number of async calls so that we don't
                        // call this() too soon (before everything is done)
                        remaining += 1;
                    }
                }
            });

            CartoURIs.forEach(function(u) {
                var uri = url.parse(encodeURI(u));
                // URL.
                if (uri.protocol && (uri.protocol == 'http:' || uri.protocol == 'https:')) {
                    var filepath = path.join(cache, cachepath(u));
                    localize(uri.href, {filepath:filepath,name:s.id}, function(err, file) {
                        if (err) {
                            cb(err);
                        } else {
                            var extname = path.extname(file);
                            if (!extname) {
                                readExtension(file, function(error, ext) {
                                    // note - we ignore any readExtension errors
                                    if (ext) {
                                        var new_filename = file + ext;
                                        fs.rename(file, new_filename, function(err) {
                                            s.data = s.data.split(u).join(new_filename);
                                            cb(err);
                                        });
                                    } else {
                                        s.data = s.data.split(u).join(file);
                                        cb(err);
                                    }
                                });
                            } else {
                                s.data = s.data.split(u).join(file);
                                cb(err);
                            }
                        }
                    });
                } else {
                    cb();
                }
            });
            cb();
        }
function localizeCartoURIs ( s , cb ) { // Get all unique URIs in stylesheet // TODO - avoid finding non url( uris? var matches = s . data . match ( / [-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)? / gi ) ; var URIs = _ . uniq ( matches || [ ] ) ; var CartoURIs = [ ] ; // remove any matched urls that are not clearly // part of a carto style // TODO - consider moving to carto so we can also avoid // downloading commented out code URIs . forEach ( function ( u ) { var idx = s . data . indexOf ( u ) ; if ( idx > - 1 ) { var pre_url = s . data . slice ( idx - 5 , idx ) ; if ( pre_url . indexOf ( 'url(' ) > - 1 ) { CartoURIs . push ( u ) ; // Update number of async calls so that we don't // call this() too soon (before everything is done) remaining += 1 ; } } } ) ; CartoURIs . forEach ( function ( u ) { var uri = url . parse ( encodeURI ( u ) ) ; // URL. if ( uri . protocol && ( uri . protocol == 'http:' || uri . protocol == 'https:' ) ) { var filepath = path . join ( cache , cachepath ( u ) ) ; localize ( uri . href , { filepath : filepath , name : s . id } , function ( err , file ) { if ( err ) { cb ( err ) ; } else { var extname = path . extname ( file ) ; if ( ! extname ) { readExtension ( file , function ( error , ext ) { // note - we ignore any readExtension errors if ( ext ) { var new_filename = file + ext ; fs . rename ( file , new_filename , function ( err ) { s . data = s . data . split ( u ) . join ( new_filename ) ; cb ( err ) ; } ) ; } else { s . data = s . data . split ( u ) . join ( file ) ; cb ( err ) ; } } ) ; } else { s . data = s . data . split ( u ) . join ( file ) ; cb ( err ) ; } } } ) ; } else { cb ( ) ; } } ) ; cb ( ) ; }
Handle URIs within the Carto CSS
Handle URIs within the Carto CSS