@vuepress/plugin-redirect 2.0.0-rc.47 → 2.0.0-rc.52
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 -77
- 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 +60 -4
- package/lib/client/components/RedirectModal.js +2 -95
- package/lib/client/components/RedirectModal.js.map +1 -0
- package/lib/client/config.d.ts +7 -3
- package/lib/client/config.js +2 -11
- package/lib/client/config.js.map +1 -0
- package/lib/client/index.d.ts +20 -0
- package/lib/client/index.js +2 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/setupRedirect-q886RMSd.js +2 -0
- package/lib/client/setupRedirect-q886RMSd.js.map +1 -0
- package/lib/client/styles/redirect-modal.css +1 -1
- package/lib/client/styles/redirect-modal.css.map +1 -1
- package/lib/client/useRedirectInfo-Bi8syic3.js +2 -0
- package/lib/client/useRedirectInfo-Bi8syic3.js.map +1 -0
- package/lib/node/index.d.ts +112 -2
- package/lib/node/index.js +90 -1
- package/lib/node/index.js.map +1 -0
- package/package.json +6 -5
- package/lib/cli/index.d.ts +0 -2
- 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 -78
- package/lib/client/define.d.ts +0 -3
- package/lib/client/define.js +0 -3
- package/lib/node/ensureRootHomePage.d.ts +0 -2
- package/lib/node/ensureRootHomePage.js +0 -15
- 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 -33
- 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/redirectPlugin.d.ts +0 -3
- package/lib/node/redirectPlugin.js +0 -53
- package/lib/node/types/frontmatter.d.ts +0 -4
- package/lib/node/types/frontmatter.js +0 -1
- package/lib/node/types/index.d.ts +0 -2
- package/lib/node/types/index.js +0 -1
- package/lib/node/types/options.d.ts +0 -22
- package/lib/node/types/options.js +0 -1
- 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
package/lib/cli/index.js
CHANGED
|
@@ -1,78 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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,CAAE,QAAS,GAAI,CACjB,EACC,OAAO,wBAAyB,yBAAyB,EACzD,OACC,wBACA,wDACF,EACC,OAAO,kBAAmB,sCAAsC,EAChE,OAAO,oBAAqB,0CAA0C,EACtE,OAAO,gBAAiB,yCAAyC,EACjE,OAAO,eAAgB,6CAA6C,EACpE,OAAO,MAAOG,EAAmBC,IAA2C,CAC3E,GAAI,CAACD,EAAW,CACdH,EAAI,WACJ,EAAA,MACF,CAGA,QAAQ,IAAI,WAAa,aAGzB,MAAMK,EAAeC,EAAoBH,EAAW,CAAA,CAAE,EAGhDI,EAAiBH,EAAe,OAClCI,EAAsBJ,EAAe,MAAM,EAC3CK,EAAkCJ,EAAa,MAAM,EAEnD,CAAE,WAAAK,CAAW,EAAI,MAAMC,EAAeJ,CAAc,EAGpDK,EAAYC,EAAiB,CACjC,iBAAkB,CAAA,EAClB,aAAAR,EACA,WAAAK,CACF,CAAC,EAED,GAAIE,IAAc,KAAM,OAGxB,MAAME,EAAMC,EAAeH,CAAS,EAGpCE,EAAI,IAAIE,EAA4BN,EAAYL,EAAa,MAAM,CAAC,EAGhED,EAAe,YAAc,KAC/Ba,EAAO,KAAK,kBAAkB,EAC9B,MAAMC,EAAG,OAAOJ,EAAI,IAAI,KAAK,CAAC,GAE5BV,EAAe,aAAe,KAChCa,EAAO,KAAK,mBAAmB,EAC/B,MAAMC,EAAG,OAAOJ,EAAI,IAAI,MAAO,CAAA,GAGjC,MAAMK,EAAef,EAAe,OAChCgB,EAAK,KAAK,QAAQ,IAAI,EAAGhB,EAAe,MAAM,EAC9CgB,EAAK,KAAKN,EAAI,IAAI,SAAU,YAAa,UAAU,EAGvD,MAAMI,EAAG,SAASC,CAAY,EAG9BF,EAAO,KAAK,6CAA6C,EAGzD,MAAMH,EAAI,KAAK,EAEfG,EAAO,KAAK,8BAA8B,EAG1C,MAAM,QAAQ,IACZH,EAAI,MAAM,IAAKO,GAAS,CACtB,MAAMxB,EAAc,GAAGyB,EAAkBlB,EAAe,QAAQ,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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2
|
-
import '
|
|
3
|
-
|
|
4
|
-
|
|
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,95 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 redirectStatusStorage = useSessionStorage('VUEPRESS_REDIRECT_LOCALES', {});
|
|
9
|
-
export default defineComponent({
|
|
10
|
-
name: 'RedirectModal',
|
|
11
|
-
setup() {
|
|
12
|
-
const languages = usePreferredLanguages();
|
|
13
|
-
const router = useRouter();
|
|
14
|
-
const routePath = useRoutePath();
|
|
15
|
-
const routeLocale = useRouteLocale();
|
|
16
|
-
const body = ref();
|
|
17
|
-
// lock body scroll when modal is displayed
|
|
18
|
-
const showModal = useScrollLock(body);
|
|
19
|
-
const info = computed(() => {
|
|
20
|
-
if (redirectLocaleEntries.some(([key]) => routeLocale.value === key))
|
|
21
|
-
for (const language of languages.value)
|
|
22
|
-
for (const [localePath, langs] of redirectLocaleEntries)
|
|
23
|
-
if (langs.includes(language)) {
|
|
24
|
-
if (localePath === routeLocale.value)
|
|
25
|
-
return null;
|
|
26
|
-
return {
|
|
27
|
-
lang: language,
|
|
28
|
-
localePath,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
});
|
|
33
|
-
const locale = computed(() => {
|
|
34
|
-
if (info.value) {
|
|
35
|
-
const { lang, localePath } = info.value;
|
|
36
|
-
const locales = [
|
|
37
|
-
redirectLocales[localePath],
|
|
38
|
-
redirectLocales[routeLocale.value],
|
|
39
|
-
];
|
|
40
|
-
return {
|
|
41
|
-
hint: locales.map(({ hint }) => hint.replace('$1', lang)),
|
|
42
|
-
switch: locales
|
|
43
|
-
.map(({ switch: switchText }) => switchText.replace('$1', lang))
|
|
44
|
-
.join(' / '),
|
|
45
|
-
cancel: locales.map(({ cancel }) => cancel).join(' / '),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
});
|
|
50
|
-
const redirect = () => {
|
|
51
|
-
router.replace(routePath.value.replace(routeLocale.value, info.value.localePath));
|
|
52
|
-
};
|
|
53
|
-
watch(routePath, () => {
|
|
54
|
-
showModal.value = false;
|
|
55
|
-
});
|
|
56
|
-
onMounted(async () => {
|
|
57
|
-
body.value = document.body;
|
|
58
|
-
await nextTick();
|
|
59
|
-
if (!redirectStatusStorage.value[routeLocale.value] && info.value) {
|
|
60
|
-
if (switchLocale === 'direct')
|
|
61
|
-
redirect();
|
|
62
|
-
else if (switchLocale === 'modal')
|
|
63
|
-
showModal.value = true;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
onBeforeUnmount(() => {
|
|
67
|
-
showModal.value = false;
|
|
68
|
-
});
|
|
69
|
-
return () => h(TransitionGroup, { name: 'redirect-modal-fade' }, () => showModal.value
|
|
70
|
-
? h('div', { key: 'mask', class: 'redirect-modal-mask' }, h('div', {
|
|
71
|
-
key: 'popup',
|
|
72
|
-
class: 'redirect-modal-wrapper',
|
|
73
|
-
}, [
|
|
74
|
-
h('div', { class: 'redirect-modal-content' }, locale.value?.hint.map((text) => h('p', text))),
|
|
75
|
-
h('button', {
|
|
76
|
-
type: 'button',
|
|
77
|
-
class: 'redirect-modal-action primary',
|
|
78
|
-
onClick: () => {
|
|
79
|
-
redirectStatusStorage.value[routeLocale.value] = true;
|
|
80
|
-
showModal.value = false;
|
|
81
|
-
redirect();
|
|
82
|
-
},
|
|
83
|
-
}, locale.value?.switch),
|
|
84
|
-
h('button', {
|
|
85
|
-
type: 'button',
|
|
86
|
-
class: 'redirect-modal-action',
|
|
87
|
-
onClick: () => {
|
|
88
|
-
redirectStatusStorage.value[routeLocale.value] = true;
|
|
89
|
-
showModal.value = false;
|
|
90
|
-
},
|
|
91
|
-
}, locale.value?.cancel),
|
|
92
|
-
]))
|
|
93
|
-
: null);
|
|
94
|
-
},
|
|
95
|
-
});
|
|
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,OACN,SAAU,EACZ,CACF,EAEA,MAAMC,EAAO,CACX,MAAMC,EAASC,EAAU,EACnBC,EAAYC,EAAa,EACzBC,EAAcC,EAAe,EAC7BC,EAAeC,EAAgBR,EAAM,MAAM,EAE3CS,EAAOC,IAEPC,EAAYC,EAAcH,CAAI,EAC9BI,EAAiBH,EAAI,EAAK,EAE1BI,EAASC,EAAS,IAAM,CAC5B,GAAI,CAACR,EAAa,MAAO,OAAO,KAEhC,KAAM,CAAE,KAAAS,EAAM,WAAAC,CAAW,EAAIV,EAAa,MACpCW,EAAU,CACdlB,EAAM,QAAQiB,CAAU,EACxBjB,EAAM,QAAQK,EAAY,KAAK,CACjC,EAEA,MAAO,CACL,KAAMa,EAAQ,IAAI,CAAC,CAAE,KAAAC,CAAK,IAAMA,EAAK,QAAQ,KAAMH,CAAI,CAAC,EACxD,OAAQE,EACL,IAAI,CAAC,CAAE,OAAQE,CAAW,IAAMA,EAAW,QAAQ,KAAMJ,CAAI,CAAC,EAC9D,KAAK,KAAK,EACb,OAAQE,EAAQ,IAAI,CAAC,CAAE,OAAAG,CAAO,IAAMA,CAAM,EAAE,KAAK,KAAK,EACtD,SAAUH,EAAQ,IAAI,CAAC,CAAE,SAAAI,CAAS,IAAMA,CAAQ,EAAE,KAAK,KAAK,CAC9D,CACF,CAAC,EAEKC,EAAc,IAAY,CAC9BC,EAAqB,MAAMnB,EAAY,KAAK,EAAI,GAC5CQ,EAAe,QACjBY,EAAmB,MAAMpB,EAAY,KAAK,EAAI,IAEhDM,EAAU,MAAQ,EACpB,EAEA,OAAAe,EAAMvB,EAAW,IAAM,CACrBQ,EAAU,MAAQ,EACpB,CAAC,EAEDgB,EAAU,SAAY,CACpBlB,EAAK,MAAQ,SAAS,KAEtB,MAAMmB,EAGJrB,EAAAA,EAAa,OACb,CAACiB,EAAqB,MAAMnB,EAAY,KAAK,GAC7C,CAACoB,EAAmB,MAAMpB,EAAY,KAAK,IAE3CM,EAAU,MAAQ,GAEtB,CAAC,EAEDkB,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"}
|
package/lib/client/config.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
|
|
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 };
|
package/lib/client/config.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
import { defineClientConfig } from
|
|
2
|
-
|
|
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","statusSessionStorage"],"mappings":"6XAAA,MAAMA,EAAc,QAEPC,EAAgB,CAACC,EAAcC,EAAa,MACtDA,EAAaD,EAAK,QAAQF,EAAa,EAAE,EAAIE,GAC3C,QAAQ,sBAAuB,aAAa,EAC5C,QAAQ,sBAAuB,OAAO,ECG9BE,EAAyB,CAAC,CACrC,WAAAC,EACA,OAAAC,EACA,gBAAAC,EACA,cAAeC,EACf,eAAAC,CACF,IAAoC,CAClC,MAAMC,EAAgB,OAAO,QAAQJ,CAAM,EACrCK,EAAYC,EAAsB,EAClCC,EAAQC,EAAS,EACjBC,EAASC,EAAAA,EACTC,EAAcC,EAAe,EAE7BC,EAAeC,EAAS,IAAMH,EAAY,QAAU,GAAG,EAEvDI,EAAuB,IAAY,CACvC,MAAMC,EAASP,EAAO,UAAU,EAC1BQ,EACJf,GACAc,EAAO,KACL,CAAC,CAAE,KAAApB,CAAK,IAAMA,IAASW,EAAM,KAAK,QAAQ,IAAKL,CAAiB,CAClE,EACIA,EACAc,EAAO,KACL,CAAC,CAAE,KAAApB,CAAK,IACNW,EAAM,KAAK,MAAM,GAAG,EAAE,QAAU,GAChCX,IAASW,EAAM,KAAK,QAAQ,aAAc,GAAG,CACjD,GAAG,KAET,IAAIW,EAAmC,KAIvCC,EAAc,UAAWC,KAAQf,EAAU,MACzC,SAAW,CAACgB,EAAYC,CAAK,IAAKlB,EAChC,GAAIkB,EAAM,SAASF,CAAI,EAAG,CACxB,GACEjB,GACAa,EAAO,MAAM,CAAC,CAAE,KAAApB,CAAK,IAAMA,IAASW,EAAM,KAAK,QAAQ,IAAKX,CAAI,CAAC,EAEjE,SAEFsB,EAAoBG,EACpB,MAAMF,CACR,CAGJ,MAAMI,EAAeN,EACjBV,EAAM,SAAS,QAAQ,IAAKU,CAAa,EACzC,KAGJ,GAAIC,EAAmB,CACrB,MAAMM,EAAgBR,EAAO,KAC3B,CAAC,CAAE,KAAApB,CAAK,IAAMW,EAAM,KAAK,QAAQ,IAAKW,CAAiB,IAAMtB,CAC/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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.redirect-modal-fade-enter-active,.redirect-modal-fade-leave-active{transition:opacity .5s}.redirect-modal-fade-enter,.redirect-modal-fade-leave-to{opacity:0}.redirect-modal-mask{position:fixed;inset:0;z-index:var(--redirect-z-index);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(10px)}@media print{.redirect-modal-mask{display:none}}.redirect-modal-wrapper{position:relative;z-index:1500;overflow:hidden;max-width:80vw;padding:1rem 2rem;border-radius:8px;background:var(--redirect-c-bg);box-shadow:0 2px 6px 0 var(--redirect-c-shadow)}.redirect-modal-action{display:block;width:100%;margin:1rem 0;padding:.5rem .75rem;border:none;border-radius:8px;background-color:var(--redirect-c-control);color:inherit;cursor:pointer}.redirect-modal-action:hover{background-color:var(--redirect-c-control-hover)}.redirect-modal-action.primary{background-color:var(--redirect-c-accent-bg);color:var(--redirect-c-accent-text)}.redirect-modal-action.primary:hover{background-color:var(--redirect-c-accent-hover)}/*# sourceMappingURL=redirect-modal.css.map */
|
|
1
|
+
.redirect-modal-fade-enter-active,.redirect-modal-fade-leave-active{transition:opacity .5s}.redirect-modal-fade-enter,.redirect-modal-fade-leave-to{opacity:0}.redirect-modal-mask{position:fixed;inset:0;z-index:var(--redirect-z-index);display:flex;align-items:center;justify-content:center;backdrop-filter:blur(10px)}@media print{.redirect-modal-mask{display:none}}.redirect-modal-wrapper{position:relative;z-index:1500;overflow:hidden;max-width:80vw;padding:1rem 2rem;border-radius:8px;background:var(--redirect-c-bg);box-shadow:0 2px 6px 0 var(--redirect-c-shadow)}.redirect-modal-hint{margin-top:.5rem;color:var(--vp-c-text-mute);font-size:14px;text-align:start}.redirect-modal-hint input[type=checkbox]{position:relative;vertical-align:text-bottom;height:1em;margin-inline-end:18px;cursor:pointer;appearance:none}.redirect-modal-hint input[type=checkbox]::after{content:" ";position:absolute;top:0;display:inline-block;box-sizing:border-box;width:14px;height:14px;padding-inline-start:0;border:1px solid var(--vp-c-border);border-radius:50%;background:var(--vp-c-control);text-align:center;visibility:visible}.redirect-modal-hint input[type=checkbox]:checked::after{content:"";border-color:var(--vp-c-accent-bg);background:var(--vp-c-accent-bg)}.redirect-modal-hint input[type=checkbox]:checked::before{content:"";position:absolute;inset-inline-start:5px;top:2px;z-index:1;width:2px;height:6px;border:solid var(--vp-c-white);border-width:0 2px 2px 0;transform:rotate(45deg)}.redirect-modal-hint label{display:inline-block}.redirect-modal-action{display:block;width:100%;margin:1rem 0;padding:.5rem .75rem;border:none;border-radius:8px;background-color:var(--redirect-c-control);color:inherit;cursor:pointer}.redirect-modal-action:hover{background-color:var(--redirect-c-control-hover)}.redirect-modal-action.primary{background-color:var(--redirect-c-accent-bg);color:var(--redirect-c-accent-text)}.redirect-modal-action.primary:hover{background-color:var(--redirect-c-accent-hover)}/*# sourceMappingURL=redirect-modal.css.map */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sourceRoot":"","sources":["../../../src/client/styles/redirect-modal.scss"],"names":[],"mappings":"AAAA,oEAEE,uBAGF,yDAEE,UAGF,qBACE,eACA,QACA,gCAEA,aACA,mBACA,uBAEA,2BAEA,aAXF,qBAYI,cAIJ,wBACE,kBACA,aAEA,gBAEA,eACA,kBACA,kBAEA,gCACA,gDAGF,uBACE,cAEA,WACA,cACA,qBACA,YACA,kBAEA,2CACA,cAEA,eAEA,6BACE,iDAGF,+BACE,6CACA,oCAEA,qCACE","file":"redirect-modal.css","sourcesContent":[".redirect-modal-fade-enter-active,\n.redirect-modal-fade-leave-active {\n transition: opacity 0.5s;\n}\n\n.redirect-modal-fade-enter,\n.redirect-modal-fade-leave-to {\n opacity: 0;\n}\n\n.redirect-modal-mask {\n position: fixed;\n inset: 0;\n z-index: var(--redirect-z-index);\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n backdrop-filter: blur(10px);\n\n @media print {\n display: none;\n }\n}\n\n.redirect-modal-wrapper {\n position: relative;\n z-index: 1500;\n\n overflow: hidden;\n\n max-width: 80vw;\n padding: 1rem 2rem;\n border-radius: 8px;\n\n background: var(--redirect-c-bg);\n box-shadow: 0 2px 6px 0 var(--redirect-c-shadow);\n}\n\n.redirect-modal-action {\n display: block;\n\n width: 100%;\n margin: 1rem 0;\n padding: 0.5rem 0.75rem;\n border: none;\n border-radius: 8px;\n\n background-color: var(--redirect-c-control);\n color: inherit;\n\n cursor: pointer;\n\n &:hover {\n background-color: var(--redirect-c-control-hover);\n }\n\n &.primary {\n background-color: var(--redirect-c-accent-bg);\n color: var(--redirect-c-accent-text);\n\n &:hover {\n background-color: var(--redirect-c-accent-hover);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../../../src/client/styles/redirect-modal.scss"],"names":[],"mappings":"AAAA,oEAEE,uBAGF,yDAEE,UAGF,qBACE,eACA,QACA,gCAEA,aACA,mBACA,uBAEA,2BAEA,aAXF,qBAYI,cAIJ,wBACE,kBACA,aAEA,gBAEA,eACA,kBACA,kBAEA,gCACA,gDAGF,qBACE,iBACA,4BACA,eACA,iBAEA,0CACE,kBAEA,2BAEA,WACA,uBAEA,eAEA,gBAEA,iDACE,YAEA,kBACA,MAEA,qBAEA,sBACA,WACA,YACA,uBACA,oCACA,kBAEA,+BAEA,kBAEA,mBAIA,yDACE,WACA,mCACA,iCAGF,0DACE,WAEA,kBACA,uBACA,QACA,UAEA,UACA,WACA,+BACA,yBAEA,wBAKN,2BACE,qBAIJ,uBACE,cAEA,WACA,cACA,qBACA,YACA,kBAEA,2CACA,cAEA,eAEA,6BACE,iDAGF,+BACE,6CACA,oCAEA,qCACE","file":"redirect-modal.css","sourcesContent":[".redirect-modal-fade-enter-active,\n.redirect-modal-fade-leave-active {\n transition: opacity 0.5s;\n}\n\n.redirect-modal-fade-enter,\n.redirect-modal-fade-leave-to {\n opacity: 0;\n}\n\n.redirect-modal-mask {\n position: fixed;\n inset: 0;\n z-index: var(--redirect-z-index);\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n backdrop-filter: blur(10px);\n\n @media print {\n display: none;\n }\n}\n\n.redirect-modal-wrapper {\n position: relative;\n z-index: 1500;\n\n overflow: hidden;\n\n max-width: 80vw;\n padding: 1rem 2rem;\n border-radius: 8px;\n\n background: var(--redirect-c-bg);\n box-shadow: 0 2px 6px 0 var(--redirect-c-shadow);\n}\n\n.redirect-modal-hint {\n margin-top: 0.5rem;\n color: var(--vp-c-text-mute);\n font-size: 14px;\n text-align: start;\n\n input[type='checkbox'] {\n position: relative;\n\n vertical-align: text-bottom;\n\n height: 1em;\n margin-inline-end: 18px;\n\n cursor: pointer;\n\n appearance: none;\n\n &::after {\n content: ' ';\n\n position: absolute;\n top: 0;\n\n display: inline-block;\n\n box-sizing: border-box;\n width: 14px;\n height: 14px;\n padding-inline-start: 0;\n border: 1px solid var(--vp-c-border);\n border-radius: 50%;\n\n background: var(--vp-c-control);\n\n text-align: center;\n\n visibility: visible;\n }\n\n &:checked {\n &::after {\n content: '';\n border-color: var(--vp-c-accent-bg);\n background: var(--vp-c-accent-bg);\n }\n\n &::before {\n content: '';\n\n position: absolute;\n inset-inline-start: 5px;\n top: 2px;\n z-index: 1;\n\n width: 2px;\n height: 6px;\n border: solid var(--vp-c-white);\n border-width: 0 2px 2px 0;\n\n transform: rotate(45deg);\n }\n }\n }\n\n label {\n display: inline-block;\n }\n}\n\n.redirect-modal-action {\n display: block;\n\n width: 100%;\n margin: 1rem 0;\n padding: 0.5rem 0.75rem;\n border: none;\n border-radius: 8px;\n\n background-color: var(--redirect-c-control);\n color: inherit;\n\n cursor: pointer;\n\n &:hover {\n background-color: var(--redirect-c-control-hover);\n }\n\n &.primary {\n background-color: var(--redirect-c-accent-bg);\n color: var(--redirect-c-accent-text);\n\n &:hover {\n background-color: var(--redirect-c-accent-hover);\n }\n }\n}\n"]}
|
|
@@ -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"}
|
package/lib/node/index.d.ts
CHANGED
|
@@ -1,2 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 };
|