postcss / postcss-url

PostCSS plugin to rebase url(), inline or copy asset.
MIT License
376 stars 58 forks source link

Custom Hash Function #44

Closed blond closed 7 years ago

blond commented 9 years ago

I need to use custom hash-function for useHash: true option.

To copy images with unique names to a folder I used borschik with freeze option.

Hash-function in borschik different from hash-function in this package.

Let's do hashFunction option?

By Default:

hashFunction: function (contents) {
    return crypto.createHash('sha1')
      .update(contents)
      .digest('hex')
      .substr(0, 16);
}

For borschik:

hashFunction: function (contents) {
    return crypto.createHash('sha1')
        .update(contents)
        .digest('base64')
        .replace(/\+/g, '-')
        .replace(/\//g, '_')
        .replace(/=/g, '')
        .replace(/^[+-]+/g, '');
}
tadatuta commented 9 years ago

:+1:

SwinX commented 9 years ago

:+1:

arikon commented 9 years ago

:fire:

arikon commented 9 years ago

@blond You should make a PR ;)

sipayRT commented 9 years ago

:+1:

tadatuta commented 9 years ago

@moox @ben-eb @truesound how can we help to seed up this issue? It's quite important for Yandex!

ben-eb commented 9 years ago

How about being able to pass a function to the existing useHash option? PR welcome.

MoOx commented 9 years ago

Also https://github.com/postcss/postcss-url/issues/43#issuecomment-133676539

tinchoz49 commented 9 years ago

Hi guys! i created a new plugin to export the copy method and add new features, one of them is the ability to use a custom has function: https://github.com/geut/postcss-copy

tadatuta commented 9 years ago

@tinchoz49 Thank you! We'll give it a try!

sergcen commented 7 years ago

Added in v6 release