Skip to content

Commit

Permalink
feat(plugin-git): improve performance and tweaks options
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 6, 2024
1 parent 3e069d0 commit 3d0a24d
Show file tree
Hide file tree
Showing 16 changed files with 486 additions and 424 deletions.
42 changes: 20 additions & 22 deletions docs/plugins/development/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,7 @@ This plugin will significantly slow down the speed of data preparation, especial
- Type: `boolean | ContributorsOptions`

```ts
interface ContributorsOptions {
/**
* Functions to transform contributors, e.g. remove duplicates ones and sort them.
* The input is the contributors collected by this plugin, and the output should be the transformed contributors.
*/
transform?: (
contributors: GitContributor[],
) => GitContributor[] | Promise<GitContributor[]>

/**
* List of contributors configurations
*/
list?: ContributorConfig[]

/**
* Whether to add avatar in contributor information
* @default false
*/
avatar?: boolean
}

interface ContributorConfig {
interface ContributorInfo {
/**
* Contributor's username on the git hosting service
*/
Expand Down Expand Up @@ -115,6 +94,25 @@ This plugin will significantly slow down the speed of data preparation, especial
*/
url?: string
}

interface ContributorsOptions {
/**
* Contributor information
*/
info?: ContributorInfo[]

/**
* Whether to add avatar in contributor information
* @default false
*/
avatar?: boolean

/**
* Functions to transform contributors, e.g. remove duplicates ones and sort them.
* The input is the contributors collected by this plugin, and the output should be the transformed contributors.
*/
transform?: (contributors: GitContributor[]) => GitContributor[]
}
```

- Default: `true`
Expand Down
42 changes: 20 additions & 22 deletions docs/zh/plugins/development/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,7 @@ export default {
- 类型: `boolean | ContributorsOptions`

```ts
interface ContributorsOptions {
/**
* 贡献者转换函数,例如去重和排序
* 该函数接收一个贡献者信息数组,返回一个新的贡献者信息数组。
*/
transform?: (
contributors: GitContributor[],
) => GitContributor[] | Promise<GitContributor[]>

/**
* 贡献者配置
*/
list?: ContributorConfig[]

/**
* 是否在贡献者信息中添加头像
* @default false
*/
avatar?: boolean
}

interface ContributorConfig {
interface ContributorInfo {
/**
* 贡献者在 git 托管服务中的用户名
*/
Expand All @@ -109,6 +88,25 @@ export default {
*/
url?: string
}

interface ContributorsOptions {
/**
* 贡献者信息
*/
info?: ContributorInfo[]

/**
* 是否在贡献者信息中添加头像
* @default false
*/
avatar?: boolean

/**
* 贡献者转换函数,例如去重和排序
* 该函数接收一个贡献者信息数组,返回一个新的贡献者信息数组。
*/
transform?: (contributors: GitContributor[]) => GitContributor[]
}
```

- 默认值: `true`
Expand Down
19 changes: 10 additions & 9 deletions plugins/development/plugin-git/src/node/gitPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
GitPluginFrontmatter,
GitPluginOptions,
GitPluginPageData,
} from './types.js'
} from './options.js'
import {
checkGitRepo,
getCommits,
Expand Down Expand Up @@ -74,13 +74,16 @@ export const gitPlugin =
page.data.git.updatedTime = commits[0].date
}

const contributorsOptions = isPlainObject(contributors)
? contributors
: {}

if ((frontmatter.contributors ?? contributors) !== false) {
const options = isPlainObject(contributors) ? contributors : {}
options.transform ??= transformContributors
page.data.git.contributors = await resolveContributors(
contributorsOptions.transform ??= transformContributors
page.data.git.contributors = resolveContributors(
commits,
options,
gitProvider,
contributorsOptions,
Array.isArray(frontmatter.contributors)
? frontmatter.contributors
: [],
Expand All @@ -89,15 +92,13 @@ export const gitPlugin =

if (frontmatter.changelog ?? changelog) {
const changelogOptions = isPlainObject(changelog) ? changelog : {}
const contributorsOptions = isPlainObject(contributors)
? contributors
: {}

page.data.git.changelog = resolveChangelog(
app,
commits,
changelogOptions,
gitProvider,
contributorsOptions.list ?? [],
contributorsOptions.info ?? [],
)
}
},
Expand Down
5 changes: 4 additions & 1 deletion plugins/development/plugin-git/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export * from './gitPlugin.js'
export type * from './types.js'
export * from './resolveChangelog.js'
export * from './resolveContributors.js'
export * from './utils/index.js'
export type * from './options.js'
export type * from './typings.js'
Loading

0 comments on commit 3d0a24d

Please sign in to comment.