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

refactor!: mv data processing to vite side #269

Merged
merged 9 commits into from
Jul 21, 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
20 changes: 18 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
items: [
{ text: 'Overview', link: '/pages/en/integrations/vitepress-plugin-git-changelog/' },
{ text: 'Getting started', link: '/pages/en/integrations/vitepress-plugin-git-changelog/getting-started' },
{ text: 'Configure UI', link: '/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui' },
{ text: 'Configure Vite Plugins', link: '/pages/en/integrations/vitepress-plugin-git-changelog/configure-vite-plugins' },
{ text: 'Configure UI', link: '/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui' },
],
},
{ text: 'Page properties', link: '/pages/en/integrations/vitepress-plugin-page-properties/' },
Expand Down Expand Up @@ -109,6 +109,10 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
text: 'Migrate from v1 to v2',
link: '/pages/en/releases/migrations/v1-to-v2',
},
{
text: 'Migrate from v2 to v3',
link: '/pages/en/releases/migrations/v2-to-v3',
},
],
},
],
Expand Down Expand Up @@ -193,8 +197,8 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
items: [
{ text: '介绍', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/' },
{ text: '快速上手', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/getting-started' },
{ text: '配置 UI 组件', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui' },
{ text: '配置 Vite 插件', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-vite-plugins' },
{ text: '配置 UI 组件', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui' },
],
},
{ text: '页面属性', link: '/pages/zh-CN/integrations/vitepress-plugin-page-properties/' },
Expand Down Expand Up @@ -227,6 +231,10 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
text: '自 v1 迁移至 v2',
link: '/pages/zh-CN/releases/migrations/v1-to-v2',
},
{
text: '自 v2 迁移至 v3',
link: '/pages/zh-CN/releases/migrations/v2-to-v3',
},
],
},
],
Expand Down Expand Up @@ -358,6 +366,10 @@ export default defineConfig({
text: 'Migrate from v1 to v2',
link: '/pages/en/releases/migrations/v1-to-v2',
},
{
text: 'Migrate from v2 to v3',
link: '/pages/en/releases/migrations/v2-to-v3',
},
],
},
],
Expand Down Expand Up @@ -387,6 +399,10 @@ export default defineConfig({
text: '自 v1 迁移至 v2',
link: '/pages/zh-CN/releases/migrations/v1-to-v2',
},
{
text: '自 v2 迁移至 v3',
link: '/pages/zh-CN/releases/migrations/v2-to-v3',
},
],
},
],
Expand Down
22 changes: 0 additions & 22 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,6 @@ export default defineThemeUnconfig({
gitChangelog: {
enable: true,
options: {
mapContributors: [
{
name: 'Neko',
username: 'nekomeowww',
mapByNameAliases: ['Neko Ayaka', 'Ayaka Neko'],
mapByEmailAliases: ['[email protected]'],
},
{
name: 'Rizumu',
username: 'LittleSound',
mapByNameAliases: ['Rizumu Ayaka', 'Ayaka Rizumu'],
mapByEmailAliases: ['[email protected]'],
},
{
name: 'Nisekoi5',
username: 'Nisekoi5',
},
{
name: 'Northword',
username: 'northword',
},
],
commitsRelativeTime: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Configuration

The Git-based page histories plugin currently provides configuration options related to **Internationalization** and **Contributors** section.
::: danger Deprecating the `mapAuthors` field for UI component options

We migrated the `mapAuthors` configuration to [configure Vite plugins](./configure-vite-plugins#option-mapauthors---map-contributors-information).

For specific migration information, see [Migrating from v2 to v3](/pages/en/releases/migrations/v2-to-v3).

:::

The Git-based page histories plugin currently provides configuration options related to **Internationalization** and **UI** section.

## Configure in VitePress

Expand Down Expand Up @@ -67,59 +75,6 @@ export const Theme: ThemeConfig = {
}
```

### Option `mapAuthors` - Map contributors' information

The `mapAuthors` field in the configuration options is used to map the contributors' information. You can provide the `mapAuthors` field in the configuration options to map the contributors' information, including the display name, avatar, email, social links, and aliases.

Let's say we have these logs:

```plaintext
commit 1
Author: John Doe <[email protected]>
Date: Fri Oct 1 12:00:00 2021 +0800

Add a new feature

commit 2
Author: John Doe <[email protected]>

Fix a bug
```

We now have two commits from the same person, with only the email address is different. By default, the plugin will treat them as two different contributors.
Such case happens when you changed your name or email address in the past.

To solve this, you can provide the `mapAuthors` field in the configuration options to map the contributors' information:

```typescript twoslash
import type { Theme as ThemeConfig } from 'vitepress'
import DefaultTheme from 'vitepress/theme'

import { InjectionKey } from '@nolebase/vitepress-plugin-git-changelog/client' // [!code focus]

export const Theme: ThemeConfig = {
extends: DefaultTheme,
Layout: () => {
// Rest of the code...
},
enhanceApp({ app }) {
// Rest of the code...

app.provide(InjectionKey, { // [!code focus]
mapAuthors: [ // [!code focus]
{ // [!code focus]
name: 'John Doe', // [!code focus]
username: 'john_doe', // [!code focus]
mapByEmailAliases: ['[email protected]'] // [!code focus]
} // [!code focus]
] // [!code focus]
}) // [!code focus]

// Rest of the code...
},
}
```

## Options inside

::: warning Deprecating warning
Expand Down Expand Up @@ -224,36 +179,6 @@ export interface Options {
* ```
*/
locales?: Record<string, Locale>
mapAuthors?: Array<{
/**
* The overriding display name of the contributor
*/
name?: string
/**
* The overriding GitHub, GitLab, Gitea username of the contributor
*/
username?: string
/**
* The overriding avatar of the contributor
*/
avatar?: string
/**
* Whether to add a link to the contributor's profile
*/
links?: string | SocialEntry[]
/**
* More names to be recognized as the same contributor.
*
* Useful when you changed your name or email address in the past.
*/
mapByNameAliases?: string[]
/**
* More emails to be recognized as the same contributor.
*
* Useful when you changed your email address in the past.
*/
mapByEmailAliases?: string[]
}>
/**
* Number of commit hash letters to display
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ For information, please refer to [Migrate from v1 to v2](/pages/en/releases/migr

Besides the UI widget components, Git-based page histories offer another two Vite plugins for data fetching and rendering. These plugins are `GitChangelog` and `GitChangelogMarkdownSection`.

### Configure Vite plugins

<!--@include: @/pages/en/snippets/configure-tsconfig.md-->

#### `GitChangelog` plugin
## Configure `GitChangelog` plugin

Remember this part back at the time where we first introduced the `GitChangelog` plugin?

Expand Down Expand Up @@ -42,16 +40,74 @@ export default defineConfig(() => {

In the `GitChangelog` plugin, you can configure the `repoURL` option to point to your repository URL. This is the only required option for the plugin to work properly.

### Option `mapAuthors` - Map contributors' information

The `mapAuthors` field in the configuration options is used to map the contributors' information. You can provide the `mapAuthors` field in the configuration options to map the contributors' information, including the display name, avatar, email, social links, and aliases.

Let's say we have these logs:

```plaintext
commit 1
Author: John Doe <[email protected]>
Date: Fri Oct 1 12:00:00 2021 +0800

Add a new feature

commit 2
Author: John Doe <[email protected]>

Fix a bug
```

We now have two commits from the same person, with only the email address is different. By default, the plugin will treat them as two different contributors.
Such case happens when you changed your name or email address in the past.

To solve this, you can provide the `mapAuthors` field in the configuration options to map the contributors' information:

```typescript twoslash
import { join } from 'node:path'
import { defineConfig } from 'vite'
import {
GitChangelog,
GitChangelogMarkdownSection,
} from '@nolebase/vitepress-plugin-git-changelog/vite'

export default defineConfig(() => {
return {
plugins: [
GitChangelog({ // [!code focus]
// Fill in your repository URL here
repoURL: () => 'https://github.com/nolebase/integrations',
mapAuthors: [ // [!code focus]
{ // [!code focus]
name: 'John Doe', // [!code focus]
username: 'john_doe', // [!code focus]
mapByEmailAliases: ['[email protected]'] // [!code focus]
} // [!code focus]
] // [!code focus]
}), // [!code focus]
GitChangelogMarkdownSection(),
]
// other vite configurations...
}
})
```

### All options

But the options don't stop there. We have more options to configure the plugin to fit your needs.

::: details Full list of options

```typescript twoslash
import type {
Commit, CommitToStringHandler, CommitToStringsHandler, RewritePathsBy
Author,
CommitToStringHandler,
CommitToStringsHandler,
RewritePathsBy
} from '@nolebase/vitepress-plugin-git-changelog/vite'
// ---cut---
interface Options {
interface GitChangelogOptions {
/**
* The current working directory in which to search files.
*
Expand All @@ -64,6 +120,10 @@ interface Options {
* @default ['** /*.md', '!node_modules']
*/
include?: string[]
/**
* Map authors
*/
mapAuthors?: Author[]
/**
* Your repository URL.
* Yes, you can dynamically generate it.
Expand Down Expand Up @@ -144,7 +204,7 @@ interface Options {

:::

#### `GitChangelogMarkdownSection` plugin
## Configure `GitChangelogMarkdownSection` plugin

The `GitChangelogMarkdownSection` plugin is a plugin that helps you to inject the Markdown sections into your VitePress pages. It's a plugin that works with the `GitChangelog` plugin to provide the data for the Markdown sections.

Expand Down Expand Up @@ -205,7 +265,7 @@ interface GitChangelogMarkdownSectionOptions {

:::

#### Excluding a page from the transformation of `GitChangelogMarkdownSection`
### Excluding a page from the transformation of `GitChangelogMarkdownSection`

You can exclude a page from the transformation of `GitChangelogMarkdownSection` by adding the `nolebase.gitChangelog` or `gitChangelog` frontmatter to the page:

Expand All @@ -224,7 +284,7 @@ gitChangelog: false
---
```

#### Globally exclude a page from the transformation of `GitChangelogMarkdownSection`
### Globally exclude a page from the transformation of `GitChangelogMarkdownSection`

You can globally exclude a page from the transformation of `GitChangelogMarkdownSection` by configuring the `exclude` option:

Expand All @@ -244,7 +304,7 @@ export default defineConfig({
})
```

#### Globally disable the changelog or contributors section
### Globally disable the changelog or contributors section

You can globally disable the changelog or contributors section by configuring the `sections` option:

Expand Down
7 changes: 7 additions & 0 deletions docs/pages/en/releases/migrations/v2-to-v3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Migrating from `v2` to `v3

## Git-based page history

### UI configuration

- `mapAuthors` is deprecated, please configure this option in the Vite plugin.
Loading
Loading