Skip to content

Commit 1ce5d92

Browse files
committed
docs: update doc
1 parent d9dbf7e commit 1ce5d92

File tree

11 files changed

+563
-209
lines changed

11 files changed

+563
-209
lines changed

README.md

+56-21
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pnpm add @plugin-web-update-notification/webpack -D
6060

6161
### Vite
6262

63+
**basic usage**
64+
6365
```ts
6466
// vite.config.ts
6567
import { defineConfig } from 'vite'
@@ -77,13 +79,14 @@ export default defineConfig({
7779
})
7880
```
7981

82+
**custom notification text**
83+
8084
```ts
8185
// vite.config.ts
8286
export default defineConfig({
8387
plugins: [
8488
vue(),
8589
webUpdateNotice({
86-
// custom notification text
8790
notificationProps: {
8891
title: 'system update',
8992
description: 'System update, please refresh the page',
@@ -94,25 +97,40 @@ export default defineConfig({
9497
})
9598
```
9699

100+
**internationalization**
101+
97102
```ts
98103
// vite.config.ts
99104
export default defineConfig({
100105
plugins: [
101106
vue(),
102107
webUpdateNotice({
103-
// custom notification UI
104-
customNotificationHTML: `
105-
<div style="background-color: #fff;padding: 24px;border-radius: 4px;position: fixed;top: 24px;right: 24px;border: 1px solid;">
106-
System update, please refresh the page
107-
</div>
108-
`,
108+
// plugin preset: zh_CN | zh_TW | en_US
109+
locale: "en_US",
110+
localeData: {
111+
en_US: {
112+
title: "📢 system update",
113+
description: "System update, please refresh the page",
114+
buttonText: "refresh",
115+
dismissButtonText: "dismiss",
116+
},
117+
zh_CN: {
118+
...
119+
},
120+
...
121+
},
109122
}),
110-
]
111-
})
123+
],
124+
});
125+
126+
127+
// other file to set locale
128+
window.pluginWebUpdateNotice_.setLocale('zh_CN')
112129
```
113130

131+
**hidden default notification, listener to update event and custom behavior.**
132+
114133
```ts
115-
// hidden default notification, listener to update event and custom behavior.
116134
// vite.config.ts
117135
export default defineConfig({
118136
plugins: [
@@ -146,6 +164,7 @@ export default {
146164
title: 'system update',
147165
description: 'System update, please refresh the page',
148166
buttonText: 'refresh',
167+
dismissButtonText: "dismiss",
149168
},
150169
} as WebUpdateNotificationOptions
151170
}
@@ -170,45 +189,61 @@ module.exports = defineConfig({
170189
})
171190
```
172191

173-
174-
175192
## Options
176193

