From 679886333f34741f5abcd3ed347ccbc35e9a7b7d Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 7 Apr 2021 00:26:26 +0200 Subject: [PATCH] Add markdown variables aliases --- source/app/metrics/index.mjs | 2 + source/templates/markdown/README.md | 2 - source/templates/markdown/example.md | 8 ++++ source/templates/markdown/template.mjs | 53 ++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 source/templates/markdown/template.mjs diff --git a/source/app/metrics/index.mjs b/source/app/metrics/index.mjs index 87d5c681..6c65e02c 100644 --- a/source/app/metrics/index.mjs +++ b/source/app/metrics/index.mjs @@ -82,8 +82,10 @@ } //Rendering template source let rendered = source.replace(/\{\{ (?[\s\S]*?) \}\}/g, "{%= $ %}") + 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"} } diff --git a/source/templates/markdown/README.md b/source/templates/markdown/README.md index a3663dca..cf50c186 100644 --- a/source/templates/markdown/README.md +++ b/source/templates/markdown/README.md @@ -1,7 +1,5 @@ ### 📒 Markdown 🚧 v3.7 - ⚠️ 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 `}}`. diff --git a/source/templates/markdown/example.md b/source/templates/markdown/example.md index 9d46b6a3..bd818716 100644 --- a/source/templates/markdown/example.md +++ b/source/templates/markdown/example.md @@ -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 diff --git a/source/templates/markdown/template.mjs b/source/templates/markdown/template.mjs new file mode 100644 index 00000000..c15e8073 --- /dev/null +++ b/source/templates/markdown/template.mjs @@ -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 ?? [], + }) +} \ No newline at end of file