Add json output support
This commit is contained in:
@@ -198,7 +198,7 @@
|
|||||||
info.break()
|
info.break()
|
||||||
info.group({metadata, name:"core", inputs:config})
|
info.group({metadata, name:"core", inputs:config})
|
||||||
info("Plugin errors", die ? "(exit with error)" : "(displayed in generated image)")
|
info("Plugin errors", die ? "(exit with error)" : "(displayed in generated image)")
|
||||||
const convert = ["jpeg", "png"].includes(config["config.output"]) ? config["config.output"] : null
|
const convert = ["jpeg", "png", "json"].includes(config["config.output"]) ? config["config.output"] : null
|
||||||
Object.assign(q, config)
|
Object.assign(q, config)
|
||||||
|
|
||||||
//Base content
|
//Base content
|
||||||
|
|||||||
@@ -53,6 +53,12 @@
|
|||||||
console.warn(util.inspect(errors, {depth:Infinity, maxStringLength:256}))
|
console.warn(util.inspect(errors, {depth:Infinity, maxStringLength:256}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//JSON output
|
||||||
|
if (convert === "json") {
|
||||||
|
console.debug(`metrics/compute/${login} > json output`)
|
||||||
|
return {rendered:data, mime:"application/json"}
|
||||||
|
}
|
||||||
|
|
||||||
//Rendering
|
//Rendering
|
||||||
console.debug(`metrics/compute/${login} > render`)
|
console.debug(`metrics/compute/${login} > render`)
|
||||||
let rendered = await ejs.render(image, {...data, s:imports.s, f:imports.format, style, fonts}, {views, async:true})
|
let rendered = await ejs.render(image, {...data, s:imports.s, f:imports.format, style, fonts}, {views, async:true})
|
||||||
|
|||||||
@@ -189,7 +189,7 @@
|
|||||||
graphql, rest, plugins, conf,
|
graphql, rest, plugins, conf,
|
||||||
die:q["plugins.errors.fatal"] ?? false,
|
die:q["plugins.errors.fatal"] ?? false,
|
||||||
verify:q.verify ?? false,
|
verify:q.verify ?? false,
|
||||||
convert:["jpeg", "png"].includes(q["config.output"]) ? q["config.output"] : null,
|
convert:["jpeg", "png", "json"].includes(q["config.output"]) ? q["config.output"] : null,
|
||||||
}, {Plugins, Templates})
|
}, {Plugins, Templates})
|
||||||
//Cache
|
//Cache
|
||||||
if ((!debug)&&(cached))
|
if ((!debug)&&(cached))
|
||||||
|
|||||||
@@ -149,12 +149,15 @@ It is possible to mitigate this issue using `retries` and `retries_delay` option
|
|||||||
retries_delay: 300
|
retries_delay: 300
|
||||||
```
|
```
|
||||||
|
|
||||||
### 💱 Convert output to PNG/JPEG
|
### 💱 Convert output to PNG/JPEG or JSON
|
||||||
|
|
||||||
It is possible to convert output from SVG to PNG or JPEG images by using `config_output` option.
|
It is possible to convert output from SVG to PNG or JPEG images and even to JSON by using `config_output` option.
|
||||||
|
|
||||||
Note that `png` does not support animations while `jpeg` does not support both animations and transparency.
|
Note that `png` does not support animations while `jpeg` does not support both animations and transparency.
|
||||||
|
|
||||||
|
Using `json` output can be useful if you want to retrieve all data computed by metrics without rendering it.
|
||||||
|
It could then be processed for other usages.
|
||||||
|
|
||||||
#### ℹ️ Examples workflows
|
#### ℹ️ Examples workflows
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ inputs:
|
|||||||
- svg
|
- svg
|
||||||
- png # Does not support animations
|
- png # Does not support animations
|
||||||
- jpeg # Does not support animations and transparency
|
- jpeg # Does not support animations and transparency
|
||||||
|
- json # Outputs a JSON file instead of an image
|
||||||
|
|
||||||
# Number of retries in case rendering fail
|
# Number of retries in case rendering fail
|
||||||
retries:
|
retries:
|
||||||
|
|||||||
@@ -10,6 +10,12 @@
|
|||||||
token: MOCKED_TOKEN
|
token: MOCKED_TOKEN
|
||||||
config_output: png
|
config_output: png
|
||||||
|
|
||||||
|
- name: Image output (json)
|
||||||
|
uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
token: MOCKED_TOKEN
|
||||||
|
config_output: json
|
||||||
|
|
||||||
- name: Use twemoji
|
- name: Use twemoji
|
||||||
uses: lowlighter/metrics@latest
|
uses: lowlighter/metrics@latest
|
||||||
with:
|
with:
|
||||||
|
|||||||
Reference in New Issue
Block a user