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 //Render metrics
info.break() info.break()
info.section("Rendering") 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") info("Status", "complete")
//Commit metrics //Commit metrics

View File

@@ -5,7 +5,7 @@
import SVGO from "svgo" import SVGO from "svgo"
//Setup //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 //Compute rendering
try { try {
@@ -39,7 +39,7 @@
//Executing base plugin and compute metrics //Executing base plugin and compute metrics
console.debug(`metrics/compute/${login} > compute`) console.debug(`metrics/compute/${login} > compute`)
await Plugins.base({login, q, data, rest, graphql, plugins, queries, pending, imports}, conf) 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) const promised = await Promise.all(pending)
//Check plugins errors //Check plugins errors
@@ -55,7 +55,7 @@
//Rendering and resizing //Rendering and resizing
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})
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 rendered = resized
//Additional SVG transformations //Additional SVG transformations

View File

@@ -124,14 +124,14 @@
} }
/**Render svg */ /**Render svg */
export async function svgresize(svg, {paddings = ["6%"], convert} = {}) { export async function svgresize(svg, {paddings, convert}) {
//Instantiate browser if needed //Instantiate browser if needed
if (!svgresize.browser) { 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"]}) 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()}`) console.debug(`metrics/svgresize > started ${await svgresize.browser.version()}`)
} }
//Format padding //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} const padding = {width:pw, height:ph ?? pw}
console.debug(`metrics/svgresize > padding width*${padding.width}, height*${padding.height}`) console.debug(`metrics/svgresize > padding width*${padding.width}, height*${padding.height}`)
//Render through browser and resize height //Render through browser and resize height

View File

@@ -12,6 +12,7 @@
"debug": false, "//": "Debug logs", "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)", "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", "repositories": 100, "//": "Number of repositories to use",
"padding": ["6%", "12%"], "//": "Image padding (default)",
"community": { "community": {
"templates": [], "//": "Additional community templates to setup" "templates": [], "//": "Additional community templates to setup"
}, },

View File

@@ -4,9 +4,9 @@
*/ */
//Setup //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 //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 //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}} 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`) console.debug(`metrics/compute/${login} > formatting common metrics`)
//Timezone config //Timezone config
if (q["config.timezone"]) { if (_timezone) {
const timezone = {name:q["config.timezone"], offset:0} const timezone = {name:_timezone, offset:0}
data.config.timezone = timezone data.config.timezone = timezone
try { try {
timezone.offset = Number(new Date().toLocaleString("fr", {timeZoneName:"short", timeZone:timezone.name}).match(/UTC[+](?<offset>\d+)/)?.groups?.offset*60*60*1000) || 0 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 //Animations
if ("config.animations" in q) { data.animated = animations
data.animated = q["config.animations"]
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`) console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)
}
//Plugins //Plugins
for (const name of Object.keys(imports.plugins)) { for (const name of Object.keys(imports.plugins)) {
@@ -99,15 +97,15 @@
data.meta = {version:conf.package.version, author:conf.package.author} data.meta = {version:conf.package.version, author:conf.package.author}
//Debug flags //Debug flags
if ((dflags.includes("--cakeday"))||(q["dflag.cakeday"])) { if ((dflags.includes("--cakeday"))||(dflags.includes("cakeday"))) {
console.debug(`metrics/compute/${login} > applying dflag --cakeday`) console.debug(`metrics/compute/${login} > applying dflag --cakeday`)
computed.cakeday = true 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`) console.debug(`metrics/compute/${login} > applying dflag --hireable`)
data.user.isHireable = true 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`) console.debug(`metrics/compute/${login} > applying dflag --halloween`)
//Haloween color replacer //Haloween color replacer
const halloween = content => content const halloween = content => content

View File

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