Add markdown template (#209)
This commit is contained in:
10
.github/readme/partials/introduction.md
vendored
10
.github/readme/partials/introduction.md
vendored
@@ -55,7 +55,7 @@ And you can customize these heavily with plugins, templates and hundreds of opti
|
|||||||
<% } %>
|
<% } %>
|
||||||
<% {
|
<% {
|
||||||
let cell = 0
|
let cell = 0
|
||||||
const elements = Object.entries(templates).filter(([key, value]) => value)
|
const elements = Object.entries(templates).filter(([key, value]) => (value)&&(!["community"].includes(key)))
|
||||||
%>
|
%>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -83,5 +83,13 @@ And you can customize these heavily with plugins, templates and hundreds of opti
|
|||||||
<% if (cell === "odd") {
|
<% if (cell === "odd") {
|
||||||
-%> </tr>
|
-%> </tr>
|
||||||
<% }}} -%>
|
<% }}} -%>
|
||||||
|
<tr>
|
||||||
|
<th colspan="2"><a href="source/templates/community/README.md"><%= templates.community.name -%></a></th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<%- templates.community.readme.demo.replace(/<img src=/g, `<img alt="" width="400" src=`)?.split("\n")?.map((x, i) => i ? ` ${x}` : x)?.join("\n") %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|||||||
1
.github/readme/partials/references.md
vendored
1
.github/readme/partials/references.md
vendored
@@ -15,3 +15,4 @@
|
|||||||
* [jamesgeorge007/github-activity-readme](https://github.com/jamesgeorge007/github-activity-readme)
|
* [jamesgeorge007/github-activity-readme](https://github.com/jamesgeorge007/github-activity-readme)
|
||||||
* [vvo/sourcekarma](https://github.com/vvo/sourcekarma)
|
* [vvo/sourcekarma](https://github.com/vvo/sourcekarma)
|
||||||
* [ryo-ma/github-profile-trophy](https://github.com/ryo-ma/github-profile-trophy)
|
* [ryo-ma/github-profile-trophy](https://github.com/ryo-ma/github-profile-trophy)
|
||||||
|
* [teoxoy/profile-readme-stats](https://github.com/teoxoy/profile-readme-stats)
|
||||||
@@ -62,6 +62,31 @@
|
|||||||
return {rendered:data, mime:"application/json"}
|
return {rendered:data, mime:"application/json"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Markdown output
|
||||||
|
if (convert === "markdown") {
|
||||||
|
//Retrieving template source
|
||||||
|
console.debug(`metrics/compute/${login} > markdown render`)
|
||||||
|
let source = image
|
||||||
|
try {
|
||||||
|
let template = q.markdown
|
||||||
|
if (!/^https:/.test(template)) {
|
||||||
|
const {data:{default_branch:branch, full_name:repo}} = await rest.repos.get({owner:login, repo:q.repo||login})
|
||||||
|
console.debug(`metrics/compute/${login} > on ${repo} with default branch ${branch}`)
|
||||||
|
template = `https://raw.githubusercontent.com/${repo}/${branch}/${template}`
|
||||||
|
}
|
||||||
|
console.debug(`metrics/compute/${login} > fetching ${template}`)
|
||||||
|
;({data:source} = await imports.axios.get(template, {headers:{Accept:"text/plain"}}))
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.debug(error)
|
||||||
|
}
|
||||||
|
//Rendering template source
|
||||||
|
let rendered = source.replace(/\{\{ (?<content>[\s\S]*?) \}\}/g, "{%= $<content> %}")
|
||||||
|
for (const delimiters of [{openDelimiter:"<", closeDelimiter:">"}, {openDelimiter:"{", closeDelimiter:"}"}])
|
||||||
|
rendered = await ejs.render(rendered, {...data, s:imports.s, f:imports.format}, {views, async:true, ...delimiters})
|
||||||
|
return {rendered, mime:"text/plain"}
|
||||||
|
}
|
||||||
|
|
||||||
//Rendering
|
//Rendering
|
||||||
console.debug(`metrics/compute/${login} > render`)
|
console.debug(`metrics/compute/${login} > render`)
|
||||||
let rendered = await ejs.render(image, {...data, s:imports.s, f:imports.format, style, fonts}, {views, async:true})
|
let rendered = await ejs.render(image, {...data, s:imports.s, f:imports.format, style, fonts}, {views, async:true})
|
||||||
|
|||||||
@@ -43,8 +43,8 @@
|
|||||||
Templates[name] = await metadata.template({__templates, name, plugins, logger})
|
Templates[name] = await metadata.template({__templates, name, plugins, logger})
|
||||||
}
|
}
|
||||||
//Reorder keys
|
//Reorder keys
|
||||||
const {classic, repository, community, ...templates} = Templates
|
const {classic, repository, markdown, community, ...templates} = Templates
|
||||||
Templates = {classic, repository, ...templates, community}
|
Templates = {classic, repository, ...templates, markdown, community}
|
||||||
|
|
||||||
//Packaged metadata
|
//Packaged metadata
|
||||||
const packaged = JSON.parse(`${await fs.promises.readFile(__package)}`)
|
const packaged = JSON.parse(`${await fs.promises.readFile(__package)}`)
|
||||||
|
|||||||
@@ -197,7 +197,7 @@
|
|||||||
graphql, rest, plugins, conf,
|
graphql, rest, plugins, conf,
|
||||||
die:q["plugins.errors.fatal"] ?? false,
|
die:q["plugins.errors.fatal"] ?? false,
|
||||||
verify:q.verify ?? false,
|
verify:q.verify ?? false,
|
||||||
convert:["jpeg", "png", "json"].includes(q["config.output"]) ? q["config.output"] : null,
|
convert:["jpeg", "png", "json", "markdown"].includes(q["config.output"]) ? q["config.output"] : null,
|
||||||
}, {Plugins, Templates})
|
}, {Plugins, Templates})
|
||||||
//Cache
|
//Cache
|
||||||
if ((!debug)&&(cached)) {
|
if ((!debug)&&(cached)) {
|
||||||
|
|||||||
@@ -58,6 +58,19 @@ inputs:
|
|||||||
type: string
|
type: string
|
||||||
default: github-metrics.svg
|
default: github-metrics.svg
|
||||||
|
|
||||||
|
# Rendered markdown output path (when using a markdown template)
|
||||||
|
# It can be either a local path or a link (e.g. raw.githubusercontent.com)
|
||||||
|
markdown:
|
||||||
|
description: Rendered markdown output path
|
||||||
|
type: string
|
||||||
|
default: TEMPLATE.md
|
||||||
|
|
||||||
|
# Rendered markdown file cache (when using a markdown template)
|
||||||
|
markdown_cache:
|
||||||
|
description: Rendered markdown file cache
|
||||||
|
type: string
|
||||||
|
default: .cache
|
||||||
|
|
||||||
# Output action
|
# Output action
|
||||||
output_action:
|
output_action:
|
||||||
description: Output action
|
description: Output action
|
||||||
@@ -155,9 +168,10 @@ inputs:
|
|||||||
default: svg
|
default: svg
|
||||||
values:
|
values:
|
||||||
- svg
|
- svg
|
||||||
- png # Does not support animations
|
- png # Does not support animations
|
||||||
- jpeg # Does not support animations and transparency
|
- jpeg # Does not support animations and transparency
|
||||||
- json # Outputs a JSON file instead of an image
|
- json # Outputs a JSON file instead of an image
|
||||||
|
- markdown # Outputs a Markdown file instead of an image
|
||||||
|
|
||||||
# Number of retries in case rendering fail
|
# Number of retries in case rendering fail
|
||||||
retries:
|
retries:
|
||||||
|
|||||||
29
source/templates/markdown/README.md
Normal file
29
source/templates/markdown/README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
### 📒 Markdown (🚧 v3.7)
|
||||||
|
|
||||||
|
Markdown template can render a **markdown template** by interpreting **templating brackets** `{{` and `}}`.
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<td align="center">
|
||||||
|
<img width="900" height="1" alt="">
|
||||||
|
</td>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
See [example.md](/source/templates/markdown/example.md) for a markdown template example.
|
||||||
|
|
||||||
|
#### ℹ️ Examples workflows
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
# ... other options
|
||||||
|
template: markdown
|
||||||
|
filename: README.md # Output file
|
||||||
|
markdown: TEMPLATE.md # Template file
|
||||||
|
markdown_cache: .cache # Cache folder
|
||||||
|
config_output: markdown # Output as markdown file
|
||||||
|
```
|
||||||
27
source/templates/markdown/example.md
Normal file
27
source/templates/markdown/example.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# 📒 Markdown template example
|
||||||
|
|
||||||
|
This is a markdown template example which explain the basic usage of this template.
|
||||||
|
|
||||||
|
## 🈂️ Templating syntax:
|
||||||
|
|
||||||
|
* Regular EJS syntax is supported
|
||||||
|
* `{{` and `}}` will be interpolated as EJS brackets (syntaxic sugar)
|
||||||
|
* `{%` and `%}` can be used as control statements
|
||||||
|
* Use [metrics.lecoq.io](https://metrics.lecoq.io/) with `config.output=json` to see available data
|
||||||
|
* You can also use `config_output: json` in GitHub Actions and/or inspect [metrics](https://github.com/lowlighter/metrics) code to get available data too
|
||||||
|
|
||||||
|
## 🧩 Markdown plugins
|
||||||
|
|
||||||
|
Most of plugins from SVG templates can be reused directly by including image source in markdown, but some have them have their own **markdown** version which includes hyperlinks.
|
||||||
|
|
||||||
|
### 📰 Recent activity
|
||||||
|
|
||||||
|
<%- await include(`partials/activity.ejs`) %>
|
||||||
|
|
||||||
|
### ✒️ Recent posts
|
||||||
|
|
||||||
|
*Coming soon*
|
||||||
|
|
||||||
|
### 🗼 Rss feed
|
||||||
|
|
||||||
|
*Coming soon*
|
||||||
1
source/templates/markdown/image.svg
Normal file
1
source/templates/markdown/image.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
You did not provide a valid "markdown" query parameter, which is required to use this template.
|
||||||
1
source/templates/markdown/partials/_.json
Normal file
1
source/templates/markdown/partials/_.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[]
|
||||||
44
source/templates/markdown/partials/activity.ejs
Normal file
44
source/templates/markdown/partials/activity.ejs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<%_ if (plugins.activity) { _%>
|
||||||
|
<%_ if (plugins.activity.error) { _%>
|
||||||
|
<%= plugins.activity.error.message _%>
|
||||||
|
<%_ } else if (plugins.activity.events.length) { _%>
|
||||||
|
<%_ for (const {actor, type, repo, timestamp, ...event} of plugins.activity.events) { _%>
|
||||||
|
<%_ if (type === "comment") { _%>
|
||||||
|
* 💬 Commented on [#<%= event.number %> <%= event.title %>](https://github.com/<%= repo %>/<%= {issue:"issues", pr:"pulls", commit:"commit"}[event.on] %>/<%= event.number %>) from [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "member") { _%>
|
||||||
|
* 💼 Added [<%= event.user %>](https://github.com/<%= event.user %>) as collaborator in [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "star") { _%>
|
||||||
|
* 🌟 Starred [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "release") { _%>
|
||||||
|
* 📦 <%- event.draft ? "Drafted release" : event.prerelease ? "Pre-released" : "Released" %> **<%= event.name %>** of [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "fork") { _%>
|
||||||
|
* 🍽️ Forked [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "push") { _%>
|
||||||
|
* ➡️ Pushed <%= event.size %> commit<%= s(event.size) %> in [<%= repo %>](https://github.com/<%= repo %>) <%= event.branch ? `on branch \`${event.branch}\`` : "" %>
|
||||||
|
<%_ for (const commit of event.commits) { _%>
|
||||||
|
* [#<%= commit.sha %>](https://github.com/<%= repo %>/commit/<%= commit.sha %>) <%= commit.message %>
|
||||||
|
<%_ } _%>
|
||||||
|
<%_ } else if (type === "issue") { _%>
|
||||||
|
* #️⃣ <%- event.action === "opened" ? "Opened" : event.action === "reopened" ? "Reopened" : "Closed" %> [#<%= event.number %> <%= event.title %>](https://github.com/<%= repo %>/issues/<%= event.number %>) in [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "pr") { _%>
|
||||||
|
* 🔃 <%- event.action === "opened" ? "Opened" : "Merged" %> [#<%= event.number %> <%= event.title %>](https://github.com/<%= repo %>/pulls/<%= event.number %>) in [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
* <%= event.files.changed %> file<%= s(event.files.changed) %> changed `++<%= event.lines.added %> --<%= event.lines.deleted%>`
|
||||||
|
<%_ } else if (type === "wiki") { _%>
|
||||||
|
* 📝 Updated <%= event.pages.length %> wiki page<%= s(event.pages.length) %> in [<%= repo %>](https://github.com/<%= repo %>/wiki)
|
||||||
|
<%_ for (const page of event.pages) { _%>
|
||||||
|
* <%= page %>
|
||||||
|
<%_ } _%>
|
||||||
|
<%_ } else if (type === "public") { _%>
|
||||||
|
* 🚀 Made [<%= repo %>](https://github.com/<%= repo %>) public
|
||||||
|
<%_ } else if (type === "review") { _%>
|
||||||
|
* 🔍 Reviewed [#<%= event.number %> <%= event.title %>](https://github.com/<%= repo %>/pulls/<%= event.number %>) in [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "ref/create") { _%>
|
||||||
|
* ⏺️ Created new <%= event.ref.type %> `<%= event.ref.name %>` in [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } else if (type === "ref/create") { _%>
|
||||||
|
* 🚮 Deleted <%= event.ref.type %> `<%= event.ref.name %>` from [<%= repo %>](https://github.com/<%= repo %>)
|
||||||
|
<%_ } _%>
|
||||||
|
<%_ } _%>
|
||||||
|
<%_ } else { _%>
|
||||||
|
No recent activity
|
||||||
|
<%_ } _%>
|
||||||
|
<%_ } _%>
|
||||||
Reference in New Issue
Block a user