Skip to content

Commit 04fb100

Browse files
nekomeowwwBeiyanYunyinorthword
authored
refactor(git-changelog): migrate i18n to ui config (#213)
* refactor(git-changelog): migrate i18n to ui config 1. The `locales` in the original Vite plugin `GitChangelogMarkdownSection` no longer need to be configured and have been migrated to the UI configuration under `locales`: 1. `changelog.title` 2. `contributors.title`; 2. In order to better structure the organization of the i18n fields, the original 1. `noLogs` i18n configuration changed to `changelog.noData`; 2. `noContributors` i18n configuration was changed to `contributors.noData`. 3. `lastEdited` i18n Configuration changed to `lastEdited`. 4. `lastEditedDateFnsLocaleName` configuration changed to `changelog.lastEditedDateFnsLocaleName` 5. `viewFullHistory` i18n Configuration changed to `changelog.viewFullHistory` 6. `committedOn` i18n configuration changed to `changelog.committedOn` * fix: migrate vite.config.ts * docs: update docs/pages/en/releases/migrations/v1-to-v2.md * docs: update docs/pages/zh-CN/releases/migrations/v1-to-v2.md --------- Signed-off-by: Neko Ayaka <neko@ayaka.moe> Co-authored-by: BeiyanYunyi <14120445+BeiyanYunyi@users.noreply.github.com> Co-authored-by: Northword <44738481+northword@users.noreply.github.com>
1 parent d557690 commit 04fb100

21 files changed

Lines changed: 371 additions & 696 deletions

File tree

cspell.config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ words:
5555
- uncrypto
5656
- unlazy
5757
- unocss
58+
- Vite
5859
- vitepress
5960
- vueuse
6061
ignoreWords: []

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

Lines changed: 104 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ export const Theme: ThemeConfig = {
122122

123123
## Options inside
124124

125+
::: warning Deprecating warning
126+
127+
We have changed the structure of locales config since `2.0.0-rc14`, and the old structure will be deprecated in the next major version. Please update your configuration according to the new structure. For migration guides, see [Migrate from v1 to v2](/pages/en/releases/migrations/v1-to-v2).
128+
129+
:::
130+
125131
::: details Complete configurable options
126132

127133
```typescript twoslash
@@ -133,29 +139,47 @@ interface SocialEntry {
133139

134140
interface Locale extends Record<string, any> {
135141
/**
136-
* What to display when there are no logs
137-
*/
138-
noLogs?: string
139-
/**
140-
* What to display when there are no contributors
141-
*/
142-
noContributors?: string
143-
/**
144-
* What to display when the page was last edited
142+
* The changelog section configuration
145143
*/
146-
lastEdited?: string
147-
/**
148-
* The name of the locale to use for date-fns
149-
*/
150-
lastEditedDateFnsLocaleName?: string
151-
/**
152-
* What to display when the user wants to view the full history
153-
*/
154-
viewFullHistory?: string
144+
changelog?: {
145+
/**
146+
* The title of the changelog section
147+
*/
148+
title?: string
149+
/**
150+
* What to display when there are no logs
151+
*/
152+
noData?: string
153+
/**
154+
* What to display when the page was last edited
155+
*/
156+
lastEdited?: string
157+
/**
158+
* The name of the locale to use for date-fns
159+
*/
160+
lastEditedDateFnsLocaleName?: string
161+
/**
162+
* What to display when the user wants to view the full history
163+
*/
164+
viewFullHistory?: string
165+
/**
166+
* What to display when the commit was committed
167+
*/
168+
committedOn?: string
169+
}
155170
/**
156-
* What to display when the commit was committed
171+
* The contributors section configuration
157172
*/
158-
committedOn?: string
173+
contributors?: {
174+
/**
175+
* The title of the contributors section
176+
*/
177+
title?: string
178+
/**
179+
* What to display when there are no contributors
180+
*/
181+
noData?: string
182+
}
159183
}
160184
// ---cut---
161185
/**
@@ -176,18 +200,24 @@ export interface Options {
176200
* {
177201
* locales: {
178202
* 'en': {
179-
* noLogs: 'No recent changes',
180-
* lastEdited: 'This page was last edited {{daysAgo}}',
181-
* lastEditedDateFnsLocaleName: 'enUS',
182-
* viewFullHistory: 'View full history',
183-
* committedOn: ' on {{date}}',
203+
* changelog: {
204+
* title: 'Changelog',
205+
* noData: 'No recent changes',
206+
* lastEdited: 'This page was last edited {{daysAgo}}',
207+
* lastEditedDateFnsLocaleName: 'enUS',
208+
* viewFullHistory: 'View full history',
209+
* committedOn: ' on {{date}}',
210+
* }
184211
* },
185212
* 'zh-CN': {
186-
* noLogs: '暂无最近变更历史',
187-
* lastEdited: '本页面最后编辑于 {{daysAgo}}',
188-
* lastEditedDateFnsLocaleName: 'zhCN',
189-
* viewFullHistory: '查看完整历史',
190-
* committedOn: '于 {{date}} 提交',
213+
* changelog: {
214+
* title: '页面历史'
215+
* noData: '暂无最近变更历史',
216+
* lastEdited: '本页面最后编辑于 {{daysAgo}}',
217+
* lastEditedDateFnsLocaleName: 'zhCN',
218+
* viewFullHistory: '查看完整历史',
219+
* committedOn: '于 {{date}} 提交',
220+
* }
191221
* },
192222
* }
193223
* }
@@ -287,6 +317,12 @@ export const Theme: ThemeConfig = {
287317

288318
### Locales options
289319

320+
::: warning Deprecating warning
321+
322+
We have changed the structure of locales config since `2.0.0-rc14`, and the old structure will be deprecated in the next major version. Please update your configuration according to the new structure. For migration guides, see [Migrate from v1 to v2](/pages/en/releases/migrations/v1-to-v2).
323+
324+
:::
325+
290326
::: details Complete internationalization field options
291327

292328
```typescript twoslash
@@ -295,29 +331,47 @@ export const Theme: ThemeConfig = {
295331
*/
296332
interface Locale {
297333
/**
298-
* What to display when there are no logs
299-
*/
300-
noLogs?: string
301-
/**
302-
* What to display when there are no contributors
303-
*/
304-
noContributors?: string
305-
/**
306-
* What to display when the page was last edited
334+
* The changelog section configuration
307335
*/
308-
lastEdited?: string
309-
/**
310-
* The name of the locale to use for date-fns
311-
*/
312-
lastEditedDateFnsLocaleName?: string
313-
/**
314-
* What to display when the user wants to view the full history
315-
*/
316-
viewFullHistory?: string
336+
changelog?: {
337+
/**
338+
* The title of the changelog section
339+
*/
340+
title?: string
341+
/**
342+
* What to display when there are no logs
343+
*/
344+
noData?: string
345+
/**
346+
* What to display when the page was last edited
347+
*/
348+
lastEdited?: string
349+
/**
350+
* The name of the locale to use for date-fns
351+
*/
352+
lastEditedDateFnsLocaleName?: string
353+
/**
354+
* What to display when the user wants to view the full history
355+
*/
356+
viewFullHistory?: string
357+
/**
358+
* What to display when the commit was committed
359+
*/
360+
committedOn?: string
361+
}
317362
/**
318-
* What to display when the commit was committed
363+
* The contributors section configuration
319364
*/
320-
committedOn?: string
365+
contributors?: {
366+
/**
367+
* The title of the contributors section
368+
*/
369+
title?: string
370+
/**
371+
* What to display when there are no contributors
372+
*/
373+
noData?: string
374+
}
321375
}
322376
```
323377

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

Lines changed: 9 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Configure Vite plugins
22

3+
::: danger Deprecating the `locales` field of `GitChangelogMarkdownSection` plugin options
4+
5+
We migrated the `locales` configurations to [UI config](/pages/en/integrations/vitepress-plugin-git-changelog/configure-ui#locales-options). You no longer need to set `locales` for `GitChangelogMarkdownSection` plugin.
6+
7+
For information, please refer to [Migrate from v1 to v2](/pages/en/releases/migrations/v1-to-v2).
8+
9+
:::
10+
311
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`.
412

513
### Configure Vite plugins
@@ -161,33 +169,9 @@ It does have more options to configure.
161169
::: details Full list of options
162170

163171
```typescript twoslash
164-
import type { Context, Locale } from '@nolebase/vitepress-plugin-git-changelog/vite'
172+
import type { Context } from '@nolebase/vitepress-plugin-git-changelog/vite'
165173
// ---cut---
166174
interface GitChangelogMarkdownSectionOptions {
167-
/**
168-
* The locales options
169-
*/
170-
locales?: Record<string, Locale>
171-
/**
172-
* The getter function to get the title of the changelog section
173-
*
174-
* @param code - raw markdown code (comes from vite when transform hook is called)
175-
* @param id - the current transforming module ID (comes from vite when transform hook is called)
176-
* @param context - the context object, contains several helper functions
177-
* @returns string
178-
* @default () => 'Changelog'
179-
*/
180-
getChangelogTitle?: (code: string, id: string, context: Context) => string
181-
/**
182-
* The getter function to get the title of the contributors section
183-
*
184-
* @param code - raw markdown code (comes from vite when transform hook is called)
185-
* @param id - the current transforming module ID (comes from vite when transform hook is called)
186-
* @param context - the context object, contains several helper functions
187-
* @returns string
188-
* @default () => 'Contributors'
189-
*/
190-
getContributorsTitle?: (code: string, id: string, context: Context) => string
191175
/**
192176
* The list of file names to exclude from the transformation
193177
*
@@ -221,85 +205,6 @@ interface GitChangelogMarkdownSectionOptions {
221205

222206
:::
223207

224-
#### Internationalization
225-
226-
The `GitChangelogMarkdownSection` plugin supports internationalization. You can configure the `locales` option to provide the translations for the section titles.
227-
228-
::: tip Why internationalization again, in Vite plugin, seriously?
229-
230-
VitePress has a function called [outline](https://vitepress.dev/reference/default-theme-config#outline), where it read all the heading titles in one page and generate the sidebar navigation based on these data.
231-
232-
So in order to make the changelog (page history) and contributors section titles to be included into outline, we have to inject them into the Markdown before it got rendered into HTML, then pass them to VitePress to render the pages into HTML.
233-
234-
And transforming and manipulating `markdown-it` AST tree is a tough work to do by comparing to directly manipulate them in Vite plugins, or through Remark API, but this would be another story for another time.
235-
236-
In conclusion, we have to inject the sections into the Markdown before it got rendered into HTML, as well as the internationalization support.
237-
238-
:::
239-
240-
```typescript twoslash
241-
import { defineConfig } from 'vite'
242-
import { // [!code focus]
243-
GitChangelogMarkdownSection, // [!code focus]
244-
} from '@nolebase/vitepress-plugin-git-changelog/vite' // [!code focus]
245-
246-
export default defineConfig({
247-
plugins: [
248-
GitChangelogMarkdownSection({ // [!code focus]
249-
locales: { // [!code focus]
250-
'zh-CN': { // [!code focus]
251-
gitChangelogMarkdownSectionTitles: { // [!code focus]
252-
changelog: '文件历史', // [!code focus]
253-
contributors: '贡献者', // [!code focus]
254-
}, // [!code focus]
255-
}, // [!code focus]
256-
'en': { // [!code focus]
257-
gitChangelogMarkdownSectionTitles: { // [!code focus]
258-
changelog: 'File History', // [!code focus]
259-
contributors: 'Contributors', // [!code focus]
260-
}, // [!code focus]
261-
}, // [!code focus]
262-
}, // [!code focus]
263-
}), // [!code focus]
264-
],
265-
// other vite configurations...
266-
})
267-
```
268-
269-
or if you would like to dynamically generate the translations:
270-
271-
```typescript twoslash
272-
import { join } from 'node:path'
273-
import { defineConfig } from 'vite'
274-
import { // [!code focus]
275-
GitChangelogMarkdownSection, // [!code focus]
276-
} from '@nolebase/vitepress-plugin-git-changelog/vite' // [!code focus]
277-
278-
export default defineConfig({
279-
plugins: [
280-
GitChangelogMarkdownSection({ // [!code focus]
281-
getChangelogTitle: (_, __, { helpers }): string => {
282-
if (helpers.idStartsWith(join('pages', 'en')))
283-
return 'File History'
284-
if (helpers.idStartsWith(join('pages', 'zh-CN')))
285-
return '文件历史'
286-
287-
return 'File History'
288-
},
289-
getContributorsTitle: (_, __, { helpers }): string => {
290-
if (helpers.idStartsWith(join('pages', 'en')))
291-
return 'Contributors'
292-
if (helpers.idStartsWith(join('pages', 'zh-CN')))
293-
return '贡献者'
294-
295-
return 'Contributors'
296-
},
297-
}), // [!code focus]
298-
],
299-
// other vite configurations...
300-
})
301-
```
302-
303208
#### Excluding a page from the transformation of `GitChangelogMarkdownSection`
304209

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

docs/pages/en/releases/migrations/v1-to-v2.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,24 @@ import '@nolebase/vitepress-plugin-highlight-targeted-heading/client/style.css'
210210
2. `nameAliases` now deprecated, please use `mapByNameAliases` instead, which is more clear and consistent with other plugins.
211211
3. `emailAliases` now deprecated, please use `mapByEmailAliases` instead, which is more clear and consistent with other plugins.
212212
4. Added new `username` field, which is the username of the author on GitHub used to fetch the avatar.
213+
5. The `locales` in the original Vite plugin `GitChangelogMarkdownSection` no longer need to be configured and have been migrated to the UI configuration under `locales`:
214+
1. `changelog.title`
215+
2. `contributors.title`;
216+
6. In order to better structure the organization of the i18n fields, the original
217+
1. `noLogs` i18n configuration changed to `changelog.noData`;
218+
2. `noContributors` i18n configuration was changed to `contributors.noData`.
219+
3. `lastEdited` i18n Configuration changed to `lastEdited`.
220+
4. `lastEditedDateFnsLocaleName` configuration changed to `changelog.lastEditedDateFnsLocaleName`
221+
5. `viewFullHistory` i18n Configuration changed to `changelog.viewFullHistory`
222+
6. `committedOn` i18n configuration changed to `changelog.committedOn`
213223
214224
### `Vite` config
215225
216-
1. `includeDirs` and `includeExtensions` have been deprecated and merged into `include`, which is a list of glob modes with `!` negation.
217-
2. If a renderable page file located outside of the VitePress root (where `.vitepress` lives), please configure the `cwd` (current working directory) to the parent directory of the page files. (For example, in a Monorepo, if the source file that rendered a page s located outside of `docs/`, you need to set `cwd` to the root directory of the Monorepo instead of the root of VitePress.)
218-
3. No longer needed to configure `rewritePaths`, therefor `rewritePaths` is now deprecated, can be safely removed.
219-
4. `rewritePaths` pattern should be configured in the against to filesystem paths, not the URL route paths.
226+
1. There is no longer a need to configure the `locales` field for `GitChangelogMarkdownSection`, and all of the internationalized i18n configuration has been migrated to the UI configuration.
227+
2. `includeDirs` and `includeExtensions` have been deprecated and merged into `include`, which is a list of glob modes with `!` negation.
228+
3. If a renderable page file located outside of the VitePress root (where `.vitepress` lives), please configure the `cwd` (current working directory) to the parent directory of the page files. (For example, in a Monorepo, if the source file that rendered a page s located outside of `docs/`, you need to set `cwd` to the root directory of the Monorepo instead of the root of VitePress.)
229+
4. No longer needed to configure `rewritePaths`, therefor `rewritePaths` is now deprecated, can be safely removed.
230+
5. `rewritePathsBy` pattern should be configured in the against to filesystem paths, not the URL route paths.
220231
221232
## Previewing image (social media card) generation
222233

0 commit comments

Comments
 (0)