Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for markupgo provider in contributors generator #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions docs/2.generators/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,42 @@ The `contributors` generator generates an image of contributors using [contrib.r

::field-group

::field{name="provider" type="string"}
Available providers are `markupgo` and `contrib.rocks` (default is `contrib.rocks`)
::

::field{name="github" type="string"}
Github repository name (by default tries to read from `package.json`)
Github repository name (by default tries to read from `package.json`) e.g. `unjs/automd`
::

::field{name="max" type="number"}
Max contributor count (100 by default)
Max contributor count (100 by default).

Set to 0 for all contributors. Max avatar count is 500. (Only available for `markupgo`)
::

::field{name="circleSize" type="number"}
Size of contributor circle (40 by default) (Only available for `markupgo`)
::

::field{name="circleSpacing" type="number"}
Spacing between contributor circles (6 by default) (Only available for `markupgo`)
::

::field{name="circleRadius" type="number"}
Radius of contributor circle (40 by default) (Only available for `markupgo`)
::

::field{name="center" type="boolean"}
Center the contributor circles (false by default) (Only available for `markupgo`)
::

::field{name="removeLogo" type="boolean"}
Remove the logo (false by default) (Only available for `markupgo`)
::

::field{name="width" type="number"}
Width of the image (890 by default) (Only available for `markupgo`)
::

::field{name="anon" type="boolean"}
Expand Down
79 changes: 66 additions & 13 deletions src/generators/contributors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { getPkg } from "../_utils";
import { defineGenerator } from "../generator";

const PROVIDERS = {
CONTRIB_ROCKS: "contrib.rocks",
MARKUPGO: "markupgo",
};

export const contributors = defineGenerator({
name: "contributors",
async generate({ config, args }) {
const { github } = await getPkg(config.dir, args);
const provider = args.provider || PROVIDERS.CONTRIB_ROCKS;

if (!github) {
throw new Error("`github` is required!");
Expand Down Expand Up @@ -34,20 +40,67 @@ export const contributors = defineGenerator({
lines.push(`Made by ${madeBy}`);

// Contributors
const params = [["repo", github]];
if (args.max) {
params.push(["max", args.max]);
}
if (args.anon) {
params.push(["anon", args.anon]);
if (provider === PROVIDERS.MARKUPGO) {
const params = [];

if (Number(args.max) >= 0) {
params.push(["count", args.max]);
}

if (Number(args.width)) {
params.push(["width", args.width]);
}

if (Number(args.circleSize)) {
params.push(["circleSize", args.circleSize]);
}

if (Number(args.circleRadius)) {
params.push(["circleRadius", args.circleRadius]);
}

if (Number(args.circleSpacing)) {
params.push(["circleSpacing", args.circleSpacing]);
}

if (args.center) {
params.push(["center", Boolean(args.center).toString()]);
}

if (args.removeLogo) {
params.push(["removeLogo", Boolean(args.removeLogo).toString()]);
}

if (args.anon) {
params.push(["anon", Boolean(args.anon).toString()]);
}

let paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&");

paramsStr = paramsStr ? `?${paramsStr}` : "";

lines.push(
`<br><br>`,
`<a href="https://github.com/${github}/graphs/contributors">`,
`<img src="https://markupgo.com/github/${github}/contributors${paramsStr}" />`,
`</a>`,
);
} else {
const params = [["repo", github]];
if (args.max) {
params.push(["max", args.max]);
}
if (args.anon) {
params.push(["anon", args.anon]);
}
const paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&");
lines.push(
`<br><br>`,
`<a href="https://github.com/${github}/graphs/contributors">`,
`<img src="https://contrib.rocks/image?${paramsStr}" />`,
`</a>`,
);
}
const paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&");
lines.push(
`<br><br>`,
`<a href="https://github.com/${github}/graphs/contributors">`,
`<img src="https://contrib.rocks/image?${paramsStr}" />`,
`</a>`,
);

return {
contents: lines.join("\n"),
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/INPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@

<!-- automd:contributors author=pi0 license=MIT -->
<!-- /automd -->

<!-- automd:contributors author=pi0 license=MIT provider=markupgo circleSize=48 center=true -->
<!-- /automd -->
11 changes: 11 additions & 0 deletions test/fixture/OUTPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,14 @@ Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/a
</a>

<!-- /automd -->

<!-- automd:contributors author=pi0 license=MIT provider=markupgo circleSize=48 center=true -->

Published under the [MIT](https://github.com/unjs/automd/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/automd/graphs/contributors) 💛
<br><br>
<a href="https://github.com/unjs/automd/graphs/contributors">
<img src="https://markupgo.com/github/unjs/automd/contributors?circleSize=48&center=true" />
</a>

<!-- /automd -->