Skip to content

Commit 59543b2

Browse files
authored
refactor!: mv data processing to vite side (#269)
* refactor!: mv data processing to vite side * fix: build error, clean code, tweaks * test: complate test cases * docs: refresh docs * docs: add missed pages * fix: types error * refactor: mv hmr logic to composable * style: fix lint * docs: add v2->v3 to nav and sidebar
1 parent f6c5fae commit 59543b2

29 files changed

Lines changed: 1182 additions & 1074 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
6969
items: [
7070
{ text: 'Overview', link: '/pages/en/integrations/vitepress-plugin-git-changelog/' },
7171
{ text: 'Getting started', link: '/pages/en/integrations/vitepress-plugin-git-changelog/getting-started' },
72-
{ text: 'Configure UI', link: '/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui' },
7372
{ text: 'Configure Vite Plugins', link: '/pages/en/integrations/vitepress-plugin-git-changelog/configure-vite-plugins' },
73+
{ text: 'Configure UI', link: '/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui' },
7474
],
7575
},
7676
{ text: 'Page properties', link: '/pages/en/integrations/vitepress-plugin-page-properties/' },
@@ -109,6 +109,10 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
109109
text: 'Migrate from v1 to v2',
110110
link: '/pages/en/releases/migrations/v1-to-v2',
111111
},
112+
{
113+
text: 'Migrate from v2 to v3',
114+
link: '/pages/en/releases/migrations/v2-to-v3',
115+
},
112116
],
113117
},
114118
],
@@ -193,8 +197,8 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
193197
items: [
194198
{ text: '介绍', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/' },
195199
{ text: '快速上手', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/getting-started' },
196-
{ text: '配置 UI 组件', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui' },
197200
{ text: '配置 Vite 插件', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-vite-plugins' },
201+
{ text: '配置 UI 组件', link: '/pages/zh-CN/integrations/vitepress-plugin-git-changelog/configure-ui' },
198202
],
199203
},
200204
{ text: '页面属性', link: '/pages/zh-CN/integrations/vitepress-plugin-page-properties/' },
@@ -227,6 +231,10 @@ export const sidebars: Record<string, DefaultTheme.Sidebar> = {
227231
text: '自 v1 迁移至 v2',
228232
link: '/pages/zh-CN/releases/migrations/v1-to-v2',
229233
},
234+
{
235+
text: '自 v2 迁移至 v3',
236+
link: '/pages/zh-CN/releases/migrations/v2-to-v3',
237+
},
230238
],
231239
},
232240
],
@@ -358,6 +366,10 @@ export default defineConfig({
358366
text: 'Migrate from v1 to v2',
359367
link: '/pages/en/releases/migrations/v1-to-v2',
360368
},
369+
{
370+
text: 'Migrate from v2 to v3',
371+
link: '/pages/en/releases/migrations/v2-to-v3',
372+
},
361373
],
362374
},
363375
],
@@ -387,6 +399,10 @@ export default defineConfig({
387399
text: '自 v1 迁移至 v2',
388400
link: '/pages/zh-CN/releases/migrations/v1-to-v2',
389401
},
402+
{
403+
text: '自 v2 迁移至 v3',
404+
link: '/pages/zh-CN/releases/migrations/v2-to-v3',
405+
},
390406
],
391407
},
392408
],

