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): support changelog and improve performance #283

Merged
merged 10 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
185 changes: 177 additions & 8 deletions docs/plugins/development/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<NpmBadge package="@vuepress/plugin-git" />

This plugin will collect git information of your pages, including the created and updated time, the contributors, etc.
This plugin will collect git information of your pages, including the created and updated time, the contributors, the changelogs, etc.

The [lastUpdated](../../themes/default/config.md#lastupdated) and [contributors](../../themes/default/config.md#contributors) of default theme is powered by this plugin.

Expand Down Expand Up @@ -60,25 +60,129 @@ This plugin will significantly slow down the speed of data preparation, especial

### contributors

- Type: `boolean`
- 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 {
/**
* Contributor's username on the git hosting service
*/
username: string
/**
* The alias of the contributor,
* Since contributors may have different usernames saved in their local git configuration
* compared to their usernames on the hosting service, In this case, aliases can be used to
* map to the actual usernames.
*/
alias?: string[] | string
Mister-Hope marked this conversation as resolved.
Show resolved Hide resolved
/**
* The avatar url of the contributor.
*
* If the git hosting service is `github`, it can be ignored and left blank,
* as the plugin will automatically fill it in.
*/
avatar?: string
/**
* The url of the contributor
*
* If the git hosting service is `github`, it can be ignored and left blank,
* as the plugin will automatically fill it in.
*/
url?: string
}
```

- Default: `true`

- Details:

Whether to collect page contributors or not.

### transformContributors

- Type: `(contributors: GitContributor[]) => GitContributor[]`
### changelogs

- Type: `false | ChangelogOptions`

```ts
interface ChangelogOptions {
/**
* Maximum number of changelogs
*/
maxCount?: number

/**
* The url of the git repository, e.g: https://github.com/vuepress/ecosystem
*/
repoUrl?: string

/**
* Commit url pattern
* Default: ':repo/commit/:hash'
*
* - `:repo` - The url of the git repository
* - `:hash` - Hash of the commit record
*/
commitUrlPattern?: string

/**
* Issue url pattern
* Default: ':repo/issues/:issue'
*
* - `:repo` - The url of the git repository
* - `:issue` - Id of the issue
*/
issueUrlPattern?: string

/**
* Tag url pattern
* Default: ':repo/releases/tag/:tag'
*
* - `:repo` - The url of the git repository
* - `:tag` - Name of the tag
*/
tagUrlPattern?: string
}
```

- Default: `false`

- Details:

A function to transform the contributors.
Whether to collect page changelogs or not.

The input is the contributors collected by this plugin, and the output should be the transformed contributors.
### enabled
pengzhanbo marked this conversation as resolved.
Show resolved Hide resolved

You can use it to filter out some contributors, or to sort contributors.
- Type: `boolean | (page: Page) => boolean`

- Default: `true`

- Details:

Whether to enable this plugin or not.

- `true` - Enable the plugin
- `false` - Disable the plugin
- `(page: Page) => boolean` - if `true` is returned, git information will be collected for that page.

## Frontmatter

Expand All @@ -100,6 +204,26 @@ gitInclude:
---
```

### contributors

- Type: `boolean | string[]`

- Details:

Whether to collect contributor information for the current page, this value will override the [contributors](#contributors) configuration item.

- `true` - Collect contributor information
- `false` - Do not collect contributor information
- `string[]` - List of additional contributors, sometimes there are additional contributors on the page, and this configuration item can be used to specify the list of additional contributors to obtain contributor information

### changelogs

- Type: `boolean`

- Details:

Whether to collect the change history for the current page, this value will override the [changelogs](#changelogs) configuration item.

## Page Data

This plugin will add a `git` field to page data.
Expand Down Expand Up @@ -147,6 +271,8 @@ interface GitContributor {
name: string
email: string
commits: number
avatar?: string
url?: string
}
```

Expand All @@ -155,3 +281,46 @@ interface GitContributor {
The contributors information of the page.

This attribute would also include contributors to the files listed in [gitInclude](#gitinclude).

### git.changelogs

- 类型: `GitChangelog[]`

```ts
interface GitChangelog {
/**
* Commit hash
*/
hash: string
/**
* Unix timestamp in milliseconds
*/
date: number
/**
* Commit message
*/
message: string
/**
* Commit author name
*/
author: string
/**
* Commit author email
*/
email: string
/**
* The url of the commit
*/
commitUrl?: string
/**
* The url of the release tag
*/
tagUrl?: string
}
```

- Details:

The changelogs of the page.

This attribute would also include contributors to the files listed in [gitInclude](#gitinclude).
Loading
Loading