Skip to content

Commit f627d63

Browse files
committed
feat: contributors generator
1 parent 91bb79a commit f627d63

File tree

8 files changed

+126
-2
lines changed

8 files changed

+126
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,22 @@ Your automated markdown maintainer!
3333

3434
</details>
3535

36-
3736
<!-- /automd -->
3837

3938
## License
4039

41-
Made with 💛 Published under the [MIT License](./LICENSE).
40+
<!-- automd:contributors license=MIT author="pi0" -->
41+
42+
Published under the [MIT](https://github.com/unjs/automd/blob/main/LICENSE) license.
43+
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/automd/graphs/contributors) 💛
44+
<br><br>
45+
<a href="https://github.com/unjs/automd/graphs/contributors">
46+
<img src="https://contrib.rocks/image?repo=unjs/automd" />
47+
</a>
48+
49+
<!-- /automd -->
50+
51+
---
4252

4353
<!-- automd:with-automd -->
4454

docs/2.generators/badges.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ The `badges` generator generates badges for the latest npm version, npm download
1919
[![npm downloads](https://flat.badgen.net/npm/dm/defu?color=yellow)](https://npmjs.com/package/defu)
2020
[![bundle size](https://flat.badgen.net/bundlephobia/minzip/defu?color=yellow)](https://bundlephobia.com/package/defu)
2121
[![install size](https://flat.badgen.net/packagephobia/publish/defu?color=yellow)](https://packagephobia.com/result?p=defu)
22+
[![codecov](https://flat.badgen.net/codecov/c/github/unjs/automd?color=yellow)](https://codecov.io/gh/unjs/automd)
23+
[![license](https://flat.badgen.net/github/license/unjs/automd?color=yellow)](https://github.com/unjs/automd/blob/main/LICENSE)
2224

2325
<!-- /automd -->
2426

docs/2.generators/contributors.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# contributors
2+
3+
The `contributors` generator generates an image of contributors using [contrib.rocks](https://contrib.rocks/) service plus additional data about authors and license.
4+
5+
<!-- automd:example generator=contributors author=pi0 license=MIT -->
6+
7+
## Example
8+
9+
### Input
10+
11+
<!-- automd:contributors author=pi0 license=MIT -->
12+
<!-- /automd -->
13+
14+
### Output
15+
16+
<!-- automd:contributors author=pi0 license=MIT -->
17+
18+
Published under the [MIT](https://github.com/unjs/automd/blob/main/LICENSE) license.
19+
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/automd/graphs/contributors) 💛
20+
<br><br>
21+
<a href="https://github.com/unjs/automd/graphs/contributors">
22+
<img src="https://contrib.rocks/image?repo=unjs/automd" />
23+
</a>
24+
25+
<!-- /automd -->
26+
27+
<!-- /automd -->
28+
29+
## Arguments
30+
31+
- `github`: Github repository name (by default tries to read from `package.json`)
32+
- `max`: Max contributor count (100 by default)
33+
- `anon` Include anonymous users (false by default)
34+
- `author`: Comma separated list of github usersnames.
35+
- `license`: Name of license.

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"private": true,
33
"name": "docs",
4+
"repository": "unjs/automd",
45
"scripts": {
56
"dev": "undocs dev",
67
"build": "undocs build"

src/generators/contributors.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { getPkg } from "../_utils";
2+
import { defineGenerator } from "../generator";
3+
4+
export const contributors = defineGenerator({
5+
name: "contributors",
6+
async generate({ config, args }) {
7+
const { github } = await getPkg(config.dir, args);
8+
9+
if (!github) {
10+
throw new Error("`github` is required!");
11+
}
12+
13+
const lines: string[] = [];
14+
15+
// License
16+
if (typeof args.license === "string") {
17+
lines.push(
18+
`Published under the [${args.license.toUpperCase()}](https://github.com/${github}/blob/main/LICENSE) license.`,
19+
);
20+
}
21+
22+
// Made by
23+
let madeBy = `[community](https://github.com/${github}/graphs/contributors) 💛`;
24+
if (typeof args.author === "string") {
25+
const authors = args.author
26+
.split(",")
27+
.map((author) => author.trim())
28+
.map((user) => `[@${user}](https://github.com/${user})`)
29+
.join(", ");
30+
if (authors.length > 0) {
31+
madeBy = `${authors} and ${madeBy}`;
32+
}
33+
}
34+
lines.push(`Made by ${madeBy}`);
35+
36+
// Contributors
37+
const params = [["repo", github]];
38+
if (args.max) {
39+
params.push(["max", args.max]);
40+
}
41+
if (args.anon) {
42+
params.push(["anon", args.anon]);
43+
}
44+
const paramsStr = params.map(([k, v]) => `${k}=${v}`).join("&");
45+
lines.push(
46+
`<br><br>`,
47+
`<a href="https://github.com/${github}/graphs/contributors">`,
48+
`<img src="https://contrib.rocks/image?${paramsStr}" />`,
49+
`</a>`,
50+
);
51+
52+
return {
53+
contents: lines.join("\n"),
54+
};
55+
},
56+
});

src/generators/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { fetch as _fetch } from "./fetch";
66
import { jsimport } from "./jsimport";
77
import { withAutomd } from "./with-automd";
88
import { file } from "./file";
9+
import { contributors } from "./contributors";
910

1011
export default {
1112
jsdocs,
@@ -17,4 +18,5 @@ export default {
1718
file,
1819
jsimport,
1920
"with-automd": withAutomd,
21+
contributors,
2022
} as Record<string, Generator>;

test/fixture/INPUT.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@
3939

4040
<!-- automd:file src="./TEST.md" -->
4141
<!-- /automd -->
42+
43+
## `contributors`
44+
45+
<!-- automd:contributors author=pi0 license=MIT -->
46+
<!-- /automd -->

test/fixture/OUTPUT.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,16 @@ When your code doesn't work, don't blame yourself. It's clearly the compiler's f
134134
Why waste time solving problems when someone else has already done it for you? Stack Overflow is your best friend, your mentor, and your savior. Just make sure to upvote the answers that save your bacon.
135135

136136
<!-- /automd -->
137+
138+
## `contributors`
139+
140+
<!-- automd:contributors author=pi0 license=MIT -->
141+
142+
Published under the [MIT](https://github.com/unjs/automd/blob/main/LICENSE) license.
143+
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/automd/graphs/contributors) 💛
144+
<br><br>
145+
<a href="https://github.com/unjs/automd/graphs/contributors">
146+
<img src="https://contrib.rocks/image?repo=unjs/automd" />
147+
</a>
148+
149+
<!-- /automd -->

0 commit comments

Comments
 (0)