posthtml-fetch
Advanced tools
Comparing version 2.1.2 to 2.2.0
@@ -0,5 +1,6 @@ | ||
const got = require('got') | ||
const path = require('path') | ||
const isUrl = require('is-url') | ||
const got = require('got') | ||
const posthtml = require('posthtml') | ||
const merge = require('lodash.merge') | ||
const matcher = require('posthtml-match-helper') | ||
@@ -9,6 +10,7 @@ const expressions = require('posthtml-expressions') | ||
module.exports = (options = {}) => tree => { | ||
options.tags = options.tags || ['fetch', 'remote'] | ||
options.got = options.got || {} | ||
options.attribute = options.attribute || 'url' | ||
options.got = options.got || {} | ||
options.expressions = options.expressions || {} | ||
options.preserveTag = options.preserveTag || false | ||
options.tags = options.tags || ['fetch', 'remote'] | ||
@@ -64,3 +66,12 @@ return new Promise((resolve, reject) => { | ||
try { | ||
plugins.push(expressions({locals: {response: JSON.parse(body)}})) | ||
plugins.push( | ||
expressions( | ||
merge( | ||
options.expressions, | ||
{ | ||
locals: {response: JSON.parse(body)} | ||
} | ||
)) | ||
) | ||
content = tree.render(node.content) | ||
@@ -67,0 +78,0 @@ } catch {} |
{ | ||
"name": "posthtml-fetch", | ||
"description": "PostHTML plugin for fetching and displaying remote content.", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"license": "MIT", | ||
@@ -36,2 +36,3 @@ "author": "Cosmin Popovici (https://github.com/cossssmin)", | ||
"is-url": "^1.2.4", | ||
"lodash.merge": "^4.6.2", | ||
"posthtml": "^0.16.4", | ||
@@ -42,3 +43,3 @@ "posthtml-expressions": "^1.6.2", | ||
"devDependencies": { | ||
"ava": "^3.13.0", | ||
"ava": "^4.1.0", | ||
"np": "^7.0.0", | ||
@@ -45,0 +46,0 @@ "nyc": "^15.1.0", |
@@ -47,3 +47,3 @@ <div align="center"> | ||
// response body | ||
// => interpolated response body | ||
``` | ||
@@ -118,3 +118,3 @@ | ||
console.log(result.html) | ||
// => ...interpolated response from https://example.test | ||
// => interpolated response body | ||
}) | ||
@@ -142,3 +142,3 @@ ``` | ||
console.log(result.html) | ||
// => ...interpolated response from https://example.test | ||
// => interpolated response body | ||
}) | ||
@@ -149,4 +149,6 @@ ``` | ||
Allows you to leave an item. Default value `false`. | ||
Default: `false` | ||
When set to `true`, this option will preserve the `tag` around the response body. | ||
Example: | ||
@@ -165,6 +167,31 @@ | ||
console.log(result.html) | ||
// => <fetch url="https://example.test">...interpolated response from https://example.test</fetch> | ||
// => <fetch url="https://example.test">interpolated response body</fetch> | ||
}) | ||
``` | ||
### `expressions` | ||
Default: `{}` | ||
You can pass options to `posthtml-expressions`. | ||
Example: | ||
```js | ||
const posthtml = require('posthtml') | ||
const pf = require('posthtml-fetch') | ||
posthtml() | ||
.use(pf({ | ||
expressions: { | ||
delimiters: ['[[', ']]'], | ||
} | ||
})) | ||
.process('<fetch url="https://example.test">[[ response ]]</fetch>') | ||
.then(result => { | ||
console.log(result.html) | ||
// => interpolated response body | ||
}) | ||
``` | ||
## Plugins | ||
@@ -201,3 +228,3 @@ | ||
console.log(result.html) | ||
// => ...interpolated response from https://example.test | ||
// => interpolated response body | ||
}) | ||
@@ -204,0 +231,0 @@ ``` |
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
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
10820
95
237
6
+ Addedlodash.merge@^4.6.2
+ Addedlodash.merge@4.6.2(transitive)