diff --git a/docs/2.generators/contributors.md b/docs/2.generators/contributors.md index ea89a99..8f6f07c 100644 --- a/docs/2.generators/contributors.md +++ b/docs/2.generators/contributors.md @@ -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"} diff --git a/src/generators/contributors.ts b/src/generators/contributors.ts index 9832f32..60328a0 100644 --- a/src/generators/contributors.ts +++ b/src/generators/contributors.ts @@ -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!"); @@ -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( + `

`, + ``, + ``, + ``, + ); + } 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( + `

`, + ``, + ``, + ``, + ); } - const paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&"); - lines.push( - `

`, - ``, - ``, - ``, - ); return { contents: lines.join("\n"), diff --git a/test/fixture/INPUT.md b/test/fixture/INPUT.md index ac559c7..980ff26 100644 --- a/test/fixture/INPUT.md +++ b/test/fixture/INPUT.md @@ -44,3 +44,6 @@ + + + diff --git a/test/fixture/OUTPUT.md b/test/fixture/OUTPUT.md index 7b661d9..20909e5 100644 --- a/test/fixture/OUTPUT.md +++ b/test/fixture/OUTPUT.md @@ -206,3 +206,14 @@ Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/a + + + +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) 💛 +

+ + + + +