Simple grunt plugin for shortening URLs in HTML files
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-short-url --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-short-url');
This grunt task uses bitly's api for shortening URLs.
Type: Object
{
username: 'your username',
password: 'your password',
client_id: 'your client id',
client_secret: 'your client secret'
}
If you know your access token, you can add access_token: 'your access token'
and remove the username and password properties.
Type: Object
Default:
{
'a[href]': 'href',
'img[src]': 'src',
'link[rel=stylesheet]': 'href',
'script[src]': 'src'
}
Any HTML element matching these CSS selectors will have their attribute, specified in value, shortened.
grunt.initConfig({
shorturl: {
yourTarget: {
options:
{
bitly: {
username: 'your username',
password: 'your password',
client_id: 'your client id',
client_secret: 'your client secret'
},
html: {
'a[href]': 'href',
'img[src]': 'src',
}
},
// HTML files
files:
[{
src: 'src/*.html',
dest: 'dest/'
}]
}
}
});