Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
vseventer committed Jul 19, 2015
0 parents commit e321d31
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
12 changes: 12 additions & 0 deletions .jshintrc
@@ -0,0 +1,12 @@
{
"indent" : 2,
"latedef" : true,
"newcap" : true,
"nonew" : true,
"plusplus" : true,
"quotmark" : "single",

"node": true,

"globals": { "hexo": true }
}
2 changes: 2 additions & 0 deletions .npmignore
@@ -0,0 +1,2 @@
test/
.jshintrc
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,4 @@
# Changelog

## 0.1.0 (July 19, 2015)
* Initial version.
21 changes: 21 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Mark van Seventer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
@@ -0,0 +1,47 @@
# more-css plugin for [Hexo](https://hexo.io)
> Compress CSS with [more-css](https://www.npmjs.com/package/more-css).
## Install
```bash
$ npm install hexo-more-css --save
```

## Options
You can configure this plugin in `_config.yml`.

```yaml
more_css:
enabled : true
exclude : *.min.css
radical : true
```

- **enabled** - Enable the plugin. Defaults to `true`.
- **exclude** - Exclude files.
- **radical** - Apply further minimization. Defaults to `true`.

## Changelog
See the [Changelog](./CHANGELOG.md) for a list of changes.

## License
The MIT License (MIT)

Copyright (c) 2015 Mark van Seventer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
42 changes: 42 additions & 0 deletions index.js
@@ -0,0 +1,42 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Mark van Seventer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/

// Strict mode.
'use strict';

// Package modules.
var assign = require('object-assign');

// Local modules.
var filter = require('./lib/filter.js');

// Configure.
hexo.config.more_css = assign({
enabled : true,
exclude : [ '*.min.css' ],
radical : true
}, hexo.config.more_css);

// Register the filter.
hexo.extend.filter.register('after_render:css', filter);
58 changes: 58 additions & 0 deletions lib/filter.js
@@ -0,0 +1,58 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Mark van Seventer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/

// Strict mode.
'use strict';

// Package modules.
var minimatch = require('minimatch'),
moreCss = require('more-css');

// Exports.
module.exports = function(str, locals) {
// Init.
var hexo = this,
config = hexo.config.more_css,
exclude = config.exclude;

// Return original if disabled.
if(false === config.enabled) {
return str;
}

// Format exclusion patterns.
if(!Array.isArray(exclude)) {
exclude = [ exclude ];
}

// Return original if the file was excluded.
for(var i = 0; i < exclude.length; i += 1) {
if(minimatch(locals.path, exclude[i])) {
return str;
}
}

// Return the result.
return moreCss.compress(str, config.radical);
};
27 changes: 27 additions & 0 deletions package.json
@@ -0,0 +1,27 @@
{
"name" : "hexo-more-css",
"version" : "0.1.0-dev",
"description" : "more-css plugin for Hexo.",
"keywords" : [ "hexo", "more-css", "plugin" ],
"homepage" : "https://github.com/vseventer/hexo-more-css",
"bugs" : "https://github.com/vseventer/hexo-more-css/issues",
"license" : "MIT",
"author" : "Mark van Seventer <mark@vseventer.com>",
"repository" : { "type": "git", "url": "vseventer/hexo-more-css" },
"main" : "./index.js",
"scripts" : {
"pretest" : "./node_modules/.bin/jshint --reporter=./node_modules/jshint-stylish lib/ test/ *.js",
"test" : "./node_modules/.bin/mocha test/"
},
"dependencies": {
"minimatch" : "2.0.x",
"more-css" : "0.12.x",
"object-assign" : "3.0.x"
},
"devDependencies": {
"jshint" : "2.8.x",
"jshint-stylish": "2.0.x",
"mocha" : "2.2.x"
},
"engines": { "node" : ">=0.10.x" }
}
16 changes: 16 additions & 0 deletions test/.jshintrc
@@ -0,0 +1,16 @@
{
"indent" : 2,
"latedef" : true,
"newcap" : true,
"nonew" : true,
"plusplus" : true,
"quotmark" : "single",

"node": true,

"globals": {
"describe" : true,
"expect" : true,
"it" : true
}
}
76 changes: 76 additions & 0 deletions test/filter.test.js
@@ -0,0 +1,76 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Mark van Seventer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/

// Strict mode.
'use strict';

// Local modules.
var subject = require('../lib/filter.js');

// Test suite.
describe('hexo-more-css', function() {
// Tests.
it('should compress CSS.', function() {
// Configure.
var data = 'div { color: black }';
var hexo = {
config: {
more_css: { exclude: [ ] }
}
};

// Filter and test.
var result = subject.call(hexo, data, { path: '123' });
var expected = 'div{color:#000}';
console.assert(result === expected);
});

it('should exclude files.', function() {
// Configure.
var data = 'div { color: black }';
var hexo = {
config: {
more_css: { exclude: '**' }
}
};

// Filter and test.
var result = subject.call(hexo, data, { path: '123' });
console.assert(result === data);
});

it('should do nothing if disabled.', function() {
// Configure.
var data = 'div { color: black }';
var hexo = {
config: {
more_css: { enabled: false, exclude: [ ] }
}
};

// Filter and test.
var result = subject.call(hexo, data, { path: '123' });
console.assert(result === data);
});
});
5 changes: 5 additions & 0 deletions test/mocha.opts
@@ -0,0 +1,5 @@
--check-leaks
--no-exit
--reporter spec
--timeout 100
--ui bdd

0 comments on commit e321d31

Please sign in to comment.