Add markdown variables aliases
This commit is contained in:
@@ -82,8 +82,10 @@
|
||||
}
|
||||
//Rendering template source
|
||||
let rendered = source.replace(/\{\{ (?<content>[\s\S]*?) \}\}/g, "{%= $<content> %}")
|
||||
console.debug(rendered)
|
||||
for (const delimiters of [{openDelimiter:"<", closeDelimiter:">"}, {openDelimiter:"{", closeDelimiter:"}"}])
|
||||
rendered = await ejs.render(rendered, {...data, s:imports.s, f:imports.format}, {views, async:true, ...delimiters})
|
||||
console.debug(`metrics/compute/${login} > success`)
|
||||
return {rendered, mime:"text/plain"}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
### 📒 Markdown <sup>🚧 v3.7</sup>
|
||||
|
||||
⚠️ This feature is still under active developement and may not be functional yet
|
||||
|
||||
Markdown template can render a **markdown template** by interpreting **templating brackets** `{{` and `}}`.
|
||||
|
||||
<table>
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
This is a markdown template example which explain the basic usage of this template.
|
||||
|
||||
See [rendering of this file here](https://github.com/lowlighter/lowlighter/blob/master/metrics.markdown.full.md).
|
||||
|
||||
## 🈂️ Templating syntax:
|
||||
|
||||
* Regular EJS syntax is supported
|
||||
@@ -9,6 +11,12 @@ This is a markdown template example which explain the basic usage of this templa
|
||||
* `{%` 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
|
||||
* Same formatting helpers available in templates can be used too
|
||||
|
||||
```markdown
|
||||
I joined GitHub on `{{ f.date(REGISTRATION_DATE, {dateStyle:"short"}) }}`.
|
||||
I contributed to `{{ REPOSITORIES_CONTRIBUTED_TO }}` repositories and made `{{ COMMITS }}` commits.
|
||||
```
|
||||
|
||||
## 🧩 Markdown plugins
|
||||
|
||||
|
||||
53
source/templates/markdown/template.mjs
Normal file
53
source/templates/markdown/template.mjs
Normal file
@@ -0,0 +1,53 @@
|
||||
/**Template processor */
|
||||
export default async function(_, {data}, {imports}) {
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
//Aliases
|
||||
const {user, computed, plugins} = data
|
||||
Object.assign(data, {
|
||||
//Base
|
||||
NAME:user.name,
|
||||
LOGIN:user.login,
|
||||
REGISTRATION_DATE:user.createdAt,
|
||||
REGISTERED_YEARS:computed.registered.years,
|
||||
LOCATION:user.location,
|
||||
WEBSITE:user.websiteUrl,
|
||||
REPOSITORIES:user.repositories.totalCount,
|
||||
REPOSITORIES_DISK_USAGE:user.repositories.totalDiskUsage,
|
||||
PACKAGES:user.packages.totalCount,
|
||||
STARRED:user.starredRepositories.totalCount,
|
||||
WATCHING:user.watching.totalCount,
|
||||
SPONSORING:user.sponsorshipsAsSponsor.totalCount,
|
||||
SPONSORS:user.sponsorshipsAsMaintainer.totalCount,
|
||||
REPOSITORIES_CONTRIBUTED_TO:user.repositoriesContributedTo.totalCount,
|
||||
COMMITS:computed.commits,
|
||||
COMMITS_PUBLIC:user.contributionsCollection.totalCommitContributions,
|
||||
COMMITS_PRIVATE:user.contributionsCollection.restrictedContributionsCount,
|
||||
ISSUES:user.contributionsCollection.totalIssueContributions,
|
||||
PULL_REQUESTS:user.contributionsCollection.totalPullRequestContributions,
|
||||
PULL_REQUESTS_REVIEWS:user.contributionsCollection.totalPullRequestReviewContributions,
|
||||
FOLLOWERS:user.followers.totalCount,
|
||||
FOLLOWING:user.following.totalCount,
|
||||
ISSUE_COMMENTS:user.issueComments.totalCount,
|
||||
ORGANIZATIONS:user.organizations.totalCount,
|
||||
WATCHERS:computed.repositories.watchers,
|
||||
STARGAZERS:computed.repositories.stargazers,
|
||||
FORKS:computed.repositories.forks,
|
||||
RELEASES:computed.repositories.releases,
|
||||
VERSION:data.meta.version,
|
||||
//Lines
|
||||
LINES_ADDED:plugins.lines?.added ?? 0,
|
||||
LINES_DELETED:plugins.lines?.deleted ?? 0,
|
||||
//Gists
|
||||
GISTS:plugins.gists?.totalCount ?? 0,
|
||||
GISTS_STARGAZERS:plugins.gists?.stargazers ?? 0,
|
||||
//Languages
|
||||
LANGUAGES:plugins.languages?.favorites?.map(({name, value, size, color}) => ({name, value, size, color})) ?? [],
|
||||
//Posts
|
||||
POSTS:plugins.posts?.list ?? [],
|
||||
//Tweets
|
||||
TWEETS:plugins.tweets?.list ?? [],
|
||||
//Topics
|
||||
TOPICS:plugins.topics?.list ?? [],
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user