Skip to content

Commit 5523e66

Browse files
committed
Update default config.padding and use metadata.inputs instead of query values in core
1 parent 9673ea7 commit 5523e66

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

source/app/action/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
//Render metrics
200200
info.break()
201201
info.section("Rendering")
202-
const {rendered} = await metrics({login:user, q, dflags}, {graphql, rest, plugins, conf, die, verify}, {Plugins, Templates})
202+
const {rendered} = await metrics({login:user, q}, {graphql, rest, plugins, conf, die, verify}, {Plugins, Templates})
203203
info("Status", "complete")
204204

205205
//Commit metrics

source/app/metrics/index.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import SVGO from "svgo"
66

77
//Setup
8-
export default async function metrics({login, q, dflags = []}, {graphql, rest, plugins, conf, die = false, verify = false, convert = null}, {Plugins, Templates}) {
8+
export default async function metrics({login, q}, {graphql, rest, plugins, conf, die = false, verify = false, convert = null}, {Plugins, Templates}) {
99
//Compute rendering
1010
try {
1111

@@ -39,7 +39,7 @@
3939
//Executing base plugin and compute metrics
4040
console.debug(`metrics/compute/${login} > compute`)
4141
await Plugins.base({login, q, data, rest, graphql, plugins, queries, pending, imports}, conf)
42-
await computer({login, q, dflags}, {conf, data, rest, graphql, plugins, queries, account:data.account}, {pending, imports})
42+
await computer({login, q}, {conf, data, rest, graphql, plugins, queries, account:data.account}, {pending, imports})
4343
const promised = await Promise.all(pending)
4444

4545
//Check plugins errors
@@ -55,7 +55,7 @@
5555
//Rendering and resizing
5656
console.debug(`metrics/compute/${login} > render`)
5757
let rendered = await ejs.render(image, {...data, s:imports.s, f:imports.format, style, fonts}, {views, async:true})
58-
const {resized, mime} = await imports.svgresize(rendered, {paddings:q["config.padding"], convert})
58+
const {resized, mime} = await imports.svgresize(rendered, {paddings:q["config.padding"] || conf.settings.padding, convert})
5959
rendered = resized
6060

6161
//Additional SVG transformations

source/app/metrics/utils.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@
124124
}
125125

126126
/**Render svg */
127-
export async function svgresize(svg, {paddings = ["6%"], convert} = {}) {
127+
export async function svgresize(svg, {paddings, convert}) {
128128
//Instantiate browser if needed
129129
if (!svgresize.browser) {
130130
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"]})
131131
console.debug(`metrics/svgresize > started ${await svgresize.browser.version()}`)
132132
}
133133
//Format padding
134-
const [pw = 1, ph] = paddings.map(padding => `${padding}`.substring(0, padding.length-1)).map(value => 1+Number(value)/100)
134+
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)
135135
const padding = {width:pw, height:ph ?? pw}
136136
console.debug(`metrics/svgresize > padding width*${padding.width}, height*${padding.height}`)
137137
//Render through browser and resize height

source/app/web/settings.example.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"debug": false, "//": "Debug logs",
1313
"mocked": false, "//": "Use mocked data instead of live APIs (use 'force' to use mocked token even if real token are defined)",
1414
"repositories": 100, "//": "Number of repositories to use",
15+
"padding": ["6%", "12%"], "//": "Image padding (default)",
1516
"community": {
1617
"templates": [], "//": "Additional community templates to setup"
1718
},

source/plugins/core/index.mjs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55

66
//Setup
7-
export default async function({login, q, dflags}, {conf, data, rest, graphql, plugins, queries, account}, {pending, imports}) {
7+
export default async function({login, q}, {conf, data, rest, graphql, plugins, queries, account}, {pending, imports}) {
88
//Load inputs
9-
imports.metadata.plugins.core.inputs({data, account, q})
9+
const {"config.animations":animations, "config.timezone":_timezone, "debug.flags":dflags} = imports.metadata.plugins.core.inputs({data, account, q})
1010

1111
//Init
1212
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 @@
1515
console.debug(`metrics/compute/${login} > formatting common metrics`)
1616

1717
//Timezone config
18-
if (q["config.timezone"]) {
19-
const timezone = {name:q["config.timezone"], offset:0}
18+
if (_timezone) {
19+
const timezone = {name:_timezone, offset:0}
2020
data.config.timezone = timezone
2121
try {
2222
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 @@
2929
}
3030

3131
//Animations
32-
if ("config.animations" in q) {
33-
data.animated = q["config.animations"]
34-
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)
35-
}
32+
data.animated = animations
33+
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)
3634

3735
//Plugins
3836
for (const name of Object.keys(imports.plugins)) {
@@ -99,15 +97,15 @@
9997
data.meta = {version:conf.package.version, author:conf.package.author}
10098

10199
//Debug flags
102-
if ((dflags.includes("--cakeday"))||(q["dflag.cakeday"])) {
100+
if ((dflags.includes("--cakeday"))||(dflags.includes("cakeday"))) {
103101
console.debug(`metrics/compute/${login} > applying dflag --cakeday`)
104102
computed.cakeday = true
105103
}
106-
if ((dflags.includes("--hireable"))||(q["dflag.hireable"])) {
104+
if ((dflags.includes("--hireable"))||(dflags.includes("hireable"))) {
107105
console.debug(`metrics/compute/${login} > applying dflag --hireable`)
108106
data.user.isHireable = true
109107
}
110-
if ((dflags.includes("--halloween"))||(q["dflag.halloween"])) {
108+
if ((dflags.includes("--halloween"))||(dflags.includes("halloween"))) {
111109
console.debug(`metrics/compute/${login} > applying dflag --halloween`)
112110
//Haloween color replacer
113111
const halloween = content => content

source/plugins/core/metadata.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ inputs:
101101
description: Image padding
102102
type: array
103103
format: comma-separated
104-
default: 6%
104+
default: 6%, 12%
105105

106106
# Metrics output format
107107
config_output:

0 commit comments

Comments
 (0)