@vuepress/plugin-redirect 2.0.0-rc.51 → 2.0.0-rc.54

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.
Files changed (64) hide show
  1. package/lib/cli/index.js +19 -77
  2. package/lib/cli/index.js.map +1 -0
  3. package/lib/{shared/localeConfig.d.ts → client/behavior-BgEQhx7R.d.ts} +15 -19
  4. package/lib/client/components/RedirectModal.d.ts +60 -4
  5. package/lib/client/components/RedirectModal.js +2 -122
  6. package/lib/client/components/RedirectModal.js.map +1 -0
  7. package/lib/client/config.d.ts +7 -3
  8. package/lib/client/config.js +2 -11
  9. package/lib/client/config.js.map +1 -0
  10. package/lib/client/index.d.ts +20 -0
  11. package/lib/client/index.js +2 -0
  12. package/lib/client/index.js.map +1 -0
  13. package/lib/client/setupRedirect-q886RMSd.js +2 -0
  14. package/lib/client/setupRedirect-q886RMSd.js.map +1 -0
  15. package/lib/client/useRedirectInfo-Bi8syic3.js +2 -0
  16. package/lib/client/useRedirectInfo-Bi8syic3.js.map +1 -0
  17. package/lib/node/index.d.ts +112 -2
  18. package/lib/node/index.js +90 -1
  19. package/lib/node/index.js.map +1 -0
  20. package/package.json +6 -5
  21. package/lib/cli/index.d.ts +0 -2
  22. package/lib/client/composables/index.d.ts +0 -1
  23. package/lib/client/composables/index.js +0 -1
  24. package/lib/client/composables/setupDevServerRedirect.d.ts +0 -1
  25. package/lib/client/composables/setupDevServerRedirect.js +0 -78
  26. package/lib/client/define.d.ts +0 -3
  27. package/lib/client/define.js +0 -3
  28. package/lib/node/ensureRootHomePage.d.ts +0 -2
  29. package/lib/node/ensureRootHomePage.js +0 -15
  30. package/lib/node/generate/generateAutoLocaleRedirectFiles.d.ts +0 -3
  31. package/lib/node/generate/generateAutoLocaleRedirectFiles.js +0 -28
  32. package/lib/node/generate/generateRedirectFiles.d.ts +0 -2
  33. package/lib/node/generate/generateRedirectFiles.js +0 -21
  34. package/lib/node/generate/getLocaleRedirectHTML.d.ts +0 -2
  35. package/lib/node/generate/getLocaleRedirectHTML.js +0 -77
  36. package/lib/node/generate/getRedirectHTML.d.ts +0 -1
  37. package/lib/node/generate/getRedirectHTML.js +0 -18
  38. package/lib/node/generate/index.d.ts +0 -2
  39. package/lib/node/generate/index.js +0 -2
  40. package/lib/node/getRedirectLocaleConfig.d.ts +0 -4
  41. package/lib/node/getRedirectLocaleConfig.js +0 -33
  42. package/lib/node/getRedirectMap.d.ts +0 -3
  43. package/lib/node/getRedirectMap.js +0 -25
  44. package/lib/node/handleRedirectTo.d.ts +0 -2
  45. package/lib/node/handleRedirectTo.js +0 -19
  46. package/lib/node/locales.d.ts +0 -3
  47. package/lib/node/locales.js +0 -150
  48. package/lib/node/logger.d.ts +0 -3
  49. package/lib/node/logger.js +0 -3
  50. package/lib/node/redirectPlugin.d.ts +0 -3
  51. package/lib/node/redirectPlugin.js +0 -53
  52. package/lib/node/types/frontmatter.d.ts +0 -4
  53. package/lib/node/types/frontmatter.js +0 -1
  54. package/lib/node/types/index.d.ts +0 -2
  55. package/lib/node/types/index.js +0 -1
  56. package/lib/node/types/options.d.ts +0 -22
  57. package/lib/node/types/options.js +0 -1
  58. package/lib/shared/index.d.ts +0 -3
  59. package/lib/shared/index.js +0 -3
  60. package/lib/shared/localeConfig.js +0 -1
  61. package/lib/shared/locales.d.ts +0 -34
  62. package/lib/shared/locales.js +0 -1
  63. package/lib/shared/normalizePath.d.ts +0 -1
  64. package/lib/shared/normalizePath.js +0 -4
