Skip to content

Commit 51b793b

Browse files
authored
feat(plugin-git): improve performance and tweaks options (#287)
1 parent 3e069d0 commit 51b793b

16 files changed

+489
-431
lines changed

docs/plugins/development/git.md

+20-22
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,7 @@ This plugin will significantly slow down the speed of data preparation, especial
6363
- Type: `boolean | ContributorsOptions`
6464

6565
```ts
66-
interface ContributorsOptions {
67-
/**
68-
* Functions to transform contributors, e.g. remove duplicates ones and sort them.
69-
* The input is the contributors collected by this plugin, and the output should be the transformed contributors.
70-
*/
71-
transform?: (
72-
contributors: GitContributor[],
73-
) => GitContributor[] | Promise<GitContributor[]>
74-
75-
/**
76-
* List of contributors configurations
77-
*/
78-
list?: ContributorConfig[]
79-
80-
/**
81-
* Whether to add avatar in contributor information
82-
* @default false
83-
*/
84-
avatar?: boolean
85-
}
86-
87-
interface ContributorConfig {
66+
interface ContributorInfo {
8867
/**
8968
* Contributor's username on the git hosting service
9069
*/
@@ -115,6 +94,25 @@ This plugin will significantly slow down the speed of data preparation, especial
11594
*/
11695
url?: string
11796
}
97+
98+
interface ContributorsOptions {
99+
/**
100+
* Contributor information
101+
*/
102+
info?: ContributorInfo[]
103+
104+
/**
105+
* Whether to add avatar in contributor information
106+
* @default false
107+
*/
108+
avatar?: boolean
109+
110+
/**
111+
* Functions to transform contributors, e.g. remove duplicates ones and sort them.
112+
* The input is the contributors collected by this plugin, and the output should be the transformed contributors.
113+
*/
114+
transform?: (contributors: GitContributor[]) => GitContributor[]
115+
}
118116
```
119117

120118
- Default: `true`

docs/zh/plugins/development/git.md

+20-22
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,7 @@ export default {
6363
- 类型: `boolean | ContributorsOptions`
6464

6565
```ts
66-
interface ContributorsOptions {
67-
/**
68-
* 贡献者转换函数,例如去重和排序
69-
* 该函数接收一个贡献者信息数组,返回一个新的贡献者信息数组。
70-
*/
71-
transform?: (
72-
contributors: GitContributor[],
73-
) => GitContributor[] | Promise<GitContributor[]>
74-
75-
/**
76-
* 贡献者配置
77-
*/
78-
list?: ContributorConfig[]
79-
80-
/**
81-
* 是否在贡献者信息中添加头像
82-
* @default false
83-
*/
84-
avatar?: boolean
85-
}
86-
87-
interface ContributorConfig {
66+
interface ContributorInfo {
8867
/**
8968
* 贡献者在 git 托管服务中的用户名
9069
*/
@@ -109,6 +88,25 @@ export default {
10988
*/
11089
url?: string
11190
}
91+
92+
interface ContributorsOptions {
93+
/**
94+
* 贡献者信息
95+
*/
96+
info?: ContributorInfo[]
97+
98+
/**
99+
* 是否在贡献者信息中添加头像
100+
* @default false
101+
*/
102+
avatar?: boolean
103+
104+
/**
105+
* 贡献者转换函数,例如去重和排序
106+
* 该函数接收一个贡献者信息数组,返回一个新的贡献者信息数组。
107+
*/
108+
transform?: (contributors: GitContributor[]) => GitContributor[]
109+
}
112110
```
113111

114112
- 默认值: `true`

plugins/development/plugin-git/src/node/gitPlugin.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ import type {
55
GitPluginFrontmatter,
66
GitPluginOptions,
77
GitPluginPageData,
8-
} from './types.js'
9-
import {
10-
checkGitRepo,
11-
getCommits,
12-
inferGitProvider,
13-
resolveChangelog,
14-
resolveContributors,
15-
} from './utils/index.js'
8+
} from './options.js'
9+
import { resolveChangelog } from './resolveChangelog.js'
10+
import { resolveContributors } from './resolveContributors.js'
11+
import { checkGitRepo, getCommits, inferGitProvider } from './utils/index.js'
1612

1713
export const gitPlugin =
1814
({
@@ -74,13 +70,16 @@ export const gitPlugin =
7470
page.data.git.updatedTime = commits[0].date
7571
}
7672

73+
const contributorsOptions = isPlainObject(contributors)
74+
? contributors
75+
: {}
76+
7777
if ((frontmatter.contributors ?? contributors) !== false) {
78-
const options = isPlainObject(contributors) ? contributors : {}
79-
options.transform ??= transformContributors
80-
page.data.git.contributors = await resolveContributors(
78+
contributorsOptions.transform ??= transformContributors
79+
page.data.git.contributors = resolveContributors(
8180
commits,
82-
options,
8381
gitProvider,
82+
contributorsOptions,
8483
Array.isArray(frontmatter.contributors)
8584
? frontmatter.contributors
8685
: [],
@@ -89,15 +88,13 @@ export const gitPlugin =
8988

9089
if (frontmatter.changelog ?? changelog) {
9190
const changelogOptions = isPlainObject(changelog) ? changelog : {}
92-
const contributorsOptions = isPlainObject(contributors)
93-
? contributors
94-
: {}
91+
9592
page.data.git.changelog = resolveChangelog(
9693
app,
9794
commits,
9895
changelogOptions,
9996
gitProvider,
100-
contributorsOptions.list ?? [],
97+
contributorsOptions.info ?? [],
10198
)
10299
}
103100
},
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export * from './gitPlugin.js'
2-
export type * from './types.js'
2+
export * from './resolveChangelog.js'
3+
export * from './resolveContributors.js'
34
export * from './utils/index.js'
5+
export type * from './options.js'
6+
export type * from './typings.js'

0 commit comments

Comments
 (0)