Update default config.padding and use metadata.inputs instead of query values in core

This commit is contained in:
lowlighter
2021-02-09 22:00:07 +01:00
parent 9673ea713a
commit 5523e66fb8
6 changed files with 17 additions and 18 deletions

View File

@@ -199,7 +199,7 @@
//Render metrics
info.break()
info.section("Rendering")
const {rendered} = await metrics({login:user, q, dflags}, {graphql, rest, plugins, conf, die, verify}, {Plugins, Templates})
const {rendered} = await metrics({login:user, q}, {graphql, rest, plugins, conf, die, verify}, {Plugins, Templates})
info("Status", "complete")
//Commit metrics

View File

@@ -5,7 +5,7 @@
import SVGO from "svgo"
//Setup
export default async function metrics({login, q, dflags = []}, {graphql, rest, plugins, conf, die = false, verify = false, convert = null}, {Plugins, Templates}) {
export default async function metrics({login, q}, {graphql, rest, plugins, conf, die = false, verify = false, convert = null}, {Plugins, Templates}) {
//Compute rendering
try {
@@ -39,7 +39,7 @@
//Executing base plugin and compute metrics
console.debug(`metrics/compute/${login} > compute`)
await Plugins.base({login, q, data, rest, graphql, plugins, queries, pending, imports}, conf)
await computer({login, q, dflags}, {conf, data, rest, graphql, plugins, queries, account:data.account}, {pending, imports})
await computer({login, q}, {conf, data, rest, graphql, plugins, queries, account:data.account}, {pending, imports})
const promised = await Promise.all(pending)
//Check plugins errors
@@ -55,7 +55,7 @@
//Rendering and resizing
console.debug(`metrics/compute/${login} > render`)
let rendered = await ejs.render(image, {...data, s:imports.s, f:imports.format, style, fonts}, {views, async:true})
const {resized, mime} = await imports.svgresize(rendered, {paddings:q["config.padding"], convert})
const {resized, mime} = await imports.svgresize(rendered, {paddings:q["config.padding"] || conf.settings.padding, convert})
rendered = resized
//Additional SVG transformations

View File

@@ -124,14 +124,14 @@
}
/**Render svg */
export async function svgresize(svg, {paddings = ["6%"], convert} = {}) {
export async function svgresize(svg, {paddings, convert}) {
//Instantiate browser if needed
if (!svgresize.browser) {
svgresize.browser = await puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]})
console.debug(`metrics/svgresize > started ${await svgresize.browser.version()}`)
}
//Format padding
const [pw = 1, ph] = paddings.map(padding => `${padding}`.substring(0, padding.length-1)).map(value => 1+Number(value)/100)
const [pw = 1, ph] = (Array.isArray(paddings) ? paddings : `${paddings}`.split(",").map(x => x.trim())).map(padding => `${padding}`.substring(0, padding.length-1)).map(value => 1+Number(value)/100)
const padding = {width:pw, height:ph ?? pw}
console.debug(`metrics/svgresize > padding width*${padding.width}, height*${padding.height}`)
//Render through browser and resize height

View File

@@ -12,6 +12,7 @@
"debug": false, "//": "Debug logs",
"mocked": false, "//": "Use mocked data instead of live APIs (use 'force' to use mocked token even if real token are defined)",
"repositories": 100, "//": "Number of repositories to use",
"padding": ["6%", "12%"], "//": "Image padding (default)",
"community": {
"templates": [], "//": "Additional community templates to setup"
},

View File

@@ -4,9 +4,9 @@
*/
//Setup
export default async function({login, q, dflags}, {conf, data, rest, graphql, plugins, queries, account}, {pending, imports}) {
export default async function({login, q}, {conf, data, rest, graphql, plugins, queries, account}, {pending, imports}) {
//Load inputs
imports.metadata.plugins.core.inputs({data, account, q})
const {"config.animations":animations, "config.timezone":_timezone, "debug.flags":dflags} = imports.metadata.plugins.core.inputs({data, account, q})
//Init
const computed = {commits:0, sponsorships:0, licenses:{favorite:"", used:{}}, token:{}, repositories:{watchers:0, stargazers:0, issues_open:0, issues_closed:0, pr_open:0, pr_merged:0, forks:0, forked:0, releases:0}}
@@ -15,8 +15,8 @@
console.debug(`metrics/compute/${login} > formatting common metrics`)
//Timezone config
if (q["config.timezone"]) {
const timezone = {name:q["config.timezone"], offset:0}
if (_timezone) {
const timezone = {name:_timezone, offset:0}
data.config.timezone = timezone
try {
timezone.offset = Number(new Date().toLocaleString("fr", {timeZoneName:"short", timeZone:timezone.name}).match(/UTC[+](?<offset>\d+)/)?.groups?.offset*60*60*1000) || 0
@@ -29,10 +29,8 @@
}
//Animations
if ("config.animations" in q) {
data.animated = q["config.animations"]
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)
}
data.animated = animations
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)
//Plugins
for (const name of Object.keys(imports.plugins)) {
@@ -99,15 +97,15 @@
data.meta = {version:conf.package.version, author:conf.package.author}
//Debug flags
if ((dflags.includes("--cakeday"))||(q["dflag.cakeday"])) {
if ((dflags.includes("--cakeday"))||(dflags.includes("cakeday"))) {
console.debug(`metrics/compute/${login} > applying dflag --cakeday`)
computed.cakeday = true
}
if ((dflags.includes("--hireable"))||(q["dflag.hireable"])) {
if ((dflags.includes("--hireable"))||(dflags.includes("hireable"))) {
console.debug(`metrics/compute/${login} > applying dflag --hireable`)
data.user.isHireable = true
}
if ((dflags.includes("--halloween"))||(q["dflag.halloween"])) {
if ((dflags.includes("--halloween"))||(dflags.includes("halloween"))) {
console.debug(`metrics/compute/${login} > applying dflag --halloween`)
//Haloween color replacer
const halloween = content => content

View File

@@ -101,7 +101,7 @@ inputs:
description: Image padding
type: array
format: comma-separated
default: 6%
default: 6%, 12%
# Metrics output format
config_output: