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(plugin-git): improve performance and tweaks options #287

Merged
merged 2 commits into from
Nov 6, 2024
Merged
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
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
29 changes: 13 additions & 16 deletions plugins/development/plugin-git/src/node/gitPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import type {
GitPluginFrontmatter,
GitPluginOptions,
GitPluginPageData,
} from './types.js'
import {
checkGitRepo,
getCommits,
inferGitProvider,
resolveChangelog,
resolveContributors,
} from './utils/index.js'
} from './options.js'
import { resolveChangelog } from './resolveChangelog.js'
import { resolveContributors } from './resolveContributors.js'
import { checkGitRepo, getCommits, inferGitProvider } from './utils/index.js'

export const gitPlugin =
({
Expand Down Expand Up @@ -74,13 +70,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 +88,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
Loading