You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-8Lines changed: 26 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,6 +87,9 @@ jobs:
87
87
# Name of SVG image output
88
88
filename: github-metrics.svg
89
89
90
+
# Template to use (see src/templates to get a list of supported templates)
91
+
template: classic
92
+
90
93
# Enable Google PageSpeed metrics for account attached website
91
94
# See https://developers.google.com/speed/docs/insights/v5/get-started for more informations
92
95
plugin_pagespeed: no
@@ -230,6 +233,14 @@ Open and edit `settings.json` to configure your instance using a text editor of
230
233
//Intended for easier development and disabled by default
231
234
"debug":false,
232
235
236
+
//Template configuration
237
+
"templates":{
238
+
//Default template
239
+
"default":"classic",
240
+
//Enabled template. Leave empty to enable all defined templates
241
+
"enabled":[],
242
+
},
243
+
233
244
//Plugins configuration
234
245
"plugins":{
235
246
//Google PageSpeed plugin
@@ -322,6 +333,7 @@ systemctl status github_metrics
322
333
<summary>⚠️ HTTP errors code</summary>
323
334
324
335
The following errors code can be encountered if on a server instance :
336
+
* `400 Bad request` : Query is invalid (e.g. unsupported template)
325
337
* `403 Forbidden` : User is not allowed in `restricted` users list
326
338
* `404 Not found` : GitHub API did not found the requested user
327
339
* `429 Too many requests` : Thrown when rate limiter is trigerred
@@ -514,10 +526,13 @@ Add the following to your workflow :
514
526
515
527
#### Metrics generator
516
528
529
+
* `src/setup.mjs` contains the configuration setup
517
530
* `src/metrics.mjs` contains the metrics renderer
518
-
* `src/query.graphql` is the GraphQL query sent to GitHub GraphQL API
519
-
* `src/style.css` contains the style used by the generated SVG image
520
-
* `src/template.svg` contains the template used by the generated SVG image
531
+
* `src/templates/*` contains templates files
532
+
* `src/templates/*/image.svg` contains the template used by the generated SVG image
533
+
* `src/templates/*/query.graphql` is the GraphQL query sent to GitHub GraphQL API
534
+
* `src/templates/*/style.css` contains the style used by the generated SVG image
535
+
* `src/templates/*/template.mjs` contains the code which prepares data for rendering
521
536
* `src/plugins/*` contains the source code of metrics plugins
522
537
523
538
#### Metrics server instance
@@ -527,6 +542,7 @@ Add the following to your workflow :
527
542
528
543
#### GitHub action
529
544
545
+
* `action.yml` contains the GitHub action descriptor
530
546
* `action/index.mjs` contains the GitHub action code
531
547
* `action/dist/index.js` contains compiled the GitHub action code
532
548
* `utils/build.mjs` contains the GitHub action builder
@@ -541,18 +557,18 @@ Read the few sections below to get started with project structure.
541
557
542
558
#### Adding new metrics through GraphQL API, REST API or Third-Party service
543
559
544
-
To use [GitHub GraphQL API](https://docs.github.com/en/graphql), update the GraphQL query from `src/query.graphql`.
545
-
Raw queried data should be exposed in `data.user` whereas computed data should be in `data.computed`, and code should be updated through `src/metrics.mjs`.
560
+
To use [GitHub GraphQL API](https://docs.github.com/en/graphql), update the GraphQL query from `templates/*/query.graphql`.
561
+
Raw queried data should be exposed in `data.user` whereas computed data should be in `data.computed`, and code should be updated through `templates/*/template.mjs`.
546
562
547
563
To use [GitHub Rest API](https://docs.github.com/en/rest) or a third-party service instead, create a new plugin in `src/plugins`.
548
-
Plugins should be self-sufficient and re-exported from [src/plugins/index.mjs](https://github.com/lowlighter/metrics/blob/master/src/plugins/index.mjs), to be later included in the `//Plugins` section of `src/metrics.mjs`.
564
+
Plugins should be self-sufficient and re-exported from [src/plugins/index.mjs](https://github.com/lowlighter/metrics/blob/master/src/plugins/index.mjs), to be later included in the `//Plugins` section of `templates/*/template.mjs`.
549
565
Data generated should be exposed in `data.computed.plugins[plugin]` where `plugin` is your plugin's name.
550
566
551
567
#### Updating the SVG template
552
568
553
-
The SVG template is located in `src/template.svg` and include the CSS from `src/style.css`.
569
+
The SVG template is located in `templates/*/image.svg` and include the CSS from `templates/*/style.css`.
554
570
555
-
It's actually a long JavaScript template string, so you can actually include variables (e.g. `` `${data.user.name}` ``) and execute inline code, like ternary conditions (e.g. `` `${computed.plugins.plugin ? `<div>${computed.plugins.plugin.data}</div>` : ""}` ``) which are useful for conditional statements.
571
+
It is rendered with [EJS](https://github.com/mde/ejs) so you can actually include variables (e.g. `<%= user.name %>`) and execute simple code, like control statements.
556
572
557
573
#### Metrics server and GitHub action
558
574
@@ -584,6 +600,8 @@ This way you'll be able to rapidly test SVG renders with your browser.
584
600
* To apply rate limiting on server and avoid spams and hitting GitHub API's own rate limit
585
601
* [octokit/graphql.js](https://github.com/octokit/graphql.js/) and [octokit/rest.js](https://github.com/octokit/rest.js)
586
602
* To perform request to GitHub GraphQL API and GitHub REST API
0 commit comments