diff --git a/source/app/metrics/index.mjs b/source/app/metrics/index.mjs index d344bfb9..98774ebe 100644 --- a/source/app/metrics/index.mjs +++ b/source/app/metrics/index.mjs @@ -83,9 +83,10 @@ console.debug(error) } //Embed method - const embed = async(q, name = Math.random().toString().substring(2)) => { + const embed = async(name, q) => { q = Object.fromEntries([...Object.entries(q).map(([key, value]) => [key.replace(/^plugin_/, "").replace(/_/g, "."), value]), ["base", false], ["config.animations", false]]) - const {rendered} = await metrics({login, q}, {...arguments[1], convert:null}, arguments[2]) + const plugins = Object.fromEntries(Object.entries(arguments[1].plugins).map(([key, value]) => [key, {...value, enabled:true}])) + const {rendered} = await metrics({login, q}, {...arguments[1], plugins, convert:null}, arguments[2]) return `` } //Rendering template source diff --git a/source/templates/markdown/README.md b/source/templates/markdown/README.md index 3e2a614a..6fc36a88 100644 --- a/source/templates/markdown/README.md +++ b/source/templates/markdown/README.md @@ -12,7 +12,7 @@ Markdown template can render a **markdown template** by interpreting **templatin It can be used to render custom markdown which include data gathered by metrics. Unlike SVG templates, it is possible to include revelant hyperlinks since it'll be rendered as regular markdown. -You can even mix it with SVG plugins for even more customization. +You can even mix it with SVG plugins for even more customization using `embed` function. See [example.md](/source/templates/markdown/example.md) for a markdown template example. diff --git a/source/templates/markdown/example.md b/source/templates/markdown/example.md index 785d158c..f4dea05c 100644 --- a/source/templates/markdown/example.md +++ b/source/templates/markdown/example.md @@ -18,8 +18,6 @@ I joined GitHub on `{{ f.date(REGISTRATION_DATE, {dateStyle:"short"}) }}`. I contributed to `{{ REPOSITORIES_CONTRIBUTED_TO }}` repositories and made `{{ COMMITS }}` commits. ``` -<%- await embed({isocalendar:true}) %> - ## 🧩 Plugins ### Using markdown plugins @@ -50,8 +48,12 @@ ___ ### Embedding SVG metrics -You can also generate "on-the-fly" SVGs metrics image using the `embed` function: +To include SVGs metrics images without creating additional jobs, use the `embed` function: -<%- await embed({isocalendar:true, isocalendar_duration:"full-year"}) %> +<%- await embed("example-isocalendar", {isocalendar:true, isocalendar_duration:"full-year"}) %> -Available configuration options are mostly the same as [action.yml](https://github.com/lowlighter/metrics/blob/master/action.yml). Note that tokens options must **not** be passed to this function. These will be automatically passed down when defined in your workflow job. \ No newline at end of file +It takes two arguments: +- An unique identifier which will be used as filename withing `markdown_cache` folder +- Configuration options (see [action.yml](https://github.com/lowlighter/metrics/blob/master/action.yml)) + - Tokens options are automatically passed down from your workflow job, do not pass them again + - Options syntax is same as web instance (i.e. dots (`.`) instead of underscores (`_`) and no `plugin_` prefixes)