GithubHelp home page GithubHelp logo

nonpolynomial / firstspiritify Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 8 KB

Module to replace URL references in CSS files with FirstSpirit `$CMS_REF(media:"", abs: 0)$` function calls

License: MIT License

JavaScript 92.72% CSS 7.28%
css css-files firstspirit

firstspiritify's Introduction

Firstspiritify

yargs mkdirp

Module to replace URL references in CSS files with FirstSpirit $CMS_REF(media:"", abs: 0)$ function calls.

Pattern

Firstspiritify searches for url\(['"]?([\w-_ ./]*\.[\w-_ ]*)['"]?\) and removes all spaces and dots (.) and replaces hyphens (-) with underscores (_).

firstspiritify's People

Contributors

nonpolynomial avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

maltemuth

firstspiritify's Issues

urls like myfont.eot?#iefix are not recognized

If using e.g. font-awesome, there are quite a few font URLs that end in with #suffix or even ?#suffix. firstspiritify won't replace these URLs as the corresponding regex does not match these strings.

The fix could be like this:

const path = require('path');
 
module.exports = ({str, abs = 0}) =>
str.replace(/url\(['"]?([\w-_ ./]*\.[\w-_ ]*)([\?\#a-zA-Z]*)['"]?\)/g, (matches, file, suffix) =>
`url("\$CMS_REF(media:"${path.parse(file).name.replace(/(-| |\.)/g, (m) => {
switch(m) {
case ' ':
case '.':
return '';
case '-':
return '_';
}
})}", abs: ${abs})\$${suffix}")`
);

Release 0.1

Since this module is already in production use, it should have a release.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.