177194
```ts
178195
function webUpdateNotice(options?: Options): Plugin
179196

180-
interface Options {
181-
/** default is 'git_commit_hash' */
182-
versionType?: 'git_commit_hash' | 'pkg_version' | 'build_timestamp'
183-
/** polling interval(ms), default 10*60*1000 */
197+
export interface Options {
198+
/**
199+
* support 'git_commit_hash' | 'pkg_version' | 'build_timestamp'
200+
*
201+
* default is 'git_commit_hash'
202+
* */
203+
versionType?: VersionType
204+
/** polling interval(ms), default 10 * 60 * 1000 */
184205
checkInterval?: number
185-
/** whether to output commit-hash in console */
206+
/** whether to output version in console */
186207
logVersion?: boolean
187208
customNotificationHTML?: string
209+
/** notificationProps have higher priority than locale */
188210
notificationProps?: NotificationProps
211+
/** locale default is zh_CN
212+
*
213+
* preset: zh_CN | zh_TW | en_US
214+
* */
215+
locale?: string
216+
localeData?: LocaleData
189217
hiddenDefaultNotification?: boolean
190218
hiddenDismissButton?: boolean
191-
/** index.html file path, by default, we will look up path.resolve(webpackOutputPath, './index.html') */
192-
indexHtmlFilePath?: string // !!! only webpack plugin support
193-
194219
/**
195220
* Base public path for inject file, Valid values include:
196221
* * Absolute URL pathname, e.g. /foo/
197222
* * Full URL, e.g. https://foo.com/
198223
* * Empty string(default) or ./
224+
* !!! Don't forget last /
199225
*/
200226
injectFileBase?: string
201227
}
202228

203-
interface NotificationProps {
229+
export type VersionType = 'git_commit_hash' | 'pkg_version' | 'build_timestamp'
230+
231+
export interface NotificationProps {
204232
title?: string
205233
description?: string
234+
/** refresh button text */
206235
buttonText?: string
207236
/** dismiss button text */
208237
dismissButtonText?: string
209238
}
239+
240+
export type LocaleData = Record<string, NotificationProps>
210241
```
211242
243+
## What was changed
244+
245+
![inject_content](https://raw.githubusercontent.com/GreatAuk/plugin-web-update-notification/master/images/inject_content)
246+
212247
## License
213248
214249
[MIT](./LICENSE)

README.zh-CN.md

+59-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
[English](./README.md) | 简体中文
24

35
# plugin-web-update-notification
@@ -58,6 +60,8 @@ pnpm add @plugin-web-update-notification/webpack -D
5860

5961
### Vite
6062

63+
**基础使用**
64+
6165
```ts
6266
// vite.config.ts
6367
import { defineConfig } from 'vite'
@@ -75,38 +79,54 @@ export default defineConfig({
7579
})
7680
```
7781

82+
**自定义通知栏文本**
83+
7884
```ts
7985
// vite.config.ts
8086
export default defineConfig({
8187
plugins: [
8288
vue(),
8389
webUpdateNotice({
84-
// 自定义通知栏文本
8590
notificationProps: {
86-
title: 'system update',
91+
title: '标题',
8792
description: 'System update, please refresh the page',
88-
buttonText: 'refresh',
93+
buttonText: '刷新',
94+
dismissButtonText: '忽略'
8995
},
9096
}),
9197
]
9298
})
9399
```
94100

101+
**国际化**
102+
95103
```ts
96104
// vite.config.ts
97105
export default defineConfig({
98106
plugins: [
99107
vue(),
100108
webUpdateNotice({
101-
// 自定义 notification UI
102-
customNotificationHTML: `
103-
<div style="background-color: #fff;padding: 24px;border-radius: 4px;position: fixed;top: 24px;right: 24px;border: 1px solid;">
104-
System update, please refresh the page
105-
</div>
106-
`,
109+
// plugin preset: zh_CN | zh_TW | en_US
110+
locale: "en_US",
111+
localeData: {
112+
en_US: {
113+
title: "📢 system update",
114+
description: "System update, please refresh the page",
115+
buttonText: "refresh",
116+
dismissButtonText: "dismiss",
117+
},
118+
zh_CN: {
119+
...
120+
},
121+
...
122+
},
107123
}),
108-
]
109-
})
124+
],
125+
});
126+
127+
128+
// other file to set locale
129+
window.pluginWebUpdateNotice_.setLocale('zh_CN')
110130
```
111131

112132
```ts
@@ -144,6 +164,7 @@ export default {
144164
title: 'system update',
145165
description: 'System update, please refresh the page',
146166
buttonText: 'refresh',
167+
dismissButtonText: "dismiss",
147168
},
148169
} as WebUpdateNotificationOptions
149170
}
@@ -173,38 +194,56 @@ module.exports = defineConfig({
173194
```ts
174195
function webUpdateNotice(options?: Options): Plugin
175196

176-
interface Options {
177-
/** default is 'git_commit_hash' */
178-
versionType?: 'git_commit_hash' | 'pkg_version' | 'build_timestamp'
179-
/** polling interval(ms), default 10*60*1000 */
197+
export interface Options {
198+
/**
199+
* support 'git_commit_hash' | 'pkg_version' | 'build_timestamp'
200+
*
201+
* default is 'git_commit_hash'
202+
* */
203+
versionType?: VersionType
204+
/** polling interval(ms), default 10 * 60 * 1000 */
180205
checkInterval?: number
181-
/** whether to output commit-hash in console */
206+
/** whether to output version in console */
182207
logVersion?: boolean
183208
customNotificationHTML?: string
209+
/** notificationProps have higher priority than locale */
184210
notificationProps?: NotificationProps
211+
/** locale default is zh_CN
212+
*
213+
* preset: zh_CN | zh_TW | en_US
214+
* */
215+
locale?: string
216+
localeData?: LocaleData
185217
hiddenDefaultNotification?: boolean
186218
hiddenDismissButton?: boolean
187-
/** index.html file path, by default, we will look up path.resolve(webpackOutputPath, './index.html') */
188-
indexHtmlFilePath?: string // !!! only webpack plugin support
189-
190219
/**
191220
* Base public path for inject file, Valid values include:
192221
* * Absolute URL pathname, e.g. /foo/
193222
* * Full URL, e.g. https://foo.com/
194223
* * Empty string(default) or ./
224+
* !!! Don't forget last /
195225
*/
196226
injectFileBase?: string
197227
}
198228

199-
interface NotificationProps {
229+
export type VersionType = 'git_commit_hash' | 'pkg_version' | 'build_timestamp'
230+
231+
export interface NotificationProps {
200232
title?: string
201233
description?: string
234+
/** refresh button text */
202235
buttonText?: string
203236
/** dismiss button text */
204237
dismissButtonText?: string
205238
}
239+
240+
export type LocaleData = Record<string, NotificationProps>
206241
```
207242
243+
## 变动了哪些内容
244+
245+
![inject_content](https://raw.githubusercontent.com/GreatAuk/plugin-web-update-notification/master/images/inject_content)
246+
208247
## License
209248
210249
[MIT](./LICENSE)

images/inject_content.webp

84.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)