package/lib/cli/index.js CHANGED
@@ -1,78 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from 'node:module';
3
- import { removeEndingSlash, removeLeadingSlash } from '@vuepress/helper';
4
- import { cac } from 'cac';
5
- import { loadUserConfig, resolveAppConfig, resolveCliAppConfig, resolveUserConfigConventionalPath, transformUserConfigToPlugin, } from 'vuepress/cli';
6
- import { createBuildApp } from 'vuepress/core';
7
- import { fs, logger, path } from 'vuepress/utils';
8
- import { getRedirectHTML } from '../node/generate/getRedirectHTML.js';
9
- const require = createRequire(import.meta.url);
10
- const cli = cac('vp-redirect');
11
- const { version } = require('@vuepress/plugin-redirect/package.json');
12
- cli
13
- .command('generate [source-dir]', 'Generate redirect site using VuePress project under source folder')
14
- .option('--hostname <hostname>', 'Hostname to redirect to (E.g.: https://new.example.com/)', { default: '/' })
15
- .option('-c, --config <config>', 'Set path to config file')
16
- .option('-o, --output <output>', 'Set the output directory (default: .vuepress/redirect)')
17
- .option('--cache <cache>', 'Set the directory of the cache files')
18
- .option('-t, --temp <temp>', 'Set the directory of the temporary files')
19
- .option('--clean-cache', 'Clean the cache files before generation')
20
- .option('--clean-temp', 'Clean the temporary files before generation')
21
- .action(async (sourceDir, commandOptions) => {
22
- if (!sourceDir) {
23
- cli.outputHelp();
24
- return;
25
- }
26
- // ensure NODE_ENV is set
27
- process.env.NODE_ENV ??= 'production';
28
- // resolve app config from cli options
29
- const cliAppConfig = resolveCliAppConfig(sourceDir, {});
30
- // resolve user config file
31
- const userConfigPath = resolveUserConfigConventionalPath(cliAppConfig.source);
32
- const { userConfig } = await loadUserConfig(userConfigPath);
33
- // resolve the final app config to use
34
- const appConfig = resolveAppConfig({
35
- defaultAppConfig: {},
36
- cliAppConfig,
37
- userConfig,
38
- });
39
- if (appConfig === null)
40
- return;
41
- // create vuepress app
42
- const app = createBuildApp(appConfig);
43
- // use user-config plugin
44
- app.use(transformUserConfigToPlugin(userConfig, cliAppConfig.source));
45
- // clean temp and cache
46
- if (commandOptions.cleanTemp === true) {
47
- logger.info('Cleaning temp...');
48
- await fs.remove(app.dir.temp());
49
- }
50
- if (commandOptions.cleanCache === true) {
51
- logger.info('Cleaning cache...');
52
- await fs.remove(app.dir.cache());
53
- }
54
- const outputFolder = commandOptions.output
55
- ? path.join(process.cwd(), commandOptions.output)
56
- : path.join(app.dir.source(), '.vuepress', 'redirect');
57
- // empty output directory
58
- await fs.emptyDir(outputFolder);
59
- // initialize vuepress app to get pages
60
- logger.info('Initializing VuePress and preparing data...');
61
- await app.init();
62
- // redirect all pages
63
- // initialize vuepress app to get pages
64
- logger.info('Generating redirect pages...');
65
- await Promise.all(app.pages.map((page) => {
66
- const redirectUrl = `${removeEndingSlash(commandOptions.hostname)}${app.options.base}${removeLeadingSlash(page.path)}`;
67
- const destLocation = path.join(outputFolder, removeLeadingSlash(page.path.replace(/\/$/, '/index.html')));
68
- return fs
69
- .ensureDir(path.dirname(destLocation))
70
- .then(() => fs.writeFile(destLocation, getRedirectHTML(redirectUrl)));
71
- }));
72
- });
73
- cli.command('').action(() => {
74
- cli.outputHelp();
75
- });
76
- cli.help();
77
- cli.version(version);
78
- cli.parse();
2
+ import{createRequire as g}from"node:module";import{removeEndingSlash as v,removeLeadingSlash as h}from"@vuepress/helper";import{cac as C}from"cac";import{resolveCliAppConfig as w,resolveUserConfigPath as y,resolveUserConfigConventionalPath as $,loadUserConfig as b,resolveAppConfig as P,transformUserConfigToPlugin as S}from"vuepress/cli";import{createBuildApp as j}from"vuepress/core";import{logger as i,fs as n,path as a}from"vuepress/utils";const A=r=>`<!doctype html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="robots" content="noindex">
7
+ <meta http-equiv="refresh" content="0; url=${r}">
8
+ <link rel="canonical" href="${r}">
9
+ <title>Redirecting...</title>
10
+ <script>
11
+ const anchor = window.location.hash.substring(1);
12
+ location.href = \`${r}\${anchor? \`#\${anchor}\`: ""}\`;
13
+ <\/script>
14
+ </head>
15
+ <body>
16
+ <p>Redirecting...</p>
17
+ </body>
18
+ </html>
19
+ `,E=g(import.meta.url),o=C("vp-redirect"),{version:H}=E("@vuepress/plugin-redirect/package.json");o.command("generate [source-dir]","Generate redirect site using VuePress project under source folder").option("--hostname <hostname>","Hostname to redirect to (E.g.: https://new.example.com/)",{default:"/"}).option("-c, --config <config>","Set path to config file").option("-o, --output <output>","Set the output directory (default: .vuepress/redirect)").option("--cache <cache>","Set the directory of the cache files").option("-t, --temp <temp>","Set the directory of the temporary files").option("--clean-cache","Clean the cache files before generation").option("--clean-temp","Clean the temporary files before generation").action(async(r,e)=>{if(!r){o.outputHelp();return}process.env.NODE_ENV??="production";const c=w(r,{}),u=e.config?y(e.config):$(c.source),{userConfig:p}=await b(u),s=P({defaultAppConfig:{},cliAppConfig:c,userConfig:p});if(s===null)return;const t=j(s);t.use(S(p,c.source)),e.cleanTemp===!0&&(i.info("Cleaning temp..."),await n.remove(t.dir.temp())),e.cleanCache===!0&&(i.info("Cleaning cache..."),await n.remove(t.dir.cache()));const l=e.output?a.join(process.cwd(),e.output):a.join(t.dir.source(),".vuepress","redirect");await n.emptyDir(l),i.info("Initializing VuePress and preparing data..."),await t.init(),i.info("Generating redirect pages..."),await Promise.all(t.pages.map(m=>{const d=`${v(e.hostname)}${t.options.base}${h(m.path)}`,f=a.join(l,h(m.path.replace(/\/$/,"/index.html")));return n.ensureDir(a.dirname(f)).then(()=>n.writeFile(f,A(d)))}))}),o.command("").action(()=>{o.outputHelp()}),o.help(),o.version(H),o.parse();
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/node/generate/getRedirectHTML.ts","../../src/cli/index.ts"],"sourcesContent":["export const getRedirectHTML = (redirectUrl: string): string => `<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"robots\" content=\"noindex\">\n <meta http-equiv=\"refresh\" content=\"0; url=${redirectUrl}\">\n <link rel=\"canonical\" href=\"${redirectUrl}\">\n <title>Redirecting...</title>\n <script>\n const anchor = window.location.hash.substring(1);\n location.href = \\`${redirectUrl}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`;\n </script>\n</head>\n<body>\n <p>Redirecting...</p>\n</body>\n</html>\n`\n","#!/usr/bin/env node\nimport { createRequire } from 'node:module'\nimport { removeEndingSlash, removeLeadingSlash } from '@vuepress/helper'\nimport { cac } from 'cac'\nimport {\n loadUserConfig,\n resolveAppConfig,\n resolveCliAppConfig,\n resolveUserConfigConventionalPath,\n resolveUserConfigPath,\n transformUserConfigToPlugin,\n} from 'vuepress/cli'\nimport { createBuildApp } from 'vuepress/core'\nimport { fs, logger, path } from 'vuepress/utils'\nimport { getRedirectHTML } from '../node/generate/getRedirectHTML.js'\n\ninterface RedirectCommandOptions {\n hostname: string\n output?: string\n config?: string\n cache: string\n temp?: string\n cleanCache?: boolean\n cleanTemp?: boolean\n}\n\nconst require = createRequire(import.meta.url)\n\nconst cli = cac('vp-redirect')\nconst { version } = require('@vuepress/plugin-redirect/package.json') as {\n version: string\n}\n\ncli\n .command(\n 'generate [source-dir]',\n 'Generate redirect site using VuePress project under source folder',\n )\n .option(\n '--hostname <hostname>',\n 'Hostname to redirect to (E.g.: https://new.example.com/)',\n { default: '/' },\n )\n .option('-c, --config <config>', 'Set path to config file')\n .option(\n '-o, --output <output>',\n 'Set the output directory (default: .vuepress/redirect)',\n )\n .option('--cache <cache>', 'Set the directory of the cache files')\n .option('-t, --temp <temp>', 'Set the directory of the temporary files')\n .option('--clean-cache', 'Clean the cache files before generation')\n .option('--clean-temp', 'Clean the temporary files before generation')\n .action(async (sourceDir: string, commandOptions: RedirectCommandOptions) => {\n if (!sourceDir) {\n cli.outputHelp()\n return\n }\n\n // ensure NODE_ENV is set\n process.env.NODE_ENV ??= 'production'\n\n // resolve app config from cli options\n const cliAppConfig = resolveCliAppConfig(sourceDir, {})\n\n // resolve user config file\n const userConfigPath = commandOptions.config\n ? resolveUserConfigPath(commandOptions.config)\n : resolveUserConfigConventionalPath(cliAppConfig.source)\n\n const { userConfig } = await loadUserConfig(userConfigPath)\n\n // resolve the final app config to use\n const appConfig = resolveAppConfig({\n defaultAppConfig: {},\n cliAppConfig,\n userConfig,\n })\n\n if (appConfig === null) return\n\n // create vuepress app\n const app = createBuildApp(appConfig)\n\n // use user-config plugin\n app.use(transformUserConfigToPlugin(userConfig, cliAppConfig.source))\n\n // clean temp and cache\n if (commandOptions.cleanTemp === true) {\n logger.info('Cleaning temp...')\n await fs.remove(app.dir.temp())\n }\n if (commandOptions.cleanCache === true) {\n logger.info('Cleaning cache...')\n await fs.remove(app.dir.cache())\n }\n\n const outputFolder = commandOptions.output\n ? path.join(process.cwd(), commandOptions.output)\n : path.join(app.dir.source(), '.vuepress', 'redirect')\n\n // empty output directory\n await fs.emptyDir(outputFolder)\n\n // initialize vuepress app to get pages\n logger.info('Initializing VuePress and preparing data...')\n\n // initialize vuepress app to get pages\n await app.init()\n\n logger.info('Generating redirect pages...')\n\n // redirect all pages\n await Promise.all(\n app.pages.map((page) => {\n const redirectUrl = `${removeEndingSlash(commandOptions.hostname)}${\n app.options.base\n }${removeLeadingSlash(page.path)}`\n const destLocation = path.join(\n outputFolder,\n removeLeadingSlash(page.path.replace(/\\/$/, '/index.html')),\n )\n\n return fs\n .ensureDir(path.dirname(destLocation))\n .then(() => fs.writeFile(destLocation, getRedirectHTML(redirectUrl)))\n }),\n )\n })\n\ncli.command('').action(() => {\n cli.outputHelp()\n})\n\ncli.help()\ncli.version(version)\n\ncli.parse()\n"],"names":["getRedirectHTML","redirectUrl","require","createRequire","cli","cac","version","sourceDir","commandOptions","cliAppConfig","resolveCliAppConfig","userConfigPath","resolveUserConfigPath","resolveUserConfigConventionalPath","userConfig","loadUserConfig","appConfig","resolveAppConfig","app","createBuildApp","transformUserConfigToPlugin","logger","fs","outputFolder","path","page","removeEndingSlash","removeLeadingSlash","destLocation"],"mappings":";4bAAO,MAAMA,EAAmBC,GAAgC;AAAA;AAAA;AAAA;AAAA;AAAA,+CAKjBA,CAAW;AAAA,gCAC1BA,CAAW;AAAA;AAAA;AAAA;AAAA,wBAInBA,CAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,ECgB7BC,EAAUC,EAAc,YAAY,GAAG,EAEvCC,EAAMC,EAAI,aAAa,EACvB,CAAE,QAAAC,CAAQ,EAAIJ,EAAQ,wCAAwC,EAIpEE,EACG,QACC,wBACA,mEACF,EACC,OACC,wBACA,2DACA,C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,CAAC,GAC/DU,EAAI,QAAQ,IACd,GAAGS,EAAmBF,EAAK,IAAI,CAAC,GAC1BG,EAAeJ,EAAK,KACxBD,EACAI,EAAmBF,EAAK,KAAK,QAAQ,MAAO,aAAa,CAAC,CAC5D,EAEA,OAAOH,EACJ,UAAUE,EAAK,QAAQI,CAAY,CAAC,EACpC,KAAK,IAAMN,EAAG,UAAUM,EAAc5B,EAAgBC,CAAW,CAAC,CAAC,CACxE,CAAC,CACH,CACF,CAAC,EAEHG,EAAI,QAAQ,EAAE,EAAE,OAAO,IAAM,CAC3BA,EAAI,WACN,CAAA,CAAC,EAEDA,EAAI,KACJA,EAAAA,EAAI,QAAQE,CAAO,EAEnBF,EAAI,MAAM"}
@@ -1,4 +1,4 @@
1
- export interface RedirectLocaleConfig {
1
+ interface RedirectBehaviorOptions {
2
2
  /**
3
3
  * Whether enable locales redirection
4
4
  *
@@ -6,21 +6,7 @@ export interface RedirectLocaleConfig {
6
6
  *
7
7
  * @default false
8
8
  */
9
- autoLocale: boolean;
10
- /**
11
- * Whether switch locales
12
- *
13
- * 是否启用重定向语言
14
- *
15
- * @default false
16
- */
17
- switchLocale: 'direct' | 'modal' | false;
18
- /**
19
- * Locale language config
20
- *
21
- * 多语言语言配置
22
- */
23
- localeConfig: Record<string, string[]>;
9
+ autoLocale?: boolean;
24
10
  /**
25
11
  * Whether fallback to other locales user defined
26
12
  *
@@ -28,7 +14,7 @@ export interface RedirectLocaleConfig {
28
14
  *
29
15
  * @default true
30
16
  */
31
- localeFallback: boolean;
17
+ localeFallback?: boolean;
32
18
  /**
33
19
  * Behavior when a locale version is not available for current link
34
20
  *
@@ -40,7 +26,7 @@ export interface RedirectLocaleConfig {
40
26
  *
41
27
  * @default "defaultLocale"
42
28
  */
43
- defaultBehavior: '404' | 'defaultLocale' | 'homepage';
29
+ defaultBehavior?: '404' | 'defaultLocale' | 'homepage';
44
30
  /**
45
31
  * Default locale path
46
32
  *
@@ -50,5 +36,15 @@ export interface RedirectLocaleConfig {
50
36
  *
51
37
  * @description 如果缺失,则使用第一个语言
52
38
  */
53
- defaultLocale: string;
39
+ defaultLocale?: string;
40
+ }
41
+ interface RedirectBehaviorConfig extends Required<RedirectBehaviorOptions> {
42
+ /**
43
+ * Locale language config
44
+ *
45
+ * 多语言语言配置
46
+ */
47
+ config: Record<string, string[]>;
54
48
  }
49
+
50
+ export type { RedirectBehaviorConfig as R };
@@ -1,4 +1,60 @@
1
- import type { VNode } from 'vue';
2
- import '../styles/redirect-modal.css';
3
- declare const _default: import("vue").DefineComponent<{}, () => VNode | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
4
- export default _default;
1
+ import * as vue from 'vue';
2
+ import { PropType, VNode } from 'vue';
3
+ import { R as RedirectBehaviorConfig } from '../behavior-BgEQhx7R.js';
4
+ import { ExactLocaleConfig } from '@vuepress/helper/shared';
5
+
6
+ interface RedirectPluginLocaleData {
7
+ /**
8
+ * Language name
9
+ *
10
+ * 语言名称
11
+ */
12
+ name: string;
13
+ /**
14
+ * Switch hint
15
+ *
16
+ * 切换提示
17
+ */
18
+ hint: string;
19
+ /**
20
+ * Switch button text
21
+ *
22
+ * 切换按钮文字
23
+ */
24
+ switch: string;
25
+ /**
26
+ * Cancel button text
27
+ *
28
+ * 取消按钮文字
29
+ */
30
+ cancel: string;
31
+ /**
32
+ * remember hint text
33
+ *
34
+ * 记住提示文本
35
+ */
36
+ remember: string;
37
+ }
38
+ type RedirectPluginLocaleConfig = ExactLocaleConfig<RedirectPluginLocaleData>;
39
+
40
+ declare const _default: vue.DefineComponent<vue.ExtractPropTypes<{
41
+ config: {
42
+ type: PropType<RedirectBehaviorConfig>;
43
+ required: true;
44
+ };
45
+ locales: {
46
+ type: PropType<RedirectPluginLocaleConfig>;
47
+ required: true;
48
+ };
49
+ }>, () => VNode | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
50
+ config: {
51
+ type: PropType<RedirectBehaviorConfig>;
52
+ required: true;
53
+ };
54
+ locales: {
55
+ type: PropType<RedirectPluginLocaleConfig>;
56
+ required: true;
57
+ };
58
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
59
+
60
+ export { _default as default };
@@ -1,122 +1,2 @@
1
- import { useLocalStorage, usePreferredLanguages, useScrollLock, useSessionStorage, } from '@vueuse/core';
2
- import { TransitionGroup, computed, defineComponent, h, nextTick, onBeforeUnmount, onMounted, ref, watch, } from 'vue';
3
- import { useRouteLocale, useRoutePath, useRouter } from 'vuepress/client';
4
- import { redirectLocaleConfig, redirectLocaleEntries } from '../define.js';
5
- import '../styles/redirect-modal.css';
6
- const redirectLocales = __REDIRECT_LOCALES__;
7
- const { switchLocale } = redirectLocaleConfig;
8
- const REDIRECT_STORAGE_KEY = 'VUEPRESS_REDIRECT_STATUS';
9
- const redirectStatusSessionStorage = useSessionStorage(REDIRECT_STORAGE_KEY, {});
10
- const redirectStatusLocalStorage = useLocalStorage(REDIRECT_STORAGE_KEY, {});
11
- export default defineComponent({
12
- name: 'RedirectModal',
13
- setup() {
14
- const languages = usePreferredLanguages();
15
- const router = useRouter();
16
- const routePath = useRoutePath();
17
- const routeLocale = useRouteLocale();
18
- const body = ref();
19
- // lock body scroll when modal is displayed
20
- const showModal = useScrollLock(body);
21
- const shouldRemember = ref(false);
22
- const info = computed(() => {
23
- if (redirectLocaleEntries.some(([key]) => routeLocale.value === key))
24
- for (const language of languages.value)
25
- for (const [localePath, langs] of redirectLocaleEntries)
26
- if (langs.includes(language)) {
27
- if (localePath === routeLocale.value)
28
- return null;
29
- return {
30
- lang: language,
31
- localePath,
32
- };
33
- }
34
- return null;
35
- });
36
- const locale = computed(() => {
37
- if (info.value) {
38
- const { lang, localePath } = info.value;
39
- const locales = [
40
- redirectLocales[localePath],
41
- redirectLocales[routeLocale.value],
42
- ];
43
- return {
44
- hint: locales.map(({ hint }) => hint.replace('$1', lang)),
45
- switch: locales
46
- .map(({ switch: switchText }) => switchText.replace('$1', lang))
47
- .join(' / '),
48
- cancel: locales.map(({ cancel }) => cancel).join(' / '),
49
- remember: locales.map(({ remember }) => remember).join(' / '),
50
- };
51
- }
52
- return null;
53
- });
54
- const redirect = () => {
55
- router.replace(routePath.value.replace(routeLocale.value, info.value.localePath));
56
- };
57
- watch(routePath, () => {
58
- showModal.value = false;
59
- });
60
- onMounted(async () => {
61
- body.value = document.body;
62
- await nextTick();
63
- if (!redirectStatusSessionStorage.value[routeLocale.value] &&
64
- info.value) {
65
- if (switchLocale === 'direct')
66
- redirect();
67
- else if (switchLocale === 'modal' &&
68
- !redirectStatusLocalStorage.value[routeLocale.value])
69
- showModal.value = true;
70
- }
71
- });
72
- onBeforeUnmount(() => {
73
- showModal.value = false;
74
- });
75
- return () => h(TransitionGroup, { name: 'redirect-modal-fade' }, () => showModal.value
76
- ? h('div', { key: 'mask', class: 'redirect-modal-mask' }, h('div', {
77
- key: 'popup',
78
- class: 'redirect-modal-wrapper',
79
- }, [
80
- h('div', { class: 'redirect-modal-content' }, locale.value?.hint.map((text) => h('p', text))),
81
- h('div', { class: 'redirect-modal-hint' }, [
82
- h('input', {
83
- id: 'remember-redirect',
84
- type: 'checkbox',
85
- value: shouldRemember.value,
86
- onChange: () => {
87
- shouldRemember.value = !shouldRemember.value;
88
- },
89
- }),
90
- h('label', { for: 'remember-redirect' }, locale.value?.remember),
91
- ]),
92
- h('button', {
93
- type: 'button',
94
- class: 'redirect-modal-action primary',
95
- onClick: () => {
96
- redirectStatusSessionStorage.value[routeLocale.value] =
97
- true;
98
- if (shouldRemember.value) {
99
- redirectStatusLocalStorage.value[routeLocale.value] =
100
- true;
101
- }
102
- showModal.value = false;
103
- redirect();
104
- },
105
- }, locale.value?.switch),
106
- h('button', {
107
- type: 'button',
108
- class: 'redirect-modal-action',
109
- onClick: () => {
110
- redirectStatusSessionStorage.value[routeLocale.value] =
111
- true;
112
- if (shouldRemember.value) {
113
- redirectStatusLocalStorage.value[routeLocale.value] =
114
- true;
115
- }
116
- showModal.value = false;
117
- },
118
- }, locale.value?.cancel),
119
- ]))
120
- : null);
121
- },
122
- });
1
+ import{useScrollLock as y}from"@vueuse/core";import{defineComponent as k,ref as p,computed as g,watch as w,onMounted as R,nextTick as j,onBeforeUnmount as C,h as e,TransitionGroup as S}from"vue";import{useRouter as x,useRoutePath as L,useRouteLocale as M}from"vuepress/client";import"../styles/redirect-modal.css";import{u as P,s as v,a as h}from"../useRedirectInfo-Bi8syic3.js";import"@vuepress/helper/client";var $=k({name:"RedirectModal",props:{config:{type:Object,required:!0},locales:{type:Object,required:!0}},setup(n){const b=x(),s=L(),l=M(),r=P(n.config),m=p(),t=y(m),o=p(!1),u=g(()=>{if(!r.value)return null;const{lang:c,localePath:f}=r.value,i=[n.locales[f],n.locales[l.value]];return{hint:i.map(({hint:a})=>a.replace("$1",c)),switch:i.map(({switch:a})=>a.replace("$1",c)).join(" / "),cancel:i.map(({cancel:a})=>a).join(" / "),remember:i.map(({remember:a})=>a).join(" / ")}}),d=()=>{v.value[l.value]=!0,o.value&&(h.value[l.value]=!0),t.value=!1};return w(s,()=>{t.value=!1}),R(async()=>{m.value=document.body,await j(),r.value&&!v.value[l.value]&&!h.value[l.value]&&(t.value=!0)}),C(()=>{t.value=!1}),()=>e(S,{name:"redirect-modal-fade"},()=>t.value?e("div",{key:"mask",class:"redirect-modal-mask"},e("div",{key:"popup",class:"redirect-modal-wrapper"},[e("div",{class:"redirect-modal-content"},u.value?.hint.map(c=>e("p",c))),e("div",{class:"redirect-modal-hint"},[e("input",{id:"remember-redirect",type:"checkbox",value:o.value,onChange:()=>{o.value=!o.value}}),e("label",{for:"remember-redirect"},u.value?.remember)]),e("button",{type:"button",class:"redirect-modal-action primary",onClick:()=>{d(),b.replace(s.value.replace(l.value,r.value.localePath))}},u.value?.switch),e("button",{type:"button",class:"redirect-modal-action",onClick:()=>{d()}},u.value?.cancel)])):null)}});export{$ as default};
2
+ //# sourceMappingURL=RedirectModal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RedirectModal.js","sources":["../../../src/client/components/RedirectModal.ts"],"sourcesContent":["import { useScrollLock } from '@vueuse/core'\nimport type { PropType, VNode } from 'vue'\nimport {\n TransitionGroup,\n computed,\n defineComponent,\n h,\n nextTick,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n} from 'vue'\nimport { useRouteLocale, useRoutePath, useRouter } from 'vuepress/client'\nimport type {\n RedirectBehaviorConfig,\n RedirectPluginLocaleConfig,\n} from '../../shared/index.js'\nimport { useRedirectInfo } from '../composables/index.js'\nimport { statusLocalStorage, statusSessionStorage } from '../utils/index.js'\n\nimport '../styles/redirect-modal.css'\n\nexport default defineComponent({\n name: 'RedirectModal',\n\n props: {\n config: {\n type: Object as PropType<RedirectBehaviorConfig>,\n required: true,\n },\n\n locales: {\n type: Object as PropType<RedirectPluginLocaleConfig>,\n required: true,\n },\n },\n\n setup(props) {\n const router = useRouter()\n const routePath = useRoutePath()\n const routeLocale = useRouteLocale()\n const redirectInfo = useRedirectInfo(props.config)\n\n const body = ref<HTMLElement>()\n // lock body scroll when modal is displayed\n const showModal = useScrollLock(body)\n const shouldRemember = ref(false)\n\n const locale = computed(() => {\n if (!redirectInfo.value) return null\n\n const { lang, localePath } = redirectInfo.value\n const locales = [\n props.locales[localePath],\n props.locales[routeLocale.value],\n ]\n\n return {\n hint: locales.map(({ hint }) => hint.replace('$1', lang)),\n switch: locales\n .map(({ switch: switchText }) => switchText.replace('$1', lang))\n .join(' / '),\n cancel: locales.map(({ cancel }) => cancel).join(' / '),\n remember: locales.map(({ remember }) => remember).join(' / '),\n }\n })\n\n const updateState = (): void => {\n statusSessionStorage.value[routeLocale.value] = true\n if (shouldRemember.value) {\n statusLocalStorage.value[routeLocale.value] = true\n }\n showModal.value = false\n }\n\n watch(routePath, () => {\n showModal.value = false\n })\n\n onMounted(async () => {\n body.value = document.body\n\n await nextTick()\n\n if (\n redirectInfo.value &&\n !statusSessionStorage.value[routeLocale.value] &&\n !statusLocalStorage.value[routeLocale.value]\n ) {\n showModal.value = true\n }\n })\n\n onBeforeUnmount(() => {\n showModal.value = false\n })\n\n return (): VNode | null =>\n h(TransitionGroup, { name: 'redirect-modal-fade' }, () =>\n showModal.value\n ? h(\n 'div',\n { key: 'mask', class: 'redirect-modal-mask' },\n h(\n 'div',\n {\n key: 'popup',\n class: 'redirect-modal-wrapper',\n },\n [\n h(\n 'div',\n { class: 'redirect-modal-content' },\n locale.value?.hint.map((text) => h('p', text)),\n ),\n h('div', { class: 'redirect-modal-hint' }, [\n h('input', {\n id: 'remember-redirect',\n type: 'checkbox',\n value: shouldRemember.value,\n onChange: () => {\n shouldRemember.value = !shouldRemember.value\n },\n }),\n h(\n 'label',\n { for: 'remember-redirect' },\n locale.value?.remember,\n ),\n ]),\n h(\n 'button',\n {\n type: 'button',\n class: 'redirect-modal-action primary',\n onClick: () => {\n updateState()\n router.replace(\n routePath.value.replace(\n routeLocale.value,\n redirectInfo.value!.localePath,\n ),\n )\n },\n },\n locale.value?.switch,\n ),\n h(\n 'button',\n {\n type: 'button',\n class: 'redirect-modal-action',\n onClick: () => {\n updateState()\n },\n },\n locale.value?.cancel,\n ),\n ],\n ),\n )\n : null,\n )\n },\n})\n"],"names":["RedirectModal","defineComponent","props","router","useRouter","routePath","useRoutePath","routeLocale","useRouteLocale","redirectInfo","useRedirectInfo","body","ref","showModal","useScrollLock","shouldRemember","locale","computed","lang","localePath","locales","hint","switchText","cancel","remember","updateState","statusSessionStorage","statusLocalStorage","watch","onMounted","nextTick","onBeforeUnmount","h","TransitionGroup","text"],"mappings":"2ZAuBA,IAAAA,EAAeC,EAAgB,CAC7B,KAAM,gBAEN,MAAO,CACL,OAAQ,CACN,KAAM,OACN,SAAU,EACZ,EAEA,QAAS,CACP,KAAM,O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kB,EAAgB,IAAM,CACpBlB,EAAU,MAAQ,EACpB,CAAC,EAEM,IACLmB,EAAEC,EAAiB,CAAE,KAAM,qBAAsB,EAAG,IAClDpB,EAAU,MACNmB,EACE,MACA,CAAE,IAAK,OAAQ,MAAO,qBAAsB,EAC5CA,EACE,MACA,CACE,IAAK,QACL,MAAO,wBACT,EACA,CACEA,EACE,MACA,CAAE,MAAO,wBAAyB,EAClChB,EAAO,OAAO,KAAK,IAAKkB,GAASF,EAAE,IAAKE,CAAI,CAAC,CAC/C,EACAF,EAAE,MAAO,CAAE,MAAO,qBAAsB,EAAG,CACzCA,EAAE,QAAS,CACT,GAAI,oBACJ,KAAM,WACN,MAAOjB,EAAe,MACtB,SAAU,IAAM,CACdA,EAAe,MAAQ,CAACA,EAAe,KACzC,CACF,CAAC,EACDiB,EACE,QACA,CAAE,IAAK,mBAAoB,EAC3BhB,EAAO,OAAO,QAChB,CACF,CAAC,EACDgB,EACE,SACA,CACE,KAAM,SACN,MAAO,gCACP,QAAS,IAAM,CACbP,EAAY,EACZtB,EAAO,QACLE,EAAU,MAAM,QACdE,EAAY,MACZE,EAAa,MAAO,UACtB,CACF,CACF,CACF,EACAO,EAAO,OAAO,MAChB,EACAgB,EACE,SACA,CACE,KAAM,SACN,MAAO,wBACP,QAAS,IAAM,CACbP,GACF,CACF,EACAT,EAAO,OAAO,MAChB,CACF,CACF,CACF,EACA,IACN,CACJ,CACF,CAAC"}
@@ -1,3 +1,7 @@
1
- import './styles/vars.css';
2
- declare const _default: import("vuepress/client").ClientConfig;
3
- export default _default;
1
+ import * as vuepress_client from 'vuepress/client';
2
+ import { R as RedirectBehaviorConfig } from './behavior-BgEQhx7R.js';
3
+
4
+ declare const config: RedirectBehaviorConfig;
5
+ declare const _default: vuepress_client.ClientConfig;
6
+
7
+ export { config, _default as default };
@@ -1,11 +1,2 @@
1
- import { defineClientConfig } from 'vuepress/client';
2
- import RedirectModal from './components/RedirectModal.js';
3
- import { setupDevServerRedirect } from './composables/index.js';
4
- import './styles/vars.css';
5
- export default defineClientConfig({
6
- setup() {
7
- if (__VUEPRESS_DEV__)
8
- setupDevServerRedirect();
9
- },
10
- rootComponents: __REDIRECT_LOCALE_SWITCH__ ? [RedirectModal] : [],
11
- });
1
+ import o from"@vuepress/plugin-redirect/modal";import{h as r}from"vue";import{defineClientConfig as t}from"vuepress/client";import"./styles/vars.css";import{a as e,s as i}from"./setupRedirect-q886RMSd.js";import"@temp/redirect/map.js";import"@vuepress/helper/client";import"@vueuse/core";import"./useRedirectInfo-Bi8syic3.js";const _=__REDIRECT_CONFIG__;var m=t({setup(){__REDIRECT_DIRECT__&&e(_),__VUEPRESS_DEV__&&i(_)},...__REDIRECT_MODAL__?{rootComponents:[()=>r(o,{config:_,locales:__REDIRECT_LOCALES__})]}:{}});export{_ as config,m as default};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sources":["../../src/client/config.ts"],"sourcesContent":["import RedirectModal from '@vuepress/plugin-redirect/modal'\nimport { h } from 'vue'\nimport { defineClientConfig } from 'vuepress/client'\nimport type {\n RedirectBehaviorConfig,\n RedirectPluginLocaleConfig,\n} from '../shared/index.js'\nimport { setupDevServerRedirect, setupRedirect } from './composables/index.js'\n\nimport './styles/vars.css'\n\ndeclare const __REDIRECT_CONFIG__: RedirectBehaviorConfig\ndeclare const __REDIRECT_LOCALES__: RedirectPluginLocaleConfig\ndeclare const __REDIRECT_DIRECT__: boolean\ndeclare const __REDIRECT_MODAL__: boolean\n\nexport const config = __REDIRECT_CONFIG__\n\nexport default defineClientConfig({\n setup() {\n if (__REDIRECT_DIRECT__) setupRedirect(config)\n if (__VUEPRESS_DEV__) setupDevServerRedirect(config)\n },\n ...(__REDIRECT_MODAL__\n ? {\n rootComponents: [\n () =>\n h(RedirectModal, {\n config,\n locales: __REDIRECT_LOCALES__,\n }),\n ],\n }\n : {}),\n})\n"],"names":["config","config$1","defineClientConfig","setupRedirect","setupDevServerRedirect","h","RedirectModal"],"mappings":"sUAgBO,MAAMA,EAAS,oBAEtB,IAAAC,EAAeC,EAAmB,CAChC,OAAQ,CACF,qBAAqBC,EAAcH,CAAM,EACzC,kBAAkBI,EAAuBJ,CAAM,CACrD,EACA,GAAI,mBACA,CACE,eAAgB,CACd,IACEK,EAAEC,EAAe,CACf,OAAAN,EACA,QAAS,oBACX,CAAC,CACL,CACF,EACA,CACN,CAAA,CAAC"}
@@ -0,0 +1,20 @@
1
+ export { default as RedirectModal } from './components/RedirectModal.js';
2
+ import { R as RedirectBehaviorConfig } from './behavior-BgEQhx7R.js';
3
+ import { ComputedRef } from 'vue';
4
+ import '@vuepress/helper/shared';
5
+
6
+ declare const setupDevServerRedirect: ({ autoLocale, config, defaultBehavior, defaultLocale: defaultLocalePath, localeFallback, }: RedirectBehaviorConfig) => void;
7
+
8
+ interface LocaleInfo {
9
+ lang: string;
10
+ localePath: string;
11
+ }
12
+ declare const setupRedirect: (behaviorConfig: RedirectBehaviorConfig) => void;
13
+
14
+ interface RedirectInfo {
15
+ lang: string;
16
+ localePath: string;
17
+ }
18
+ declare const useRedirectInfo: (behaviorConfig: RedirectBehaviorConfig) => ComputedRef<RedirectInfo | null>;
19
+
20
+ export { type LocaleInfo, type RedirectInfo, setupDevServerRedirect, setupRedirect, useRedirectInfo };
@@ -0,0 +1,2 @@
1
+ import{default as a}from"./components/RedirectModal.js";import{s as f,a as u}from"./setupRedirect-q886RMSd.js";import{u as R}from"./useRedirectInfo-Bi8syic3.js";import"@vueuse/core";import"vue";import"vuepress/client";import"./styles/redirect-modal.css";import"@temp/redirect/map.js";import"@vuepress/helper/client";export{a as RedirectModal,f as setupDevServerRedirect,u as setupRedirect,R as useRedirectInfo};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import{redirectMap as k}from"@temp/redirect/map.js";import{entries as M,isLinkHttp as S}from"@vuepress/helper/client";import{usePreferredLanguages as $}from"@vueuse/core";import{computed as x,watch as C,onMounted as D}from"vue";import{useRoute as E,useRouter as d,useRouteLocale as v,useRoutePath as j}from"vuepress/client";import{u as y,s as R}from"./useRedirectInfo-Bi8syic3.js";const z=/#.*$/u,A=(o,l=!1)=>(l?o.replace(z,""):o).replace(/\/(?:README\.md)?$/i,"/index.html").replace(/(?:\.(?:md|html))?$/,".html"),B=({autoLocale:o,config:l,defaultBehavior:r,defaultLocale:p,localeFallback:m})=>{const L=Object.entries(l),g=$(),e=E(),s=d(),P=v(),w=x(()=>P.value==="/"),b=()=>{const c=s.getRoutes(),u=p&&c.some(({path:a})=>a===e.path.replace("/",p))?p:c.find(({path:a})=>e.path.split("/").length>=3&&a===e.path.replace(/^\/[^/]+\//,"/"))?.path;let t=null;e:for(const a of g.value)for(const[i,f]of L)if(f.includes(a)){if(m&&c.every(({path:h})=>h!==e.path.replace("/",h)))continue;t=i;break e}const n=u?e.fullPath.replace("/",u):null;if(t){const a=c.some(({path:h})=>e.path.replace("/",t)===h),i=e.fullPath.replace("/",t),f=a?i:r==="homepage"?t:r==="defaultLocale"&&n?n:i;s.replace(f)}else n?s.replace(n):e.path!=="/404.html"&&s.replace("/404.html")};C(()=>e.path,c=>{for(const[u,t]of M(k))if(A(c.toLowerCase())===u.toLowerCase()){S(t)?window.open(t):s.replace(t);return}o&&w.value&&b()},{immediate:!0})},F=o=>{const l=y(o),r=v(),p=j(),m=d();D(()=>{l.value&&!R.value[r.value]&&(m.replace(p.value.replace(r.value,l.value.localePath)),R.value[r.value]=!0)})};export{F as a,B as s};
2
+ //# sourceMappingURL=setupRedirect-q886RMSd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupRedirect-q886RMSd.js","sources":["../../src/shared/normalizePath.ts","../../src/client/composables/setupDevServerRedirect.ts","../../src/client/composables/setupRedirect.ts"],"sourcesContent":["const HASH_REGEXP = /#.*$/u\n\nexport const normalizePath = (path: string, removeHash = false): string =>\n (removeHash ? path.replace(HASH_REGEXP, '') : path)\n .replace(/\\/(?:README\\.md)?$/i, '/index.html')\n .replace(/(?:\\.(?:md|html))?$/, '.html')\n","import { redirectMap } from '@temp/redirect/map.js'\nimport { entries, isLinkHttp } from '@vuepress/helper/client'\nimport { usePreferredLanguages } from '@vueuse/core'\nimport { computed, watch } from 'vue'\nimport { useRoute, useRouteLocale, useRouter } from 'vuepress/client'\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\nimport { normalizePath } from '../../shared/index.js'\n\nexport const setupDevServerRedirect = ({\n autoLocale,\n config,\n defaultBehavior,\n defaultLocale: defaultLocalePath,\n localeFallback,\n}: RedirectBehaviorConfig): void => {\n const localeEntries = Object.entries(config)\n const languages = usePreferredLanguages()\n const route = useRoute()\n const router = useRouter()\n const routeLocale = useRouteLocale()\n\n const isRootLocale = computed(() => routeLocale.value === '/')\n\n const handleLocaleRedirect = (): void => {\n const routes = router.getRoutes()\n const defaultLocale =\n defaultLocalePath &&\n routes.some(\n ({ path }) => path === route.path.replace('/', defaultLocalePath),\n )\n ? defaultLocalePath\n : routes.find(\n ({ path }) =>\n route.path.split('/').length >= 3 &&\n path === route.path.replace(/^\\/[^/]+\\//, '/'),\n )?.path\n\n let matchedLocalePath: string | null = null\n\n // get matched locale\n // eslint-disable-next-line no-restricted-syntax\n findLanguage: for (const lang of languages.value)\n for (const [localePath, langs] of localeEntries)\n if (langs.includes(lang)) {\n if (\n localeFallback &&\n routes.every(({ path }) => path !== route.path.replace('/', path))\n )\n continue\n\n matchedLocalePath = localePath\n break findLanguage\n }\n\n // default link\n const defaultRoute = defaultLocale\n ? route.fullPath.replace('/', defaultLocale)\n : null\n\n // a locale matches\n if (matchedLocalePath) {\n const hasLocalePage = routes.some(\n ({ path }) => route.path.replace('/', matchedLocalePath) === path,\n )\n const localeRoute = route.fullPath.replace('/', matchedLocalePath)\n\n const routePath =\n // the locale page exists\n hasLocalePage\n ? localeRoute\n : // the page does not exist\n defaultBehavior === 'homepage'\n ? // locale homepage\n matchedLocalePath\n : defaultBehavior === 'defaultLocale' && defaultRoute\n ? // default locale page\n defaultRoute\n : // as is to get a 404 page of that locale\n localeRoute\n\n router.replace(routePath)\n }\n // we have a default page\n else if (defaultRoute) {\n router.replace(defaultRoute)\n } else if (route.path !== '/404.html') {\n router.replace('/404.html')\n }\n }\n\n watch(\n () => route.path,\n (path) => {\n // handle redirects\n for (const [from, to] of entries(redirectMap))\n if (normalizePath(path.toLowerCase()) === from.toLowerCase()) {\n if (isLinkHttp(to)) window.open(to)\n else router.replace(to)\n\n return\n }\n\n if (autoLocale && isRootLocale.value) handleLocaleRedirect()\n },\n { immediate: true },\n )\n}\n","import { onMounted } from 'vue'\nimport { useRouteLocale, useRoutePath, useRouter } from 'vuepress/client'\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\nimport { statusSessionStorage } from '../utils/index.js'\nimport { useRedirectInfo } from './useRedirectInfo.js'\n\nexport interface LocaleInfo {\n lang: string\n localePath: string\n}\n\nexport const setupRedirect = (behaviorConfig: RedirectBehaviorConfig): void => {\n const redirectInfo = useRedirectInfo(behaviorConfig)\n const routeLocale = useRouteLocale()\n const routePath = useRoutePath()\n const router = useRouter()\n\n onMounted(() => {\n if (redirectInfo.value && !statusSessionStorage.value[routeLocale.value]) {\n router.replace(\n routePath.value.replace(\n routeLocale.value,\n redirectInfo.value.localePath,\n ),\n )\n statusSessionStorage.value[routeLocale.value] = true\n }\n })\n}\n"],"names":["HASH_REGEXP","normalizePath","path","removeHash","setupDevServerRedirect","autoLocale","config","defaultBehavior","defaultLocalePath","localeFallback","localeEntries","languages","usePreferredLanguages","route","useRoute","router","useRouter","routeLocale","useRouteLocale","isRootLocale","computed","handleLocaleRedirect","routes","defaultLocale","matchedLocalePath","findLanguage","lang","localePath","langs","defaultRoute","hasLocalePage","localeRoute","routePath","watch","from","to","entries","redirectMap","isLinkHttp","setupRedirect","behaviorConfig","redirectInfo","useRedirectInfo","useRoutePath","onMounted","statusSession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AC/D,EACM6B,EAAclB,EAAM,SAAS,QAAQ,IAAKW,CAAiB,EAE3DQ,EAEJF,EACIC,EAEAxB,IAAoB,WAElBiB,EACAjB,IAAoB,iBAAmBsB,EAErCA,EAEAE,EAEVhB,EAAO,QAAQiB,CAAS,CAC1B,MAESH,EACPd,EAAO,QAAQc,CAAY,EAClBhB,EAAM,OAAS,aACxBE,EAAO,QAAQ,WAAW,CAE9B,EAEAkB,EACE,IAAMpB,EAAM,KACXX,GAAS,CAER,SAAW,CAACgC,EAAMC,CAAE,IAAKC,EAAQC,CAAW,EAC1C,GAAIpC,EAAcC,EAAK,YAAa,CAAA,IAAMgC,EAAK,YAAA,EAAe,CACxDI,EAAWH,CAAE,EAAG,OAAO,KAAKA,CAAE,EAC7BpB,EAAO,QAAQoB,CAAE,EAEtB,MACF,CAEE9B,GAAcc,EAAa,OAAOE,EAAqB,CAC7D,EACA,CAAE,UAAW,EAAK,CACpB,CACF,EC/FakB,EAAiBC,GAAiD,CAC7E,MAAMC,EAAeC,EAAgBF,CAAc,EAC7CvB,EAAcC,IACdc,EAAYW,IACZ5B,EAASC,IAEf4B,EAAU,IAAM,CACVH,EAAa,OAAS,CAACI,EAAqB,MAAM5B,EAAY,KAAK,IACrEF,EAAO,QACLiB,EAAU,MAAM,QACdf,EAAY,MACZwB,EAAa,MAAM,UACrB,CACF,EACAI,EAAqB,MAAM5B,EAAY,KAAK,EAAI,GAEpD,CAAC,CACH"}
@@ -0,0 +1,2 @@
1
+ import{useLocalStorage as c,useSessionStorage as l,usePreferredLanguages as f}from"@vueuse/core";import{entries as i}from"@vuepress/helper/client";import{computed as m}from"vue";import{useRouteLocale as S}from"vuepress/client";const s="VUEPRESS_REDIRECT_STATUS",g=c(s,{}),p=l(s,{}),R=a=>{const u=f(),e=S(),t=i(a.config);return m(()=>{if(t.some(([o])=>e.value===o)){for(const o of u.value)for(const[r,n]of t)if(n.includes(o))return r===e.value?null:{lang:o,localePath:r}}return null})};export{g as a,p as s,R as u};
2
+ //# sourceMappingURL=useRedirectInfo-Bi8syic3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRedirectInfo-Bi8syic3.js","sources":["../../src/client/utils/storage.ts","../../src/client/composables/useRedirectInfo.ts"],"sourcesContent":["import { useLocalStorage, useSessionStorage } from '@vueuse/core'\n\nconst REDIRECT_STORAGE_KEY = 'VUEPRESS_REDIRECT_STATUS'\n\nexport const statusLocalStorage = useLocalStorage<Record<string, boolean>>(\n REDIRECT_STORAGE_KEY,\n {},\n)\n\nexport const statusSessionStorage = useSessionStorage<Record<string, boolean>>(\n REDIRECT_STORAGE_KEY,\n {},\n)\n","import { entries } from '@vuepress/helper/client'\nimport { usePreferredLanguages } from '@vueuse/core'\nimport type { ComputedRef } from 'vue'\nimport { computed } from 'vue'\nimport { useRouteLocale } from 'vuepress/client'\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\n\nexport interface RedirectInfo {\n lang: string\n localePath: string\n}\n\nexport const useRedirectInfo = (\n behaviorConfig: RedirectBehaviorConfig,\n): ComputedRef<RedirectInfo | null> => {\n const languages = usePreferredLanguages()\n const routeLocale = useRouteLocale()\n\n const localeEntries = entries(behaviorConfig.config)\n\n return computed(() => {\n if (localeEntries.some(([key]) => routeLocale.value === key))\n for (const language of languages.value)\n for (const [localePath, langs] of localeEntries)\n if (langs.includes(language)) {\n if (localePath === routeLocale.value) return null\n\n return {\n lang: language,\n localePath,\n }\n }\n\n return null\n })\n}\n"],"names":["REDIRECT_STORAGE_KEY","statusLocalStorage","useLocalStorage","statusSessionStorage","useSessionStorage","useRedirectInfo","behaviorConfig","languages","usePreferredLanguages","routeLocale","useRouteLocale","localeEntries","entries","computed","key","language","localePath","langs"],"mappings":"mOAEA,MAAMA,EAAuB,2BAEhBC,EAAqBC,EAChCF,EACA,CACF,CAAA,EAEaG,EAAuBC,EAClCJ,EACA,CACF,CAAA,ECAaK,EACXC,GACqC,CACrC,MAAMC,EAAYC,EAAAA,EACZC,EAAcC,EAEdC,EAAAA,EAAgBC,EAAQN,EAAe,MAAM,EAEnD,OAAOO,EAAS,IAAM,CACpB,GAAIF,EAAc,KAAK,CAAC,CAACG,CAAG,IAAML,EAAY,QAAUK,CAAG,GACzD,UAAWC,KAAYR,EAAU,MAC/B,SAAW,CAACS,EAAYC,CAAK,IAAKN,EAChC,GAAIM,EAAM,SAASF,CAAQ,EACzB,OAAIC,IAAeP,EAAY,MAAc,KAEtC,CACL,KAAMM,EACN,WAAAC,CACF,EAGR,OAAO,IACT,CAAC,CACH"}
@@ -1,2 +1,112 @@
1
- export * from './redirectPlugin.js';
2
- export type * from './types/index.js';
1
+ import { App, LocaleConfig, PluginFunction } from 'vuepress/core';
2
+ import { PageFrontmatter } from 'vuepress';
3
+
4
+ interface RedirectPluginFrontmatter extends PageFrontmatter {
5
+ redirectFrom?: string[] | string;
6
+ redirectTo?: string;
7
+ }
8
+
9
+ interface RedirectBehaviorOptions {
10
+ /**
11
+ * Whether enable locales redirection
12
+ *
13
+ * 是否启用语言重定向
14
+ *
15
+ * @default false
16
+ */
17
+ autoLocale?: boolean;
18
+ /**
19
+ * Whether fallback to other locales user defined
20
+ *
21
+ * 是否回退到用户定义的其他语言
22
+ *
23
+ * @default true
24
+ */
25
+ localeFallback?: boolean;
26
+ /**
27
+ * Behavior when a locale version is not available for current link
28
+ *
29
+ * @description `"homepage"` and `"404"` is only available when a locale is assigned to current language
30
+ *
31
+ * 当前链接没有可用的语言版本时的行为
32
+ *
33
+ * @description 只有当语言分配给当前语言时,`"homepage"` 和 `"404"` 才可用
34
+ *
35
+ * @default "defaultLocale"
36
+ */
37
+ defaultBehavior?: '404' | 'defaultLocale' | 'homepage';
38
+ /**
39
+ * Default locale path
40
+ *
41
+ * @description the first locale will be used if absent
42
+ *
43
+ * 默认语言路径
44
+ *
45
+ * @description 如果缺失,则使用第一个语言
46
+ */
47
+ defaultLocale?: string;
48
+ }
49
+
50
+ interface RedirectPluginLocaleData {
51
+ /**
52
+ * Language name
53
+ *
54
+ * 语言名称
55
+ */
56
+ name: string;
57
+ /**
58
+ * Switch hint
59
+ *
60
+ * 切换提示
61
+ */
62
+ hint: string;
63
+ /**
64
+ * Switch button text
65
+ *
66
+ * 切换按钮文字
67
+ */
68
+ switch: string;
69
+ /**
70
+ * Cancel button text
71
+ *
72
+ * 取消按钮文字
73
+ */
74
+ cancel: string;
75
+ /**
76
+ * remember hint text
77
+ *
78
+ * 记住提示文本
79
+ */
80
+ remember: string;
81
+ }
82
+
83
+ interface RedirectPluginOptions extends RedirectBehaviorOptions {
84
+ /**
85
+ * Redirect mapping
86
+ *
87
+ * 重定向映射
88
+ */
89
+ config?: Record<string, string> | ((app: App) => Record<string, string>);
90
+ /**
91
+ * Whether switch locales
92
+ *
93
+ * 是否启用重定向语言
94
+ */
95
+ switchLocale?: 'direct' | 'modal';
96
+ /**
97
+ * Locale language config
98
+ *
99
+ * 多语言语言配置
100
+ */
101
+ localeConfig?: Record<string, string[] | string>;
102
+ /**
103
+ * Locales config
104
+ *
105
+ * 多语言选项
106
+ */
107
+ locales?: LocaleConfig<RedirectPluginLocaleData>;
108
+ }
109
+
110
+ declare const redirectPlugin: (options?: RedirectPluginOptions) => PluginFunction;
111
+
112
+ export { type RedirectPluginFrontmatter, type RedirectPluginOptions, redirectPlugin };