Accept other formats in embed function
This commit is contained in:
@@ -315,11 +315,11 @@ async function wait(seconds) {
|
|||||||
|
|
||||||
//Cache
|
//Cache
|
||||||
if (/markdown/.test(convert)) {
|
if (/markdown/.test(convert)) {
|
||||||
const regex = /(?<match><img class="metrics-cachable" data-name="(?<name>[\s\S]+?)" src="data:image[/]svg[+]xml;base64,(?<content>[/+=\w]+)">)/g
|
const regex = /(?<match><img class="metrics-cachable" data-name="(?<name>[\s\S]+?)" src="data:image[/](?<format>(?:svg[+]xml)|jpeg|png);base64,(?<content>[/+=\w]+)">)/g
|
||||||
let matched = null
|
let matched = null
|
||||||
while (matched = regex.exec(rendered)?.groups) { //eslint-disable-line no-cond-assign
|
while (matched = regex.exec(rendered)?.groups) { //eslint-disable-line no-cond-assign
|
||||||
const {match, name, content} = matched
|
const {match, name, format, content} = matched
|
||||||
let path = `${_markdown_cache}/${name}.svg`
|
let path = `${_markdown_cache}/${name}.${format.replace(/[+].*$/g, "")}`
|
||||||
console.debug(`Processing ${path}`)
|
console.debug(`Processing ${path}`)
|
||||||
let sha = null
|
let sha = null
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -122,8 +122,8 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
|
|||||||
console.debug(`metrics/compute/${login} > embed called with`)
|
console.debug(`metrics/compute/${login} > embed called with`)
|
||||||
console.debug(q)
|
console.debug(q)
|
||||||
//Compute rendering
|
//Compute rendering
|
||||||
const {rendered} = await metrics({login, q}, {...arguments[1], convert:null}, arguments[2])
|
const {rendered} = await metrics({login, q}, {...arguments[1], convert:["svg", "png", "jpeg"].includes(q["config.output"]) ? q["config.output"] : null}, arguments[2])
|
||||||
return `<img class="metrics-cachable" data-name="${name}" src="data:image/svg+xml;base64,${Buffer.from(rendered).toString("base64")}">`
|
return `<img class="metrics-cachable" data-name="${name}" src="data:image/${{png:"png", jpeg:"jpeg"}[q["config.output"]] ?? "svg+xml"};base64,${Buffer.from(rendered).toString("base64")}">`
|
||||||
}
|
}
|
||||||
//Rendering template source
|
//Rendering template source
|
||||||
let rendered = source.replace(/\{\{ (?<content>[\s\S]*?) \}\}/g, "{%= $<content> %}")
|
let rendered = source.replace(/\{\{ (?<content>[\s\S]*?) \}\}/g, "{%= $<content> %}")
|
||||||
|
|||||||
Reference in New Issue
Block a user