Skip to content

Commit ed0da41

Browse files
authored
Add config_display option to support regular and large renders (lowlighter#310)
1 parent 04bf1f0 commit ed0da41

36 files changed

+583
-399
lines changed

source/app/metrics/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
2626
//Initialization
2727
const pending = []
2828
const {queries} = conf
29-
const data = {animated:true, base:{}, config:{}, errors:[], plugins:{}, computed:{}}
29+
const data = {animated:true, large:false, base:{}, config:{}, errors:[], plugins:{}, computed:{}}
3030
const imports = {
3131
plugins:Plugins,
3232
templates:Templates,

source/app/web/statics/app.placeholder.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@
5151
return await ejs.render(partial, data, { async: true, rmWhitespace: true })
5252
},
5353
//Meta-data
54-
meta: { version: set.version, author: "lowlighter" },
54+
meta: { version: set.version, author: "lowlighter", generated:new Date().toGMTString().replace(/GMT$/g, "").trim() },
5555
//Animated
5656
animated: false,
57+
//Display size
58+
large: set.config.display === "large",
5759
//Config
5860
config: set.config,
5961
//Base elements

source/plugins/contributors/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default async function({login, q, imports, data, rest, graphql, queries,
3333
console.debug(`metrics/compute/${login}/plugins > contributors > no more page to load`)
3434
break
3535
}
36-
commits.push(...loaded)
36+
commits.push(...loaded.filter(commit => commit?.author?.login))
3737
}
3838
catch (error) {
3939
if (/Git Repository is empty/.test(error))

source/plugins/core/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ It may increase filesize since it replace unicode characters by SVG images.
140140
config_twemoji: yes
141141
```
142142

143+
### ↔️ Controlling display size
144+
145+
Some templates like `classic` and `repositories` support different output display size:
146+
- `regular` (default) will render a medium-sized image, which is suitable for both desktop and mobile displays and is preferable when using data-intensive metrics (since text may be scaled down on small devices)
147+
- `large` will render a large-sized image, which may be more suitable for some plugins (like displaying topics icons, repository contributors, etc.)
148+
149+
#### ℹ️ Examples workflows
150+
151+
```yaml
152+
- uses: lowlighter/metrics@latest
153+
with:
154+
# ... other options
155+
config_display: large
156+
```
157+
143158
### 🎞️ SVG CSS Animations
144159

145160
As rendered metrics use HTML and CSS, some templates have animations.

source/plugins/core/index.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//Setup
77
export default async function({login, q}, {conf, data, rest, graphql, plugins, queries, account, convert, template}, {pending, imports}) {
88
//Load inputs
9-
const {"config.animations":animations, "config.timezone":_timezone, "debug.flags":dflags} = imports.metadata.plugins.core.inputs({data, account, q})
9+
const {"config.animations":animations, "config.display":display, "config.timezone":_timezone, "debug.flags":dflags} = imports.metadata.plugins.core.inputs({data, account, q})
1010
imports.metadata.templates[template].check({q, account, format:convert})
1111

1212
//Init
@@ -29,6 +29,9 @@ export default async function({login, q}, {conf, data, rest, graphql, plugins, q
2929
}
3030
}
3131

32+
//Display
33+
data.large = display === "large"
34+
3235
//Animations
3336
data.animated = animations
3437
console.debug(`metrics/compute/${login} > animations ${data.animated ? "enabled" : "disabled"}`)

source/plugins/core/metadata.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ inputs:
167167
type: boolean
168168
default: yes
169169

170+
# Render display width
171+
config_display:
172+
description: Render display width
173+
type: string
174+
default: regular
175+
values:
176+
- regular # 480px width
177+
- large # 960px width (may not be supported by all templates)
178+
170179
# Enable SVG CSS animations
171180
config_animations:
172181
description: SVG CSS animations

source/plugins/licenses/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default async function({login, q, imports, data, graphql, queries, accoun
5757
//Spawn licensed process
5858
console.debug(`metrics/compute/${login}/plugins > licenses > running licensed`)
5959
JSON.parse(await imports.run("licensed list --format=json --licenses", {cwd:path})).apps
60-
.map(({sources}) => sources?.flatMap(source => source.dependencies.map(({dependency, license}) => {
60+
.map(({sources}) => sources?.flatMap(source => source.dependencies?.map(({dependency, license}) => {
6161
used[license] = (used[license] ?? 0) + 1
6262
result.dependencies.push(dependency)
6363
result.known += (license in licenses)

source/plugins/screenshot/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
2828
}, selector)
2929
console.debug(`metrics/compute/${login}/plugins > screenshot > coordinates ${JSON.stringify(clip)}`)
3030
const [buffer] = await imports.record({page, ...clip, frames:1, background})
31-
const screenshot = await (await imports.jimp.read(Buffer.from(buffer.split(",").pop(), "base64"))).resize(Math.min(454, clip.width), imports.jimp.AUTO)
31+
const screenshot = await (await imports.jimp.read(Buffer.from(buffer.split(",").pop(), "base64"))).resize(Math.min(454 * (1 + data.large), clip.width), imports.jimp.AUTO)
3232
await browser.close()
3333

3434
//Results

source/plugins/skyline/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
1212
year = new Date().getFullYear()
1313
console.debug(`metrics/compute/${login}/plugins > skyline > year set to ${year}`)
1414
}
15-
const width = 454
15+
const width = 454 * (1 + data.large)
1616
const height = 284
1717

1818
//Start puppeteer and navigate to skyline.github.com

source/plugins/stargazers/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default async function({login, graphql, data, imports, q, queries, accoun
3131
console.debug(`metrics/compute/${login}/plugins > stargazers > loaded ${dates.length} stargazers in total`)
3232

3333
//Compute stargazers increments
34-
const days = 14
34+
const days = 14 * (1 + data.large/2)
3535
const increments = {dates:Object.fromEntries([...new Array(days).fill(null).map((_, i) => [new Date(Date.now() - i * 24 * 60 * 60 * 1000).toISOString().slice(0, 10), 0]).reverse()]), max:NaN, min:NaN}
3636
dates
3737
.map(date => date.toISOString().slice(0, 10))

0 commit comments

Comments
 (0)