docs/.vitepress/theme/index.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,6 @@ export default defineThemeUnconfig({
5454
gitChangelog: {
5555
enable: true,
5656
options: {
57-
mapContributors: [
58-
{
59-
name: 'Neko',
60-
username: 'nekomeowww',
61-
mapByNameAliases: ['Neko Ayaka', 'Ayaka Neko'],
62-
mapByEmailAliases: ['neko@ayaka.moe'],
63-
},
64-
{
65-
name: 'Rizumu',
66-
username: 'LittleSound',
67-
mapByNameAliases: ['Rizumu Ayaka', 'Ayaka Rizumu'],
68-
mapByEmailAliases: ['rizumu@ayaka.moe'],
69-
},
70-
{
71-
name: 'Nisekoi5',
72-
username: 'Nisekoi5',
73-
},
74-
{
75-
name: 'Northword',
76-
username: 'northword',
77-
},
78-
],
7957
commitsRelativeTime: true,
8058
},
8159
},

docs/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui.md

Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Configuration
22

3-
The Git-based page histories plugin currently provides configuration options related to **Internationalization** and **Contributors** section.
3+
::: danger Deprecating the `mapAuthors` field for UI component options
4+
5+
We migrated the `mapAuthors` configuration to [configure Vite plugins](./configure-vite-plugins#option-mapauthors---map-contributors-information).
6+
7+
For specific migration information, see [Migrating from v2 to v3](/pages/en/releases/migrations/v2-to-v3).
8+
9+
:::
10+
11+
The Git-based page histories plugin currently provides configuration options related to **Internationalization** and **UI** section.
412

513
## Configure in VitePress
614

@@ -67,59 +75,6 @@ export const Theme: ThemeConfig = {
6775
}
6876
```
6977

70-
### Option `mapAuthors` - Map contributors' information
71-
72-
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.
73-
74-
Let's say we have these logs:
75-
76-
```plaintext
77-
commit 1
78-
Author: John Doe <john.doe@example.com>
79-
Date: Fri Oct 1 12:00:00 2021 +0800
80-
81-
Add a new feature
82-
83-
commit 2
84-
Author: John Doe <john.doe@anothersite.com>
85-
86-
Fix a bug
87-
```
88-
89-
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.
90-
Such case happens when you changed your name or email address in the past.
91-
92-
To solve this, you can provide the `mapAuthors` field in the configuration options to map the contributors' information:
93-
94-
```typescript twoslash
95-
import type { Theme as ThemeConfig } from 'vitepress'
96-
import DefaultTheme from 'vitepress/theme'
97-
98-
import { InjectionKey } from '@nolebase/vitepress-plugin-git-changelog/client' // [!code focus]
99-
100-
export const Theme: ThemeConfig = {
101-
extends: DefaultTheme,
102-
Layout: () => {
103-
// Rest of the code...
104-
},
105-
enhanceApp({ app }) {
106-
// Rest of the code...
107-
108-
app.provide(InjectionKey, { // [!code focus]
109-
mapAuthors: [ // [!code focus]
110-
{ // [!code focus]
111-
name: 'John Doe', // [!code focus]
112-
username: 'john_doe', // [!code focus]
113-
mapByEmailAliases: ['john.doe@anothersite.com'] // [!code focus]
114-
} // [!code focus]
115-
] // [!code focus]
116-
}) // [!code focus]
117-
118-
// Rest of the code...
119-
},
120-
}
121-
```
122-
12378
## Options inside
12479

12580
::: warning Deprecating warning
@@ -224,36 +179,6 @@ export interface Options {
224179
* ```
225180
*/
226181
locales?: Record<string, Locale>
227-
mapAuthors?: Array<{
228-
/**
229-
* The overriding display name of the contributor
230-
*/
231-
name?: string
232-
/**
233-
* The overriding GitHub, GitLab, Gitea username of the contributor
234-
*/
235-
username?: string
236-
/**
237-
* The overriding avatar of the contributor
238-
*/
239-
avatar?: string
240-
/**
241-
* Whether to add a link to the contributor's profile
242-
*/
243-
links?: string | SocialEntry[]
244-
/**
245-
* More names to be recognized as the same contributor.
246-
*
247-
* Useful when you changed your name or email address in the past.
248-
*/
249-
mapByNameAliases?: string[]
250-
/**
251-
* More emails to be recognized as the same contributor.
252-
*
253-
* Useful when you changed your email address in the past.
254-
*/
255-
mapByEmailAliases?: string[]
256-
}>
257182
/**
258183
* Number of commit hash letters to display
259184
*

docs/pages/en/integrations/vitepress-plugin-git-changelog/configure-vite-plugins.md

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ For information, please refer to [Migrate from v1 to v2](/pages/en/releases/migr
1010

1111
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`.
1212

13-
### Configure Vite plugins
14-
1513
<!--@include: @/pages/en/snippets/configure-tsconfig.md-->
1614

17-
#### `GitChangelog` plugin
15+
## Configure `GitChangelog` plugin
1816

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

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

4341
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.
4442

43+
### Option `mapAuthors` - Map contributors' information
44+
45+
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.
46+
47+
Let's say we have these logs:
48+
49+
```plaintext
50+
commit 1
51+
Author: John Doe <john.doe@example.com>
52+
Date: Fri Oct 1 12:00:00 2021 +0800
53+
54+
Add a new feature
55+
56+
commit 2
57+
Author: John Doe <john.doe@anothersite.com>
58+
59+
Fix a bug
60+
```
61+
62+
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.
63+
Such case happens when you changed your name or email address in the past.
64+
65+
To solve this, you can provide the `mapAuthors` field in the configuration options to map the contributors' information:
66+
67+
```typescript twoslash
68+
import { join } from 'node:path'
69+
import { defineConfig } from 'vite'
70+
import {
71+
GitChangelog,
72+
GitChangelogMarkdownSection,
73+
} from '@nolebase/vitepress-plugin-git-changelog/vite'
74+
75+
export default defineConfig(() => {
76+
return {
77+
plugins: [
78+
GitChangelog({ // [!code focus]
79+
// Fill in your repository URL here
80+
repoURL: () => 'https://github.com/nolebase/integrations',
81+
mapAuthors: [ // [!code focus]
82+
{ // [!code focus]
83+
name: 'John Doe', // [!code focus]
84+
username: 'john_doe', // [!code focus]
85+
mapByEmailAliases: ['john.doe@anothersite.com'] // [!code focus]
86+
} // [!code focus]
87+
] // [!code focus]
88+
}), // [!code focus]
89+
GitChangelogMarkdownSection(),
90+
]
91+
// other vite configurations...
92+
}
93+
})
94+
```
95+
96+
### All options
97+
4598
But the options don't stop there. We have more options to configure the plugin to fit your needs.
4699

47100
::: details Full list of options
48101

49102
```typescript twoslash
50103
import type {
51-
Commit, CommitToStringHandler, CommitToStringsHandler, RewritePathsBy
104+
Author,
105+
CommitToStringHandler,
106+
CommitToStringsHandler,
107+
RewritePathsBy
52108
} from '@nolebase/vitepress-plugin-git-changelog/vite'
53109
// ---cut---
54-
interface Options {
110+
interface GitChangelogOptions {
55111
/**
56112
* The current working directory in which to search files.
57113
*
@@ -64,6 +120,10 @@ interface Options {
64120
* @default ['** /*.md', '!node_modules']
65121
*/
66122
include?: string[]
123+
/**
124+
* Map authors
125+
*/
126+
mapAuthors?: Author[]
67127
/**
68128
* Your repository URL.
69129
* Yes, you can dynamically generate it.
@@ -144,7 +204,7 @@ interface Options {
144204

145205
:::
146206

147-
#### `GitChangelogMarkdownSection` plugin
207+
## Configure `GitChangelogMarkdownSection` plugin
148208

149209
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.
150210

@@ -205,7 +265,7 @@ interface GitChangelogMarkdownSectionOptions {
205265

206266
:::
207267

208-
#### Excluding a page from the transformation of `GitChangelogMarkdownSection`
268+
### Excluding a page from the transformation of `GitChangelogMarkdownSection`
209269

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

@@ -224,7 +284,7 @@ gitChangelog: false
224284
---
225285
```
226286

227-
#### Globally exclude a page from the transformation of `GitChangelogMarkdownSection`
287+
### Globally exclude a page from the transformation of `GitChangelogMarkdownSection`
228288

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

@@ -244,7 +304,7 @@ export default defineConfig({
244304
})
245305
```
246306

247-
#### Globally disable the changelog or contributors section
307+
### Globally disable the changelog or contributors section
248308

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Migrating from `v2` to `v3
2+
3+
## Git-based page history
4+
5+
### UI configuration
6+
7+
- `mapAuthors` is deprecated, please configure this option in the Vite plugin.

0 commit comments

Comments
 (0)