index.js 676 B

12345678910111213141516171819202122
  1. var less = require('less'),
  2. path = require('path');
  3. hexo.extend.renderer.register('less', 'css', function(data, options, callback){
  4. var themeConfig = hexo.theme.config.less || {};
  5. var cwd = process.cwd();
  6. var paths = (themeConfig.paths || []).map(function(filepath){
  7. return path.join(cwd, filepath); // assuming paths are relative from the root of the project
  8. });
  9. var parser = less.render(data.text, {
  10. paths: paths.concat(path.dirname(data.path)),
  11. filename: path.basename(data.path),
  12. compress: themeConfig.compress || false
  13. })
  14. .then(function(output) {
  15. callback(null, output.css);
  16. },
  17. function(error){
  18. callback(error);
  19. });
  20. });