@vuepress/plugin-redirect 2.0.0-rc.9 → 2.0.0-rc.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli/index.js +19 -73
- package/lib/cli/index.js.map +1 -0
- package/lib/{shared/localeConfig.d.ts → client/behavior-BgEQhx7R.d.ts} +15 -19
- package/lib/client/components/RedirectModal.d.ts +61 -0
- package/lib/client/components/RedirectModal.js +2 -0
- package/lib/client/components/RedirectModal.js.map +1 -0
- package/lib/client/config.d.ts +7 -3
- package/lib/client/config.js +2 -10
- package/lib/client/config.js.map +1 -0
- package/lib/client/index.d.ts +21 -0
- package/lib/client/index.js +2 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/setupRedirect-DVhycPIJ.js +2 -0
- package/lib/client/setupRedirect-DVhycPIJ.js.map +1 -0
- package/lib/client/styles/redirect-modal.css +1 -0
- package/lib/client/styles/redirect-modal.css.map +1 -0
- package/lib/client/styles/vars.css +1 -0
- package/lib/client/styles/vars.css.map +1 -0
- package/lib/client/useRedirectInfo-BzhIENgm.js +2 -0
- package/lib/client/useRedirectInfo-BzhIENgm.js.map +1 -0
- package/lib/node/index.d.ts +113 -3
- package/lib/node/index.js +90 -3
- package/lib/node/index.js.map +1 -0
- package/package.json +10 -15
- package/lib/cli/index.d.ts +0 -2
- package/lib/client/components/LanguageSwitch.d.ts +0 -4
- package/lib/client/components/LanguageSwitch.js +0 -99
- package/lib/client/composables/index.d.ts +0 -1
- package/lib/client/composables/index.js +0 -1
- package/lib/client/composables/setupDevServerRedirect.d.ts +0 -1
- package/lib/client/composables/setupDevServerRedirect.js +0 -80
- package/lib/client/define.d.ts +0 -3
- package/lib/client/define.js +0 -3
- package/lib/client/styles/language-switch.css +0 -57
- package/lib/node/ensureRootHomePage.d.ts +0 -3
- package/lib/node/ensureRootHomePage.js +0 -68
- package/lib/node/frontmatter.d.ts +0 -4
- package/lib/node/frontmatter.js +0 -1
- package/lib/node/generate/generateAutoLocaleRedirectFiles.d.ts +0 -3
- package/lib/node/generate/generateAutoLocaleRedirectFiles.js +0 -28
- package/lib/node/generate/generateRedirectFiles.d.ts +0 -2
- package/lib/node/generate/generateRedirectFiles.js +0 -21
- package/lib/node/generate/getLocaleRedirectHTML.d.ts +0 -2
- package/lib/node/generate/getLocaleRedirectHTML.js +0 -77
- package/lib/node/generate/getRedirectHTML.d.ts +0 -1
- package/lib/node/generate/getRedirectHTML.js +0 -18
- package/lib/node/generate/index.d.ts +0 -2
- package/lib/node/generate/index.js +0 -2
- package/lib/node/getRedirectLocaleConfig.d.ts +0 -4
- package/lib/node/getRedirectLocaleConfig.js +0 -35
- package/lib/node/getRedirectMap.d.ts +0 -3
- package/lib/node/getRedirectMap.js +0 -25
- package/lib/node/handleRedirectTo.d.ts +0 -2
- package/lib/node/handleRedirectTo.js +0 -19
- package/lib/node/locales.d.ts +0 -3
- package/lib/node/locales.js +0 -129
- package/lib/node/logger.d.ts +0 -3
- package/lib/node/logger.js +0 -3
- package/lib/node/options.d.ts +0 -22
- package/lib/node/options.js +0 -1
- package/lib/node/redirectPlugin.d.ts +0 -3
- package/lib/node/redirectPlugin.js +0 -53
- package/lib/shared/index.d.ts +0 -3
- package/lib/shared/index.js +0 -3
- package/lib/shared/localeConfig.js +0 -1
- package/lib/shared/locales.d.ts +0 -24
- package/lib/shared/locales.js +0 -1
- package/lib/shared/normalizePath.d.ts +0 -1
- package/lib/shared/normalizePath.js +0 -4
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { App } from 'vuepress/core';
|
|
2
|
-
import type { RedirectLocaleConfig } from '../shared/index.js';
|
|
3
|
-
import type { RedirectPluginOptions } from './options.js';
|
|
4
|
-
export declare const getRedirectLocaleConfig: (app: App, options: RedirectPluginOptions) => RedirectLocaleConfig;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { deepAssign, entries, fromEntries, isArray, isPlainObject, keys, } from '@vuepress/helper';
|
|
2
|
-
import { colors } from 'vuepress/utils';
|
|
3
|
-
import { logger } from './logger.js';
|
|
4
|
-
const AVAILABLE_FALLBACK = ['defaultLocale', 'homepage', '404'];
|
|
5
|
-
export const getRedirectLocaleConfig = (app, options) => {
|
|
6
|
-
const { locales } = app.options;
|
|
7
|
-
const localeConfig = deepAssign(fromEntries(entries(locales)
|
|
8
|
-
.filter(([key, { lang }]) => {
|
|
9
|
-
if (key === '/')
|
|
10
|
-
return false;
|
|
11
|
-
if (!lang) {
|
|
12
|
-
logger.error(`Missing ${colors.magenta('lang')} option for locale "${key}", this locale will be ignored!`);
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
})
|
|
17
|
-
.map(([key, { lang }]) => [key, [lang]])), isPlainObject(options.localeConfig)
|
|
18
|
-
? entries(options.localeConfig).map(([routePath, lang]) => [
|
|
19
|
-
routePath,
|
|
20
|
-
isArray(lang) ? lang : [lang],
|
|
21
|
-
])
|
|
22
|
-
: {});
|
|
23
|
-
const defaultLocale = options.defaultLocale || keys(localeConfig).pop();
|
|
24
|
-
return {
|
|
25
|
-
autoLocale: options.autoLocale ?? false,
|
|
26
|
-
switchLocale: options.switchLocale ?? false,
|
|
27
|
-
localeConfig,
|
|
28
|
-
defaultLocale,
|
|
29
|
-
localeFallback: options.localeFallback ?? true,
|
|
30
|
-
defaultBehavior: options.defaultBehavior &&
|
|
31
|
-
AVAILABLE_FALLBACK.includes(options.defaultBehavior)
|
|
32
|
-
? options.defaultBehavior
|
|
33
|
-
: 'defaultLocale',
|
|
34
|
-
};
|
|
35
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { entries, fromEntries, isArray, isFunction, isPlainObject, } from '@vuepress/helper';
|
|
2
|
-
import { normalizePath } from '../shared/normalizePath.js';
|
|
3
|
-
export const getRedirectMap = (app, options) => {
|
|
4
|
-
const config = isFunction(options.config)
|
|
5
|
-
? options.config(app)
|
|
6
|
-
: isPlainObject(options.config)
|
|
7
|
-
? options.config
|
|
8
|
-
: {};
|
|
9
|
-
return {
|
|
10
|
-
...fromEntries(app.pages
|
|
11
|
-
.map(({ frontmatter, path }) => isArray(frontmatter.redirectFrom)
|
|
12
|
-
? frontmatter.redirectFrom.map((from) => [
|
|
13
|
-
normalizePath(from, true),
|
|
14
|
-
path,
|
|
15
|
-
])
|
|
16
|
-
: frontmatter.redirectFrom
|
|
17
|
-
? [[normalizePath(frontmatter.redirectFrom, true), path]]
|
|
18
|
-
: [])
|
|
19
|
-
.flat()),
|
|
20
|
-
...fromEntries(entries(config).map(([from, to]) => [
|
|
21
|
-
normalizePath(from, true),
|
|
22
|
-
normalizePath(to),
|
|
23
|
-
])),
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { isLinkAbsolute, removeLeadingSlash } from '@vuepress/helper';
|
|
2
|
-
import { normalizePath } from '../shared/normalizePath.js';
|
|
3
|
-
export const handleRedirectTo = ({ frontmatter }, app) => {
|
|
4
|
-
const { base } = app.options;
|
|
5
|
-
const { redirectTo } = frontmatter;
|
|
6
|
-
if (redirectTo) {
|
|
7
|
-
const redirectUrl = normalizePath(isLinkAbsolute(redirectTo)
|
|
8
|
-
? `${base}${removeLeadingSlash(redirectTo)}`
|
|
9
|
-
: redirectTo);
|
|
10
|
-
(frontmatter.head ??= []).unshift([
|
|
11
|
-
'script',
|
|
12
|
-
{},
|
|
13
|
-
`{\
|
|
14
|
-
const anchor = window.location.hash.substring(1);\
|
|
15
|
-
location.href=\`${redirectUrl}\${anchor? \`#\${anchor}\`: ""}\`;\
|
|
16
|
-
}`,
|
|
17
|
-
]);
|
|
18
|
-
}
|
|
19
|
-
};
|
package/lib/node/locales.d.ts
DELETED
package/lib/node/locales.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/** Multi language config for redirect popup */
|
|
2
|
-
export const redirectLocales = {
|
|
3
|
-
'/en/': {
|
|
4
|
-
name: 'English',
|
|
5
|
-
hint: 'Your primary language is $1, do you want to switch to it?',
|
|
6
|
-
switch: 'Switch to $1',
|
|
7
|
-
cancel: 'Cancel',
|
|
8
|
-
},
|
|
9
|
-
'/zh/': {
|
|
10
|
-
name: '简体中文',
|
|
11
|
-
hint: '您的首选语言是 $1,是否切换到该语言?',
|
|
12
|
-
switch: '切换到 $1',
|
|
13
|
-
cancel: '取消',
|
|
14
|
-
},
|
|
15
|
-
'/zh-tw/': {
|
|
16
|
-
name: '繁體中文',
|
|
17
|
-
hint: '您的首選語言是 $1,是否切換到該語言?',
|
|
18
|
-
switch: '切換到 $1',
|
|
19
|
-
cancel: '取消',
|
|
20
|
-
},
|
|
21
|
-
'/de/': {
|
|
22
|
-
name: 'Deutsch',
|
|
23
|
-
hint: 'Ihre bevorzugte Sprache ist $1, möchten Sie zu dieser wechseln?',
|
|
24
|
-
switch: 'Zu $1 wechseln',
|
|
25
|
-
cancel: 'Abbrechen',
|
|
26
|
-
},
|
|
27
|
-
'/de-at/': {
|
|
28
|
-
name: 'Deutsch (Österreich)',
|
|
29
|
-
hint: 'Ihre bevorzugte Sprache ist $1, möchten Sie zu dieser wechseln?',
|
|
30
|
-
switch: 'Zu $1 wechseln',
|
|
31
|
-
cancel: 'Abbrechen',
|
|
32
|
-
},
|
|
33
|
-
'/vi/': {
|
|
34
|
-
name: 'Tiếng Việt',
|
|
35
|
-
hint: 'Ngôn ngữ chính của bạn là $1, bạn có muốn chuyển sang nó?',
|
|
36
|
-
switch: 'Chuyển sang $1',
|
|
37
|
-
cancel: 'Hủy',
|
|
38
|
-
},
|
|
39
|
-
'/uk/': {
|
|
40
|
-
name: 'Українська',
|
|
41
|
-
hint: 'Вашою основною мовою є $1, чи бажаєте ви переключитися на неї?',
|
|
42
|
-
switch: 'Переключитися на $1',
|
|
43
|
-
cancel: 'Скасувати',
|
|
44
|
-
},
|
|
45
|
-
'/ru/': {
|
|
46
|
-
name: 'Русский',
|
|
47
|
-
hint: 'Ваш основной язык - $1, вы хотите переключиться на него?',
|
|
48
|
-
switch: 'Переключиться на $1',
|
|
49
|
-
cancel: 'Отмена',
|
|
50
|
-
},
|
|
51
|
-
'/br/': {
|
|
52
|
-
name: 'Português (Brasil)',
|
|
53
|
-
hint: 'A língua principal é $1, deseja mudar para ela?',
|
|
54
|
-
switch: 'Mudar para $1',
|
|
55
|
-
cancel: 'Cancelar',
|
|
56
|
-
},
|
|
57
|
-
'/pl/': {
|
|
58
|
-
name: 'Polski',
|
|
59
|
-
hint: 'Twoim głównym językiem jest $1, czy chcesz przełączyć się na niego?',
|
|
60
|
-
switch: 'Przełącz na $1',
|
|
61
|
-
cancel: 'Anuluj',
|
|
62
|
-
},
|
|
63
|
-
'/sk/': {
|
|
64
|
-
name: 'Slovenčina',
|
|
65
|
-
hint: 'Vašou hlavnou jazykom je $1, chcete prepnúť naň?',
|
|
66
|
-
switch: 'Prepnúť na $1',
|
|
67
|
-
cancel: 'Zrušiť',
|
|
68
|
-
},
|
|
69
|
-
'/fr/': {
|
|
70
|
-
name: 'Français',
|
|
71
|
-
hint: 'Votre langue principale est $1, voulez-vous la changer ?',
|
|
72
|
-
switch: 'Changer pour $1',
|
|
73
|
-
cancel: 'Annuler',
|
|
74
|
-
},
|
|
75
|
-
'/tr/': {
|
|
76
|
-
name: 'Türkçe',
|
|
77
|
-
hint: 'Ana diliniz $1, ona geçmek ister misiniz?',
|
|
78
|
-
switch: "$1'e geç",
|
|
79
|
-
cancel: 'İptal',
|
|
80
|
-
},
|
|
81
|
-
'/fi/': {
|
|
82
|
-
name: 'Suomi',
|
|
83
|
-
hint: 'Pääkielenäsi on $1, haluatko vaihtaa siihen?',
|
|
84
|
-
switch: 'Vaihda $1:een',
|
|
85
|
-
cancel: 'Peruuta',
|
|
86
|
-
},
|
|
87
|
-
'/hu/': {
|
|
88
|
-
name: 'Magyar',
|
|
89
|
-
hint: 'A fő nyelvét $1, szeretné váltani?',
|
|
90
|
-
switch: 'Váltás $1',
|
|
91
|
-
cancel: 'Mégse',
|
|
92
|
-
},
|
|
93
|
-
'/id/': {
|
|
94
|
-
name: 'Bahasa Indonesia',
|
|
95
|
-
hint: 'Bahasa utama Anda adalah $1, apakah Anda ingin beralih ke sana?',
|
|
96
|
-
switch: 'Beralih ke $1',
|
|
97
|
-
cancel: 'Batal',
|
|
98
|
-
},
|
|
99
|
-
'/nl/': {
|
|
100
|
-
name: 'Nederlands',
|
|
101
|
-
hint: 'Uw primaire taal is $1, wilt u overschakelen?',
|
|
102
|
-
switch: 'Overschakelen naar $1',
|
|
103
|
-
cancel: 'Annuleren',
|
|
104
|
-
},
|
|
105
|
-
'/ja/': {
|
|
106
|
-
name: '日本語',
|
|
107
|
-
hint: 'あなたの主要な言語は $1 です。それに切り替えますか?',
|
|
108
|
-
switch: '$1 に切り替える',
|
|
109
|
-
cancel: 'キャンセル',
|
|
110
|
-
},
|
|
111
|
-
'/ko/': {
|
|
112
|
-
name: '한국어',
|
|
113
|
-
hint: '당신의 기본 언어는 $1입니다. 그것으로 전환 하시겠습니까?',
|
|
114
|
-
switch: '$1로 전환',
|
|
115
|
-
cancel: '취소',
|
|
116
|
-
},
|
|
117
|
-
'/es/': {
|
|
118
|
-
name: 'Español',
|
|
119
|
-
hint: 'Su idioma principal es $1, ¿desea cambiarlo?',
|
|
120
|
-
switch: 'Cambiar a $1',
|
|
121
|
-
cancel: 'Cancelar',
|
|
122
|
-
},
|
|
123
|
-
'/pt/': {
|
|
124
|
-
name: 'Português',
|
|
125
|
-
hint: 'Sua língua principal é $1, deseja mudar para ela?',
|
|
126
|
-
switch: 'Mudar para $1',
|
|
127
|
-
cancel: 'Cancelar',
|
|
128
|
-
},
|
|
129
|
-
};
|
package/lib/node/logger.d.ts
DELETED
package/lib/node/logger.js
DELETED
package/lib/node/options.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { App, LocaleConfig } from 'vuepress/core';
|
|
2
|
-
import type { RedirectLocaleConfig, RedirectPluginLocaleData } from '../shared/index.js';
|
|
3
|
-
export interface RedirectPluginOptions extends Partial<Omit<RedirectLocaleConfig, 'localeConfig'>> {
|
|
4
|
-
/**
|
|
5
|
-
* Redirect mapping
|
|
6
|
-
*
|
|
7
|
-
* 重定向映射
|
|
8
|
-
*/
|
|
9
|
-
config?: Record<string, string> | ((app: App) => Record<string, string>);
|
|
10
|
-
/**
|
|
11
|
-
* Locale language config
|
|
12
|
-
*
|
|
13
|
-
* 多语言语言配置
|
|
14
|
-
*/
|
|
15
|
-
localeConfig?: Record<string, string | string[]>;
|
|
16
|
-
/**
|
|
17
|
-
* Locales config
|
|
18
|
-
*
|
|
19
|
-
* 多语言选项
|
|
20
|
-
*/
|
|
21
|
-
locales?: LocaleConfig<RedirectPluginLocaleData>;
|
|
22
|
-
}
|
package/lib/node/options.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { addViteSsrNoExternal, getLocaleConfig } from '@vuepress/helper';
|
|
2
|
-
import { getDirname, path } from 'vuepress/utils';
|
|
3
|
-
import { ensureRootHomePage } from './ensureRootHomePage.js';
|
|
4
|
-
import { generateAutoLocaleRedirectFiles, generateRedirectFiles, } from './generate/index.js';
|
|
5
|
-
import { getRedirectLocaleConfig } from './getRedirectLocaleConfig.js';
|
|
6
|
-
import { getRedirectMap } from './getRedirectMap.js';
|
|
7
|
-
import { handleRedirectTo } from './handleRedirectTo.js';
|
|
8
|
-
import { redirectLocales } from './locales.js';
|
|
9
|
-
import { logger, PLUGIN_NAME } from './logger.js';
|
|
10
|
-
const __dirname = getDirname(import.meta.url);
|
|
11
|
-
export const redirectPlugin = (options = {}) => (app) => {
|
|
12
|
-
if (app.env.isDebug)
|
|
13
|
-
logger.info('Options:', options);
|
|
14
|
-
const redirectLocaleConfig = getRedirectLocaleConfig(app, options);
|
|
15
|
-
let redirectMap;
|
|
16
|
-
return {
|
|
17
|
-
name: PLUGIN_NAME,
|
|
18
|
-
define: {
|
|
19
|
-
__REDIRECT_LOCALE_CONFIG__: redirectLocaleConfig,
|
|
20
|
-
__REDIRECT_LOCALE_SWITCH__: Boolean(redirectLocaleConfig.switchLocale),
|
|
21
|
-
__REDIRECT_LOCALES__: getLocaleConfig({
|
|
22
|
-
app,
|
|
23
|
-
name: 'redirect',
|
|
24
|
-
config: options.locales,
|
|
25
|
-
default: redirectLocales,
|
|
26
|
-
}),
|
|
27
|
-
},
|
|
28
|
-
extendsBundlerOptions: (bundlerOptions, app) => {
|
|
29
|
-
addViteSsrNoExternal(bundlerOptions, app, '@vuepress/helper');
|
|
30
|
-
},
|
|
31
|
-
extendsPage: (page, app) => {
|
|
32
|
-
handleRedirectTo(page, app);
|
|
33
|
-
},
|
|
34
|
-
onInitialized: async (app) => {
|
|
35
|
-
redirectMap = getRedirectMap(app, options);
|
|
36
|
-
if (app.env.isDebug)
|
|
37
|
-
logger.info('Redirect Map:', redirectMap);
|
|
38
|
-
if (redirectLocaleConfig.autoLocale)
|
|
39
|
-
await ensureRootHomePage(app, redirectLocaleConfig);
|
|
40
|
-
},
|
|
41
|
-
onPrepared: async (app) => {
|
|
42
|
-
await app.writeTemp('redirect/map.js', `\
|
|
43
|
-
export const redirectMap = ${app.env.isDev ? JSON.stringify(redirectMap, null, 2) : '{}'};
|
|
44
|
-
`);
|
|
45
|
-
},
|
|
46
|
-
onGenerated: async (app) => {
|
|
47
|
-
await generateRedirectFiles(app, redirectMap);
|
|
48
|
-
if (redirectLocaleConfig.autoLocale)
|
|
49
|
-
await generateAutoLocaleRedirectFiles(app, redirectLocaleConfig);
|
|
50
|
-
},
|
|
51
|
-
clientConfigFile: path.join(__dirname, '../client/config.js'),
|
|
52
|
-
};
|
|
53
|
-
};
|
package/lib/shared/index.d.ts
DELETED
package/lib/shared/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/shared/locales.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ExactLocaleConfig } from '@vuepress/helper/shared';
|
|
2
|
-
export interface RedirectPluginLocaleData {
|
|
3
|
-
/**
|
|
4
|
-
* Language name
|
|
5
|
-
*/
|
|
6
|
-
name: string;
|
|
7
|
-
/**
|
|
8
|
-
* Switch hint
|
|
9
|
-
*
|
|
10
|
-
* 切换提示
|
|
11
|
-
*/
|
|
12
|
-
hint: string;
|
|
13
|
-
/**
|
|
14
|
-
* Switch button text
|
|
15
|
-
*/
|
|
16
|
-
switch: string;
|
|
17
|
-
/**
|
|
18
|
-
* Cancel button text
|
|
19
|
-
*
|
|
20
|
-
* 取消按钮文字
|
|
21
|
-
*/
|
|
22
|
-
cancel: string;
|
|
23
|
-
}
|
|
24
|
-
export type RedirectPluginLocaleConfig = ExactLocaleConfig<RedirectPluginLocaleData>;
|
package/lib/shared/locales.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const normalizePath: (path: string, removeHash?: boolean) => string;
|