git
This plugin collects Git information for your pages, including creation and update timestamps, contributor lists, and changelogs.
The lastUpdated and contributors features in the default theme are powered by this plugin.
This plugin is primarily intended for theme development. In most cases, you will not need to use it directly.
Usage
npm i -D @vuepress/plugin-git@nextimport { gitPlugin } from '@vuepress/plugin-git'
export default {
plugins: [
gitPlugin({
// options
}),
],
}Git Repository
This plugin requires your project to be located within a Git Repository to properly collect data from the commit history.
Ensure that the full commit history is available when building your site. CI workflows often use --depth 1 when cloning repositories to improve performance, which prevents the plugin from accessing the necessary history. You must disable this shallow clone behavior (usually by setting fetch-depth: 0) for the plugin to work correctly in CI environments.
Warning
This plugin may significantly increase data preparation time during builds, especially for projects with a large number of pages. You may consider disabling this plugin in dev mode to improve the development experience.
Options
booleantrueWhether to collect the creation timestamp of the page.
booleantrueWhether to collect the update timestamp of the page.
ContributorsOptions | booleantrueWhether to collect contributor information for the page. You can also pass an object to configure it.
:username- Contributor's username
ContributorInfo[]Pre-defined contributor information.
stringThe contributor's username on the Git hosting service.
stringThe contributor's display name on the page. Defaults to username.
string[] | stringAliases for the contributor. Useful when a contributor's local Git username differs from their hosting service username. Use aliases to map them to the correct account.
stringThe primary email of the contributor.
string[] | stringAlternative emails for the contributor (e.g., emails used in past commits).
stringThe avatar URL of the contributor. If the hosting service is github, this can be left blank, as the plugin will automatically populate it.
stringThe profile URL of the contributor. If the hosting service is github, this can be left blank, as the plugin will automatically populate it.
booleanfalseWhether to include avatars in contributor information.
stringThe pattern for avatar URLs.
(contributors: GitContributorInfo[]) => GitContributorInfo[]A function to transform the contributors list (e.g., to deduplicate or sort). Accepts the list collected by the plugin and returns the transformed list.
ChangelogOptions | booleanfalseWhether to collect the changelog for the page. You can also pass an object to configure it.
:repo- The URL of the Git repository:hash- The hash of the commit:repo- The URL of the Git repository:issue- The ID of the issue:repo- The URL of the Git repository:tag- The name of the tag
numberThe maximum number of changelog entries to collect.
stringThe URL of the Git repository, e.g., https://github.com/vuepress/ecosystem.
string':repo/commit/:hash'The pattern for commit URLs.
string':repo/issues/:issue'The pattern for issue URLs.
string':repo/releases/tag/:tag'The pattern for tag URLs.
(page: Page) => booleanA function to filter pages. Git information will only be collected if this function returns true.
Record<string, GitLocaleData>Locale configuration, primarily used by the Git Components.
See also: Locales.
stringThe title for the contributors section.
stringThe title for the changelog section.
stringThe text representing a commit "on" a specific date.
stringThe text for the "View Changelog" button.
stringThe text for "Latest Updated".
Frontmatter
string[]An array of relative file paths. The Git history of these files will be included when calculating the current page's data (e.g., timestamps and contributors).
---
gitInclude:
- relative/path/to/file1
- relative/path/to/file2
---boolean | string[]Controls the collection of contributor information for the current page. This overrides the global contributors option.
true- Enable collection.false- Disable collection.string[]- A list of additional contributors. Useful for manually specifying contributors who may not appear in the Git history.
booleanWhether to collect the changelog for the current page. This overrides the global changelog option.
Composables
You can import the following composables from @vuepress/plugin-git/client.
useChangelog
Returns the changelog for the current page.
export interface CoAuthorInfo {
/**
* Co-author name
*/
name: string
/**
* Co-author email
*/
email: string
}
export interface GitChangelogItem extends GitChangelogInfo {
/**
* Commit hash
*/
hash: string
/**
* Unix timestamp in milliseconds
*/
time: number
/**
* Commit message
*/
message: string
/**
* The URL of the commit
*/
commitUrl?: string
/**
* Release tag associated with the commit
*/
tag?: string
/**
* The URL of the release tag
*/
tagUrl?: string
/**
* Commit author name
*/
author: string
/**
* Commit author email
*/
email: string
/**
* The co-authors of the commit
*/
coAuthors?: CoAuthorInfo[]
/**
* Formatted date string of the commit
*/
date: string
}
export const useChangelog: (
enabled?: MaybeRefOrGetter<boolean>,
) => ComputedRef<GitChangelogItem[]>useContributors
Returns the list of contributors for the current page.
export interface GitContributorInfo {
/**
* Contributor display name
*/
name: string
/**
* Contributor email
*/
email: string
/**
* Contributor username on the Git hosting service
*/
username: string
/**
* Number of commits
*/
commits: number
/**
* Contributor avatar URL
*/
avatar?: string
/**
* Contributor profile URL
*/
url?: string
}
export const useContributors: (
enabled?: MaybeRefOrGetter<boolean>,
) => ComputedRef<GitContributorInfo[]>useLastUpdated
Returns the last updated time of the current page.
export interface LastUpdated {
/**
* The Date object of the last updated time
*/
date: Date
/**
* The ISO string of the last updated time
*/
iso: string
/**
* The formatted text of the last updated time
*/
text: string
/**
* The locale string for the date format
*/
locale: string
}
export const useLastUpdated: (
enabled?: MaybeRefOrGetter<boolean>,
) => ComputedRef<LastUpdated | null>Page Data
This plugin injects a git field into the page data.
You can access the collected Git information via the page data object:
import type { GitPluginPageData } from '@vuepress/plugin-git'
import { usePage } from 'vuepress/client'
export default {
setup(): void {
const page = usePage<GitPluginPageData>()
console.log(page.value.git)
},
}git.createdTime
Type:
numberDetails:
The Unix timestamp (in milliseconds) of the page's first commit.
This value reflects the earliest commit timestamp among the current page and any files listed in gitInclude.
git.updatedTime
Type:
numberDetails:
The Unix timestamp (in milliseconds) of the page's last commit.
This value reflects the latest commit timestamp among the current page and any files listed in gitInclude.
git.contributors
- Type:
GitContributorInfo[]
interface GitContributorInfo {
// display name
name: string
email: string
// username on the git hosting service
username: string
commits: number
avatar?: string
url?: string
}Details:
The list of contributors for the page.
This list includes contributors from the current page and any files listed in gitInclude.
git.changelog
- Type:
GitChangelogInfo[]
interface CoAuthorInfo {
/**
* Co-author name
*/
name: string
/**
* Co-author email
*/
email: string
}
interface GitChangelogInfo {
/**
* Commit hash
*/
hash: string
/**
* Unix timestamp in milliseconds
*/
time: number
/**
* Commit message
*/
message: string
/**
* The URL of the commit
*/
commitUrl?: string
/**
* Release tag associated with the commit
*/
tag?: string
/**
* The URL of the release tag
*/
tagUrl?: string
/**
* Commit author name
*/
author: string
/**
* Commit author email
*/
email: string
/**
* The co-authors of the commit
*/
coAuthors?: CoAuthorInfo[]
}Details:
The changelog for the page.
This list includes commit history from the current page and any files listed in gitInclude.
Git Component
The plugin registers global components for displaying Git information, which can be easily used within themes.
GitContributors
Displays a list of contributors for the current page.
<template>
<div vp-content>
<Content />
<GitContributors />
</div>
</template>Preview:
Contributors
GitChangelog
Displays the changelog for the current page.
<template>
<div vp-content>
<Content />
<GitChangelog />
</div>
</template>Preview:
Changelog
d715a-on2c88a-on81918-on0f128-on8fc70-ona13d5-on7dd53-ond0d19-on63eb8-onacd14-on56cec-onae96c-ona0241-on51b79-on448d8-onb526b-ond431d-on29ccd-onabd78-on082a9-onceb04-on
