|
1 | | -### 📒 Markdown template |
| 1 | +<!--header--> |
| 2 | +<!--/header--> |
2 | 3 |
|
3 | | -Markdown template can render a **markdown template** by interpreting **templating brackets** `{{` and `}}`. |
| 4 | +#### ℹ️ Examples workflows |
4 | 5 |
|
5 | | -<table> |
6 | | - <td align="center"> |
7 | | - <img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.markdown.png"> |
8 | | - <img width="900" height="1" alt=""> |
9 | | - </td> |
10 | | -</table> |
| 6 | +<!--examples--> |
| 7 | +<!--/examples--> |
11 | 8 |
|
12 | | -It can be used to render custom markdown which include data gathered by metrics. |
13 | | -Unlike SVG templates, it is possible to include revelant hyperlinks since it'll be rendered as regular markdown. |
| 9 | +___ |
14 | 10 |
|
15 | | -You can even mix it with SVG plugins for even more customization using `embed` function. |
| 11 | +This template can be used to a *markdown template file* with data gathered by metrics. |
16 | 12 |
|
17 | | -See [example.md](/source/templates/markdown/example.md) for a markdown template example. |
| 13 | +Since the resulting output is a markdown file, it is possible to do additional formatting such as creating hyperlinks and adding custom texts. |
18 | 14 |
|
19 | | -> Note that available data still depends on which plugins have been enabled. |
20 | | -> You may need to handle errors and setup plugins correctly in order to access to their output data. |
| 15 | +## 🈂️ Templating syntax: |
21 | 16 |
|
22 | | -To find which data can be used, you can run a workflow with `config_output: json`. |
23 | | -For convenience, several useful properties are aliased in [/source/templates/markdown/template.mjs](/source/templates/markdown/template.mjs). |
| 17 | +The templating engine is [EJS](https://github.com/mde/ejs) and can be used to interpolate any data retrieved by metrics. |
24 | 18 |
|
25 | | -#### ℹ️ Examples workflows |
| 19 | +* `<%=` and `%>` are used to display escaped output |
| 20 | + * `{{` and `}}` is also supported as syntaxic sugar |
| 21 | +* `<%-` and `%>` are used to display raw output |
| 22 | +* `<%` and `%>` are used to execute JavaScript, and can also contains control statements such as conditionals and loops |
| 23 | + |
| 24 | +*Example: basic templating* |
| 25 | +```markdown |
| 26 | +<!-- template --> |
| 27 | +I joined GitHub on `{{ f.date(REGISTRATION_DATE, {date:true}) }}`. |
| 28 | +I contributed to `{{ REPOSITORIES_CONTRIBUTED_TO }}` repositories and made `{{ COMMITS }}` commits. |
| 29 | + |
| 30 | +<!-- render --> |
| 31 | +I joined GitHub on `20 Oct 2016`. |
| 32 | +I contributed to `37` repositories and made `5947` commits. |
| 33 | +``` |
| 34 | + |
| 35 | +## 🔣 Available data |
26 | 36 |
|
27 | | -[➡️ Supported formats and inputs](metadata.yml) |
| 37 | +Any data fetched by metrics and exposed formatting helpers can be used. |
28 | 38 |
|
29 | | -```yaml |
30 | | -# Markdown output |
| 39 | +It also means that to access plugins data they must be enabled and configured beforehand. |
| 40 | + |
| 41 | +*Example: enabling `plugin_activity` exposes `plugins.activity` data* |
| 42 | +```yml |
31 | 43 | - uses: lowlighter/metrics@latest |
32 | 44 | with: |
33 | | - # ... other options |
34 | 45 | template: markdown |
35 | | - filename: README.md # Output file |
36 | | - markdown: TEMPLATE.md # Template file |
37 | | - markdown_cache: .cache # Cache folder |
| 46 | + plugin_activity: yes |
| 47 | +``` |
| 48 | +
|
| 49 | +> 💡 To avoid failures while accessing data, use [optional chaining operator `?.`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) or ensure that no errors where reported by a given plugin. |
| 50 | + |
| 51 | +> ⚠️ Although rare, data schemas may change in-between metrics version without any notice (these changes are not documented in release notes). It is advised to use a pinned version or a fork when using this template. |
| 52 | + |
| 53 | +A few properties are aliased in [/source/templates/markdown/template.mjs](/source/templates/markdown/template.mjs) for convenience. |
| 54 | + |
| 55 | +Use `config_output: json` to dump all available data for a given configuration. Power users can also directly read [metrics source code](https://github.com/lowlighter/metrics) to know what is exposed. |
| 56 | + |
| 57 | +For a quick overview, it is also possible to use [metrics.lecoq.io/{username}?config.output=json](https://metrics.lecoq.io). |
| 58 | + |
| 59 | +> 💡 Note however that [metrics.lecoq.io](https://metrics.lecoq.io) has a caching system which may prevent any new result. |
| 60 | + |
| 61 | +## 🧩 Plugins with markdown version |
| 62 | + |
| 63 | +Several plugins have a markdown version which provides better usability, usually with hyperlinks and better text formatting. |
| 64 | + |
| 65 | +*Example: using `✒️ posts` plugin markdown version* |
| 66 | +```ejs |
| 67 | +<%- await include(`partials/posts.ejs`) %> |
38 | 68 | ``` |
39 | 69 |
|
40 | | -```yaml |
41 | | -# PDF output |
| 70 | +**[✒️ Recent posts from dev.to](https://dev.to/lowlighter)** |
| 71 | +<table> |
| 72 | + <tr> |
| 73 | + <td rowspan="2" width="280"> |
| 74 | + <img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rbmokFTg--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/idot5ak9irxtu948bgzs.png" alt="" width="280"> |
| 75 | + </td> |
| 76 | + <th> |
| 77 | + <a href="https://dev.to/lowlighter/metrics-v3-0-the-ultimate-tool-to-pimp-your-github-profile-g7p">Metrics v3.0, the ultimate tool to pimp your GitHub profile!</a> |
| 78 | + </th> |
| 79 | + </tr> |
| 80 | + <tr> |
| 81 | + <td> |
| 82 | + Metrics is an extensive SVG images generator plugged with various APIs (GitHub, Twitter, Spotify, ...... |
| 83 | + <br> |
| 84 | + <i>Published on 4 Jan 2021</i> |
| 85 | + </td> |
| 86 | + </tr> |
| 87 | +</table> |
| 88 | + |
| 89 | +> 💡 Remember, plugins still need to be enabled and configured in workflow file! |
| 90 | + |
| 91 | +## 🎈 Embedding SVG metrics on-the-fly |
| 92 | + |
| 93 | +An additional feature which makes the markdown template more powerful than its counterparts is that it can also render SVG on the fly using `embed()` function, without creating any additional jobs. |
| 94 | + |
| 95 | +These renders will automatically be pushed to `markdown_cache` folder and included in the markdown render. |
| 96 | + |
| 97 | +```yml |
42 | 98 | - uses: lowlighter/metrics@latest |
43 | 99 | with: |
44 | | - # ... other options |
45 | 100 | template: markdown |
46 | | - filename: render.pdf # Output file |
47 | | - markdown: TEMPLATE.md # Template file |
48 | | - markdown_cache: .cache # Cache folder |
49 | | - config_output: markdown-pdf # Output as pdf file |
| 101 | + markdown_cache: .cache |
| 102 | +``` |
| 103 | + |
| 104 | +The `embed()` function takes two arguments: |
| 105 | +1. An unique file identifier (which will be used to store render in `${markdown_cache}/${file_identifier}`) |
| 106 | +2. Configuration options |
| 107 | + - Note that `token` options are automatically passed down from overall configuration, do not pass them again (especially in clear) in it |
| 108 | + |
| 109 | +*Example: embed a `🈷️ languages` SVG render* |
| 110 | +```ejs |
| 111 | +<%- await embed(`example-languages-pdf`, {languages:true, languages_details:"percentage, bytes-size", config_display:"large"}) %> |
50 | 112 | ``` |
| 113 | + |
| 114 | +<img src="https://github.com/lowlighter/lowlighter/blob/master/.cache/example-languages-pdf.svg"> |
| 115 | + |
| 116 | +> 💡 The `plugin_` prefix can be dropped for convenience |
| 117 | + |
| 118 | +> 💡 The `embed()` function does not have `🗃️ base` plugin enabled by default. To use it, it is required to explicitely pass them through `base` option. |
0 commit comments