├── .npmrc ├── test ├── mocha.opts └── index.js ├── .npmignore ├── .gitignore ├── index.js ├── package.json ├── lib └── renderer.js ├── .travis.yml ├── CHANGELOG.md ├── README.md └── .github └── workflows └── codeql-analysis.yml /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | .DS_Store 3 | coverage 4 | test 5 | .travis.yml -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | .idea 4 | 5 | package-lock.json 6 | yarn.lock -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* global hexo */ 2 | 'use strict' 3 | 4 | var sassRenderer = require('./lib/renderer') 5 | 6 | // associate the Sass renderer with .scss AND .sass extensions 7 | hexo.extend.renderer.register('scss', 'css', sassRenderer('scss')) 8 | hexo.extend.renderer.register('sass', 'css', sassRenderer('sass')) 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hexo-renderer-sass", 3 | "version": "0.5.0", 4 | "description": "Sass renderer plugin for Hexo", 5 | "main": "index", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/knksmith57/hexo-renderer-sass.git" 9 | }, 10 | "keywords": [ 11 | "hexo", 12 | "sass", 13 | "scss", 14 | "renderer" 15 | ], 16 | "author": "Kyle Smith ", 17 | "license": "MIT", 18 | "scripts": { 19 | "lint": "standard", 20 | "test": "mocha test/index.js", 21 | "test-cov": "istanbul cover --print both _mocha -- test/index.js" 22 | }, 23 | "engines": { 24 | "node": ">= 6" 25 | }, 26 | "dependencies": { 27 | "sass": "^1.41.1" 28 | }, 29 | "peerDependencies": { 30 | "hexo": ">= 3" 31 | }, 32 | "devDependencies": { 33 | "chai": "^3.5.0", 34 | "istanbul": "^0.4.5", 35 | "mocha": "^9.1.3", 36 | "standard": "^16.0.4" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/renderer.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var sass = require('sass') 4 | var extend = require('util')._extend 5 | 6 | module.exports = (ext) => function (data) { 7 | // support global and theme-specific config 8 | var userConfig = extend( 9 | this.theme.config.node_sass || {}, 10 | this.config.node_sass || {} 11 | ) 12 | 13 | var config = extend({ 14 | data: data.text, 15 | file: data.path, 16 | outputStyle: 'expanded', 17 | sourceComments: false, 18 | indentedSyntax: (ext === 'sass') 19 | }, userConfig) 20 | 21 | try { 22 | // node-sass result object: 23 | // https://github.com/sass/node-sass#result-object 24 | var result = sass.renderSync(config) 25 | // result is now Buffer instead of String 26 | // https://github.com/sass/node-sass/issues/711 27 | return result.css.toString() 28 | } catch (error) { 29 | console.error(error.toString()) 30 | throw error 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | sudo: false 4 | 5 | cache: 6 | apt: true 7 | directories: 8 | - node_modules 9 | 10 | # track upstream node_js matrix: 11 | # - https://github.com/hexojs/hexo/blob/master/.travis.yml 12 | # - https://github.com/sass/node-sass/blob/master/.travis.yml 13 | node_js: 14 | - "6" 15 | - "8" 16 | - "10" 17 | - "node" 18 | 19 | addons: 20 | apt: 21 | sources: 22 | - ubuntu-toolchain-r-test 23 | packages: 24 | - gcc-4.7 25 | - g++-4.7 26 | - gcc-4.9 27 | - g++-4.9 28 | 29 | # https://github.com/sass/node-sass/blob/0c31dc2/.travis.yml#L73-L88 30 | before_install: 31 | - npm config set python `which python` 32 | - if [ $TRAVIS_OS_NAME == "linux" ]; then 33 | if [[ $(node -v) =~ v1[01] ]]; then 34 | export CC="gcc-4.9"; 35 | export CXX="g++-4.9"; 36 | export LINK="gcc-4.9"; 37 | export LINKXX="g++-4.9"; 38 | else 39 | export CC="gcc-4.7"; 40 | export CXX="g++-4.7"; 41 | export LINK="gcc-4.7"; 42 | export LINKXX="g++-4.7"; 43 | fi 44 | fi 45 | 46 | script: 47 | - npm run lint 48 | - npm run test-cov 49 | 50 | after_script: 51 | - npm install coveralls 52 | - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | #### 0.3.2 (2017-6-15) 2 | 3 | ##### Chores 4 | 5 | * **travis:** replace 7 by latest node version ([58b6dbbd](https://github.com/knksmith57/hexo-renderer-sass/commit/58b6dbbdbefe675040e33377ce1681afb54d5338)) 6 | * **package:** upgrade node-sass to version 4.5.3 ([610157e3](https://github.com/knksmith57/hexo-renderer-sass/commit/610157e39f8bafe44988b63795339bdb87b4c3e7)) 7 | 8 | #### 0.3.1 (2017-2-24) 9 | 10 | ##### Chores 11 | 12 | * **package:** license field should be a string ([430bd883](https://github.com/knksmith57/hexo-renderer-sass/commit/430bd883a03b10a01d9cdc0e49b99cbf7fcea10c)) 13 | 14 | ##### Bug Fixes 15 | 16 | * **main:** hotfix hexo undefined regression This regression is introduced at f9a2ef62c9cf480f1fc3d757de57fd06b93cc164 due to the fact that `hexo` is not in global namespace. Here is a dirty hotfix and we will drop hexo 2.x support to migrate to new plugin syntax. ([da181f29](https://github.com/knksmith57/hexo-renderer-sass/commit/da181f29c1690e7e4178de8b2ddedd8ac4723ce1)) 17 | 18 | ## 0.3.0 (2017-2-24) 19 | 20 | Breaking changes: this version drops node.js 0.12 support. 21 | 22 | ### node-sass 23 | - Bump `node-sass` version to 4.0 (#22) 24 | 25 | ### packages 26 | - Add yarn lockfile (#20) 27 | - Add engine requirement (#27) 28 | 29 | ### test 30 | - Add eslint (#23) 31 | - Add travis (#24) 32 | - Use standard code style (#25) 33 | - Better support on `sass` format (#28) 34 | 35 | ## 0.2.0 (2015-9-28) 36 | 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [Sass] renderer plugin for [Hexo] 2 | ================================= 3 | 4 | [![npm version](https://badge.fury.io/js/hexo-renderer-sass.svg)](https://badge.fury.io/js/hexo-renderer-sass) 5 | [![Build Status](https://travis-ci.org/knksmith57/hexo-renderer-sass.svg?branch=master)](https://travis-ci.org/knksmith57/hexo-renderer-sass) 6 | [![Coverage Status](https://coveralls.io/repos/github/knksmith57/hexo-renderer-sass/badge.svg?branch=master)](https://coveralls.io/github/knksmith57/hexo-renderer-sass?branch=master) 7 | 8 | > A hexo plugin for node-sass 9 | 10 | ## Install 11 | ```sh 12 | $ npm install --save hexo-renderer-sass 13 | ``` 14 | 15 | ## Config 16 | Anything specified under the key `node_sass` in your `_config.yml` files will 17 | be [passed directly] to the `sass.render()` call. Check out the [node sass options docs] 18 | for all available settings. 19 | 20 | ### _config.yml 21 | ```yaml 22 | node_sass: 23 | outputStyle: nested 24 | precision: 5 25 | sourceComments: false 26 | ``` 27 | 28 | ### Inheritance 29 | The config object passed to node sass is constructed by merging properties from 30 | the following locations using a least-specific-first order: 31 | 32 | 1. Hardcoded Defaults (`{outputStyle: 'nested',sourceComments: false}`) 33 | 2. Theme specific `_config.yml` 34 | 3. Blog root `_config.yml` 35 | 36 | 37 | ## ♥︎ 38 | Questions, comments, concerns? 39 | * [@JLHwung](https://github.com/JLHwung) 40 | * [@jojoee](https://github.com/jojoee) 41 | * [@knksmith57](https://github.com/knksmith57) 42 | 43 | 44 | [Hexo]: http://hexo.io 45 | [Sass]: http://sass-lang.com/ 46 | [node-sass]: https://github.com/andrew/node-sass 47 | [passed directly]: index.js:#L22 48 | [node sass options docs]: https://github.com/sass/node-sass#options 49 | 50 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '15 21 * * 4' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v1 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v1 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v1 71 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /* eslint-env mocha */ 4 | 5 | var should = require('chai').should(); // eslint-disable-line 6 | 7 | describe('Sass renderer', function () { 8 | var ctx = { 9 | config: {}, 10 | theme: { 11 | config: {} 12 | } 13 | } 14 | 15 | var r = require('../lib/renderer') 16 | 17 | it('default: scss syntax', function () { 18 | var body = [ 19 | '$color: red;', 20 | '.foo {', 21 | ' color: $color;', 22 | '}' 23 | ].join('\n') 24 | 25 | var result = r('scss').call(ctx, { text: body }, {}) 26 | result.should.eql([ 27 | '.foo {', 28 | ' color: red;', 29 | '}' 30 | ].join('\n')) 31 | }) 32 | 33 | it('default: sass syntax', function () { 34 | var body = [ 35 | '$color: red', 36 | '.foo', 37 | ' color: $color' 38 | ].join('\n') 39 | 40 | var result = r('sass').call(ctx, { text: body }, {}) 41 | result.should.eql([ 42 | '.foo {', 43 | ' color: red;', 44 | '}' 45 | ].join('\n')) 46 | }) 47 | 48 | it('outputStyle compressed: scss syntax', function () { 49 | ctx.theme.config = { node_sass: { outputStyle: 'compressed' } } 50 | 51 | var body = [ 52 | '$color: red;', 53 | '.foo {', 54 | ' color: $color;', 55 | '}' 56 | ].join('\n') 57 | 58 | var result = r('scss').call(ctx, { text: body }, {}) 59 | result.should.eql([ 60 | '.foo{color:red}' 61 | ].join('\n')) 62 | }) 63 | 64 | it('outputStyle compressed: sass syntax', function () { 65 | ctx.theme.config = { node_sass: { outputStyle: 'compressed' } } 66 | 67 | var body = [ 68 | '$color: red', 69 | '.foo', 70 | ' color: $color' 71 | ].join('\n') 72 | 73 | var result = r('sass').call(ctx, { text: body }, {}) 74 | result.should.eql([ 75 | '.foo{color:red}' 76 | ].join('\n')) 77 | }) 78 | 79 | it('supports root config: scss syntax', function () { 80 | ctx.config = { node_sass: { outputStyle: 'compressed' } } 81 | ctx.theme.config = {} 82 | 83 | var body = [ 84 | '$color: red;', 85 | '.foo {', 86 | ' color: $color;', 87 | '}' 88 | ].join('\n') 89 | 90 | var result = r('scss').call(ctx, { text: body }, {}) 91 | result.should.eql([ 92 | '.foo{color:red}' 93 | ].join('\n')) 94 | }) 95 | 96 | it('supports root config: sass syntax', function () { 97 | ctx.config = { node_sass: { outputStyle: 'compressed' } } 98 | ctx.theme.config = {} 99 | 100 | var body = [ 101 | '$color: red', 102 | '.foo', 103 | ' color: $color' 104 | ].join('\n') 105 | 106 | var result = r('sass').call(ctx, { text: body }, {}) 107 | result.should.eql([ 108 | '.foo{color:red}' 109 | ].join('\n')) 110 | }) 111 | 112 | it('throw when error occurs: scss syntax', function () { 113 | ctx.theme.config = { node_sass: { outputStyle: 'compressed' } } 114 | ctx.config = {} 115 | 116 | var body = [ 117 | '.foo {', 118 | ' color: $color;', 119 | '}' 120 | ].join('\n') 121 | 122 | should.Throw(function () { 123 | return r('scss').call(ctx, { text: body }, {}) 124 | }, 'Undefined variable.\n ╷\n2 │ color: $color;\n │ ^^^^^^\n ╵\n stdin 2:10 root stylesheet') 125 | }) 126 | 127 | it('throw when error occurs: sass syntax', function () { 128 | ctx.theme.config = { node_sass: { outputStyle: 'compressed' } } 129 | ctx.config = {} 130 | 131 | var body = [ 132 | '.foo', 133 | ' color: $color' 134 | ].join('\n') 135 | 136 | should.Throw(function () { 137 | return r('sass').call(ctx, { text: body }, {}) 138 | }, 'Undefined variable.\n ╷\n2 │ color: $color\n │ ^^^^^^\n ╵\n stdin 2:10 root stylesheet') 139 | }) 140 | }) 141 | --------------------------------------------------------------------------------