hexo-renderer-pug
Advanced tools
Comparing version 2.0.0 to 3.0.0
'use strict'; | ||
const path = require('path'); | ||
const pug = require('pug'); | ||
const configPath = path.join(process.cwd(), 'pug.config'); | ||
const defaultConfig = { compile: {} }; // avoids key errors | ||
let hasConfig = true; | ||
try { | ||
require.resolve(configPath); | ||
} catch { | ||
hasConfig = false; | ||
} | ||
const config = hasConfig ? require(configPath) : defaultConfig; | ||
// Validate non-standard keys -- e.g. 'compile'. | ||
const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); | ||
const invalidKeys = Object.keys(config).filter(k => !hasProp(defaultConfig, k)); | ||
if (invalidKeys.length > 0) { | ||
throw Error(`Unsupported PUG config keys: ${invalidKeys.join(', ')}`); | ||
} | ||
function pugCompile(data) { | ||
return pug.compile(data.text, { | ||
filename: data.path | ||
}); | ||
const opts = { | ||
...config.compile, | ||
filename: data.path // always used | ||
}; | ||
return pug.compile(data.text, opts); | ||
} | ||
@@ -10,0 +32,0 @@ |
{ | ||
"name": "hexo-renderer-pug", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Pug renderer plugin for Hexo", | ||
@@ -35,5 +35,5 @@ "main": "index.js", | ||
"chai": "^4.3.4", | ||
"eslint": "^7.25.0", | ||
"eslint-config-hexo": "^4.1.0", | ||
"mocha": "^8.3.2", | ||
"eslint": "^8.4.0", | ||
"eslint-config-hexo": "^5.0.0", | ||
"mocha": "^9.2.0", | ||
"nyc": "^15.1.0" | ||
@@ -40,0 +40,0 @@ }, |
@@ -15,2 +15,17 @@ # hexo-renderer-pug | ||
## Config | ||
PugJS [options](https://pugjs.org/api/reference.html#options) are supported. These are the options passed into [compile()](https://pugjs.org/api/reference.html#pugcompilesource-options). | ||
Create a `pug.config.js` in your project root: | ||
```js | ||
module.exports = { | ||
compile: { // Passed to compile(). | ||
basedir: process.cwd(), | ||
// ...Other options. | ||
} | ||
// No other methods are supported for now. | ||
} | ||
``` | ||
[Pug]: http://pugjs.org/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3995
33
31
0
3