@vuepress/plugin-redirect 2.0.0-rc.130 → 2.0.0-rc.134
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/dist/{RedirectModal-BG3Cahi_.js → RedirectModal-ClNybd9M.js} +3 -3
- package/dist/{RedirectModal-BG3Cahi_.js.map → RedirectModal-ClNybd9M.js.map} +1 -1
- package/dist/RedirectModal-Dk0TfIg8.d.ts +27 -0
- package/dist/{behavior-C4MffXxI.d.ts → behavior-BFx86lvj.d.ts} +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/client/components/RedirectModal.d.ts +1 -1
- package/dist/client/components/RedirectModal.js +1 -1
- package/dist/client/components/RedirectPopup.d.ts +10 -10
- package/dist/client/components/RedirectPopup.js +1 -1
- package/dist/client/components/RedirectPopup.js.map +1 -1
- package/dist/client/config.d.ts +4 -6
- package/dist/client/config.js +1 -1
- package/dist/client/index.d.ts +12 -19
- package/dist/client/index.js +1 -1
- package/dist/{getRedirectHTML-C9SBJAfB.js → getRedirectHTML-Bb3v1fdn.js} +1 -1
- package/dist/{getRedirectHTML-C9SBJAfB.js.map → getRedirectHTML-Bb3v1fdn.js.map} +1 -1
- package/dist/{locales-CFqGsY9x.d.ts → locales-D7nbWdGO.d.ts} +1 -1
- package/dist/node/index.d.ts +4 -5
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/{setupRedirect-DH0rj-BS.js → setupRedirect-Ca8WTELZ.js} +2 -2
- package/dist/{setupRedirect-DH0rj-BS.js.map → setupRedirect-Ca8WTELZ.js.map} +1 -1
- package/dist/{types-DXUJF0Nm.d.ts → types-C9kDILtX.d.ts} +2 -3
- package/dist/{useRedirect-BA5x0nN6.js → useRedirect-CSm17u8x.js} +2 -2
- package/dist/{useRedirect-BA5x0nN6.js.map → useRedirect-CSm17u8x.js.map} +1 -1
- package/dist/{useRedirectLocation-OmESywdI.js → useRedirectLocation-D83RJLxs.js} +1 -1
- package/dist/{useRedirectLocation-OmESywdI.js.map → useRedirectLocation-D83RJLxs.js.map} +1 -1
- package/package.json +7 -7
- package/dist/RedirectModal-B6mWTqIR.d.ts +0 -27
- /package/dist/{RedirectModal-BG3Cahi_.css → RedirectModal-ClNybd9M.css} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './RedirectModal-
|
|
2
|
-
import{n as e,t}from"./useRedirect-
|
|
3
|
-
//# sourceMappingURL=RedirectModal-
|
|
1
|
+
import './RedirectModal-ClNybd9M.css';
|
|
2
|
+
import{n as e,t}from"./useRedirect-CSm17u8x.js";import{useScrollLock as n,watchImmediate as r}from"@vueuse/core";import{TransitionGroup as i,defineComponent as a,h as o,onMounted as s,ref as c}from"vue";import"@vuepress/helper/transition/fade-in-scale-up.css";var l=a({name:`RedirectModal`,props:t,setup(t){let{shouldRemember:a,showComponent:l,locale:u,persistUserAction:d,redirect:f}=e(t),p=c(),m=n(p);return s(()=>{p.value=document.body,r(l,e=>{m.value=e})}),()=>o(i,{name:`fade-in-scale-up`},()=>l.value?o(`div`,{key:`mask`,class:`redirect-modal-mask`},o(`div`,{key:`popup`,class:`redirect-modal-wrapper`},[o(`div`,{class:`redirect-modal-content`},u.value?.hint.map(e=>o(`p`,e))),o(`div`,{class:`redirect-modal-hint`},[o(`input`,{id:`remember-redirect`,type:`checkbox`,checked:a.value,onChange:()=>{a.value=!a.value}}),o(`label`,{for:`remember-redirect`},u.value?.remember)]),o(`div`,{class:`redirect-modal-actions`},[o(`button`,{type:`button`,class:`redirect-modal-action primary`,onClick:()=>{f()}},u.value?.switch),o(`button`,{type:`button`,class:`redirect-modal-action`,onClick:()=>{d()}},u.value?.cancel)])])):null)}});export{l as t};
|
|
3
|
+
//# sourceMappingURL=RedirectModal-ClNybd9M.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedirectModal-
|
|
1
|
+
{"version":3,"file":"RedirectModal-ClNybd9M.js","names":[],"sources":["../src/client/components/RedirectModal.ts"],"sourcesContent":["import { useScrollLock, watchImmediate } from '@vueuse/core'\nimport type { VNode } from 'vue'\nimport { TransitionGroup, defineComponent, h, onMounted, ref } from 'vue'\n\nimport { useRedirect, propsOptions } from '../composables/index.js'\n\nimport '@vuepress/helper/transition/fade-in-scale-up.css'\nimport '../styles/redirect-modal.scss'\n\nexport default defineComponent({\n name: 'RedirectModal',\n\n props: propsOptions,\n\n setup(props) {\n const {\n shouldRemember,\n showComponent,\n locale,\n persistUserAction,\n redirect,\n } = useRedirect(props)\n\n const body = ref<HTMLElement>()\n // lock body scroll when modal is displayed\n const bodyLock = useScrollLock(body)\n\n onMounted(() => {\n body.value = document.body\n\n // lock scroll while the modal is displayed\n watchImmediate(showComponent, (value) => {\n bodyLock.value = value\n })\n })\n\n return (): VNode | null =>\n h(TransitionGroup, { name: 'fade-in-scale-up' }, () =>\n showComponent.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 checked: 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('div', { class: 'redirect-modal-actions' }, [\n h(\n 'button',\n {\n type: 'button',\n class: 'redirect-modal-action primary',\n onClick: () => {\n redirect()\n },\n },\n locale.value?.switch,\n ),\n h(\n 'button',\n {\n type: 'button',\n class: 'redirect-modal-action',\n onClick: () => {\n persistUserAction()\n },\n },\n locale.value?.cancel,\n ),\n ]),\n ],\n ),\n )\n : null,\n )\n },\n})\n"],"mappings":"oQASA,IAAA,EAAe,EAAgB,CAC7B,KAAM,gBAEN,MAAO,EAEP,MAAM,EAAO,CACX,GAAM,CACJ,iBACA,gBACA,SACA,oBACA,YACE,EAAY,CAAK,EAEf,EAAO,EAAiB,EAExB,EAAW,EAAc,CAAI,EAWnC,OATA,MAAgB,CACd,EAAK,MAAQ,SAAS,KAGtB,EAAe,EAAgB,GAAU,CACvC,EAAS,MAAQ,CACnB,CAAC,CACH,CAAC,MAGC,EAAE,EAAiB,CAAE,KAAM,kBAAmB,MAC5C,EAAc,MACV,EACE,MACA,CAAE,IAAK,OAAQ,MAAO,qBAAsB,EAC5C,EACE,MACA,CACE,IAAK,QACL,MAAO,wBACT,EACA,CACE,EACE,MACA,CAAE,MAAO,wBAAyB,EAClC,EAAO,OAAO,KAAK,IAAK,GAAS,EAAE,IAAK,CAAI,CAAC,CAC/C,EACA,EAAE,MAAO,CAAE,MAAO,qBAAsB,EAAG,CACzC,EAAE,QAAS,CACT,GAAI,oBACJ,KAAM,WACN,QAAS,EAAe,MACxB,aAAgB,CACd,EAAe,MAAQ,CAAC,EAAe,KACzC,CACF,CAAC,EACD,EACE,QACA,CAAE,IAAK,mBAAoB,EAC3B,EAAO,OAAO,QAChB,CACF,CAAC,EACD,EAAE,MAAO,CAAE,MAAO,wBAAyB,EAAG,CAC5C,EACE,SACA,CACE,KAAM,SACN,MAAO,gCACP,YAAe,CACb,EAAS,CACX,CACF,EACA,EAAO,OAAO,MAChB,EACA,EACE,SACA,CACE,KAAM,SACN,MAAO,wBACP,YAAe,CACb,EAAkB,CACpB,CACF,EACA,EAAO,OAAO,MAChB,CACF,CAAC,CACH,CACF,CACF,EACA,IACN,CACJ,CACF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as RedirectBehaviorConfig } from "./behavior-BFx86lvj.js";
|
|
2
|
+
import { t as RedirectPluginLocaleConfig } from "./types-C9kDILtX.js";
|
|
3
|
+
import { VNode } from "vue";
|
|
4
|
+
import "@vuepress/helper/transition/fade-in-scale-up.css";
|
|
5
|
+
//#region src/client/components/RedirectModal.d.ts
|
|
6
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
|
+
readonly config: {
|
|
8
|
+
readonly type: import("vue").PropType<RedirectBehaviorConfig>;
|
|
9
|
+
readonly required: true;
|
|
10
|
+
};
|
|
11
|
+
readonly locales: {
|
|
12
|
+
readonly type: import("vue").PropType<RedirectPluginLocaleConfig>;
|
|
13
|
+
readonly required: true;
|
|
14
|
+
};
|
|
15
|
+
}>, () => VNode | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
16
|
+
readonly config: {
|
|
17
|
+
readonly type: import("vue").PropType<RedirectBehaviorConfig>;
|
|
18
|
+
readonly required: true;
|
|
19
|
+
};
|
|
20
|
+
readonly locales: {
|
|
21
|
+
readonly type: import("vue").PropType<RedirectPluginLocaleConfig>;
|
|
22
|
+
readonly required: true;
|
|
23
|
+
};
|
|
24
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { _default as t };
|
|
27
|
+
//# sourceMappingURL=RedirectModal-Dk0TfIg8.d.ts.map
|
|
@@ -50,4 +50,4 @@ interface RedirectBehaviorConfig extends Required<RedirectBehaviorOptions> {
|
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
52
|
export { RedirectBehaviorOptions as n, RedirectBehaviorConfig as t };
|
|
53
|
-
//# sourceMappingURL=behavior-
|
|
53
|
+
//# sourceMappingURL=behavior-BFx86lvj.d.ts.map
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{t as e}from"../getRedirectHTML-
|
|
2
|
+
import{t as e}from"../getRedirectHTML-Bb3v1fdn.js";import{removeEndingSlash as t,removeLeadingSlash as n}from"@vuepress/helper";import{createCommand as r}from"commander";import{loadUserConfig as i,resolveAppConfig as a,resolveCliAppConfig as o,resolveUserConfigConventionalPath as s,resolveUserConfigPath as c,transformUserConfigToPlugin as l}from"vuepress/cli";import{createBuildApp as u}from"vuepress/core";import{fs as d,logger as f,path as p}from"vuepress/utils";var m=`2.0.0-rc.134`;const h=r(`vp-redirect`);h.summary(`Generate redirect site`).description(`Generate redirect site for current VuePress project`).option(`--hostname <hostname>`,`Hostname to redirect to (E.g.: https://new.example.com/)`,`/`).option(`-c, --config [config]`,`Set path to config file`).option(`--cache [cache]`,`Set the directory of the cache files`).option(`--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`).argument(`<source>`,`Source directory of VuePress project`).argument(`[output]`,`Output folder (default: .vuepress/redirect relative to source folder)`).action(async(r,m,g)=>{process.env.NODE_ENV??=`production`,await d.exists(r)||h.error(`Source directory ${r} does not exist!`);let _=o(r,{}),v=g.config?c(g.config):s(_.source),{userConfig:y}=await i(v),b=a({defaultAppConfig:{cache:g.cache,temp:g.temp},cliAppConfig:_,userConfig:y});if(b==null)return;let x=u(b);x.use(l(y,_.source)),g.cleanTemp===!0&&(f.info(`Cleaning temp...`),await d.remove(x.dir.temp())),g.cleanCache===!0&&(f.info(`Cleaning cache...`),await d.remove(x.dir.cache()));let S=m?p.join(process.cwd(),m):p.join(x.dir.source(),`.vuepress`,`redirect`);await d.emptyDir(S),f.info(`Initializing VuePress and preparing data...`),await x.init(),f.info(`Generating redirect pages...`),await Promise.all(x.pages.map(r=>{let i=`${t(g.hostname)}${x.siteData.base}${n(r.path)}`,a=p.join(S,n(r.path.replace(/\/$/u,`/index.html`)));return d.ensureDir(p.dirname(a)).then(()=>d.writeFile(a,e(i)))}))}),h.version(m),h.showHelpAfterError(`add --help for additional information`),await h.parseAsync();export{};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["pkg.version"],"sources":["../../package.json","../../src/cli/index.ts"],"sourcesContent":["","#!/usr/bin/env node\nimport { removeEndingSlash, removeLeadingSlash } from '@vuepress/helper'\nimport { createCommand } from 'commander'\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'\n\nimport pkg from '../../package.json' with { type: 'json' }\nimport { getRedirectHTML } from '../node/generate/getRedirectHTML.js'\n\ninterface RedirectCommandOptions {\n hostname: string\n config?: string\n cache?: string\n temp?: string\n cleanCache?: boolean\n cleanTemp?: boolean\n}\n\nconst program = createCommand('vp-redirect')\n\nprogram\n .summary('Generate redirect site')\n .description('Generate redirect site for current VuePress project')\n .option(\n '--hostname <hostname>',\n 'Hostname to redirect to (E.g.: https://new.example.com/)',\n '/',\n )\n .option('-c, --config [config]', 'Set path to config file')\n .option('--cache [cache]', 'Set the directory of the cache files')\n .option('--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 .argument('<source>', 'Source directory of VuePress project')\n .argument(\n '[output]',\n 'Output folder (default: .vuepress/redirect relative to source folder)',\n )\n .action(\n async (\n sourceDir: string,\n output: string | undefined,\n commandOptions: RedirectCommandOptions,\n ) => {\n // ensure NODE_ENV is set\n process.env.NODE_ENV ??= 'production'\n\n if (!fs.
|
|
1
|
+
{"version":3,"file":"index.js","names":["pkg.version"],"sources":["../../package.json","../../src/cli/index.ts"],"sourcesContent":["","#!/usr/bin/env node\nimport { removeEndingSlash, removeLeadingSlash } from '@vuepress/helper'\nimport { createCommand } from 'commander'\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'\n\nimport pkg from '../../package.json' with { type: 'json' }\nimport { getRedirectHTML } from '../node/generate/getRedirectHTML.js'\n\ninterface RedirectCommandOptions {\n hostname: string\n config?: string\n cache?: string\n temp?: string\n cleanCache?: boolean\n cleanTemp?: boolean\n}\n\nconst program = createCommand('vp-redirect')\n\nprogram\n .summary('Generate redirect site')\n .description('Generate redirect site for current VuePress project')\n .option(\n '--hostname <hostname>',\n 'Hostname to redirect to (E.g.: https://new.example.com/)',\n '/',\n )\n .option('-c, --config [config]', 'Set path to config file')\n .option('--cache [cache]', 'Set the directory of the cache files')\n .option('--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 .argument('<source>', 'Source directory of VuePress project')\n .argument(\n '[output]',\n 'Output folder (default: .vuepress/redirect relative to source folder)',\n )\n .action(\n async (\n sourceDir: string,\n output: string | undefined,\n commandOptions: RedirectCommandOptions,\n ) => {\n // ensure NODE_ENV is set\n process.env.NODE_ENV ??= 'production'\n\n if (!(await fs.exists(sourceDir)))\n program.error(`Source directory ${sourceDir} does not exist!`)\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 cache: commandOptions.cache,\n temp: commandOptions.temp,\n },\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 = output\n ? path.join(process.cwd(), output)\n : path.join(app.dir.source(), '.vuepress', 'redirect')\n\n // empty output directory\n await fs.emptyDir(outputFolder)\n\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.siteData.base\n }${removeLeadingSlash(page.path)}`\n const destLocation = path.join(\n outputFolder,\n removeLeadingSlash(page.path.replace(/\\/$/u, '/index.html')),\n )\n\n return fs\n .ensureDir(path.dirname(destLocation))\n .then(() =>\n fs.writeFile(destLocation, getRedirectHTML(redirectUrl)),\n )\n }),\n )\n },\n )\n\nprogram.version(pkg.version)\nprogram.showHelpAfterError('add --help for additional information')\n\nawait program.parseAsync()\n"],"mappings":";weC0BA,MAAM,EAAU,EAAc,aAAa,EAE3C,EACG,QAAQ,wBAAwB,CAAC,CACjC,YAAY,qDAAqD,CAAC,CAClE,OACC,wBACA,2DACA,GACF,CAAC,CACA,OAAO,wBAAyB,yBAAyB,CAAC,CAC1D,OAAO,kBAAmB,sCAAsC,CAAC,CACjE,OAAO,gBAAiB,0CAA0C,CAAC,CACnE,OAAO,gBAAiB,yCAAyC,CAAC,CAClE,OAAO,eAAgB,6CAA6C,CAAC,CACrE,SAAS,WAAY,sCAAsC,CAAC,CAC5D,SACC,WACA,uEACF,CAAC,CACA,OACC,MACE,EACA,EACA,IACG,CAEH,QAAQ,IAAI,WAAa,aAEnB,MAAM,EAAG,OAAO,CAAS,GAC7B,EAAQ,MAAM,oBAAoB,EAAU,iBAAiB,EAG/D,IAAM,EAAe,EAAoB,EAA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_default } from "../../RedirectModal-
|
|
1
|
+
import { t as _default } from "../../RedirectModal-Dk0TfIg8.js";
|
|
2
2
|
export { _default as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../../RedirectModal-
|
|
1
|
+
import{t as e}from"../../RedirectModal-ClNybd9M.js";export{e as default};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { t as RedirectBehaviorConfig } from "../../behavior-
|
|
2
|
-
import { t as RedirectPluginLocaleConfig } from "../../types-
|
|
3
|
-
import * as _$vue from "vue";
|
|
1
|
+
import { t as RedirectBehaviorConfig } from "../../behavior-BFx86lvj.js";
|
|
2
|
+
import { t as RedirectPluginLocaleConfig } from "../../types-C9kDILtX.js";
|
|
4
3
|
import { VNode } from "vue";
|
|
4
|
+
import "@vuepress/helper/transition/fade-in-scale-up.css";
|
|
5
5
|
//#region src/client/components/RedirectPopup.d.ts
|
|
6
|
-
declare const _default:
|
|
6
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
7
|
readonly config: {
|
|
8
|
-
readonly type:
|
|
8
|
+
readonly type: import("vue").PropType<RedirectBehaviorConfig>;
|
|
9
9
|
readonly required: true;
|
|
10
10
|
};
|
|
11
11
|
readonly locales: {
|
|
12
|
-
readonly type:
|
|
12
|
+
readonly type: import("vue").PropType<RedirectPluginLocaleConfig>;
|
|
13
13
|
readonly required: true;
|
|
14
14
|
};
|
|
15
|
-
}>, () => VNode | null, {}, {}, {},
|
|
15
|
+
}>, () => VNode | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
16
16
|
readonly config: {
|
|
17
|
-
readonly type:
|
|
17
|
+
readonly type: import("vue").PropType<RedirectBehaviorConfig>;
|
|
18
18
|
readonly required: true;
|
|
19
19
|
};
|
|
20
20
|
readonly locales: {
|
|
21
|
-
readonly type:
|
|
21
|
+
readonly type: import("vue").PropType<RedirectPluginLocaleConfig>;
|
|
22
22
|
readonly required: true;
|
|
23
23
|
};
|
|
24
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string,
|
|
24
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
25
25
|
//#endregion
|
|
26
26
|
export { _default as default };
|
|
27
27
|
//# sourceMappingURL=RedirectPopup.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './RedirectPopup.css';
|
|
2
|
-
import{n as e,t}from"../../useRedirect-
|
|
2
|
+
import{n as e,t}from"../../useRedirect-CSm17u8x.js";import{TransitionGroup as n,defineComponent as r,h as i,ref as a,watch as o}from"vue";import"@vuepress/helper/transition/fade-in-scale-up.css";const s=5e3,c=2*Math.PI*12;var l=r({name:`RedirectPopup`,props:t,setup(t){let{shouldRemember:r,showComponent:l,locale:u,persistUserAction:d,redirect:f}=e(t),p=a(0),m,h,g=()=>{clearTimeout(m),clearInterval(h)},_=()=>{p.value=0;let e=Date.now();h=setInterval(()=>{let t=Date.now()-e;p.value=Math.min(t/s,1)},50),m=setTimeout(()=>{g(),p.value=1,l.value=!1},s)};return o(l,e=>{e?_():g()}),()=>i(n,{name:`fade-in-scale-up`},()=>l.value?i(`div`,{key:`popup`,class:`redirect-popup`},[i(`button`,{type:`button`,class:`redirect-close-button`,"aria-label":u.value?.cancel,title:u.value?.cancel,onClick:()=>{g(),d()}},i(`svg`,{class:`redirect-close-icon`,viewBox:`0 0 24 24`,xmlns:`http://www.w3.org/2000/svg`},[i(`circle`,{class:`redirect-progress-ring`,cx:`12`,cy:`12`,r:`12`,fill:`none`,"stroke-dasharray":c.toString(),"stroke-dashoffset":(c*p.value).toString()}),i(`path`,{d:`M8 8l8 8M16 8l-8 8`,stroke:`currentColor`,fill:`none`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`1.5`})])),i(`button`,{type:`button`,class:`redirect-popup-redirect-button`,onClick:()=>{f()}},u.value?.switch),i(`div`,{class:`redirect-popup-hint`},[i(`input`,{id:`remember-redirect`,type:`checkbox`,checked:r.value,onChange:()=>{r.value=!r.value}}),i(`label`,{for:`remember-redirect`},u.value?.remember)])]):null)}});export{l as default};
|
|
3
3
|
//# sourceMappingURL=RedirectPopup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedirectPopup.js","names":[],"sources":["../../../src/client/components/RedirectPopup.ts"],"sourcesContent":["import type { VNode } from 'vue'\nimport { TransitionGroup, defineComponent, h, ref, watch } from 'vue'\n\nimport { useRedirect, propsOptions } from '../composables/index.js'\n\nimport '@vuepress/helper/transition/fade-in-scale-up.css'\nimport '../styles/redirect-popup.scss'\n\nconst AUTO_CLOSE_DELAY = 5000\nconst RADIUS = 12\nconst CIRCUMFERENCE = 2 * Math.PI * RADIUS\n\nexport default defineComponent({\n name: 'RedirectPopup',\n\n props: propsOptions,\n\n setup(props) {\n const {\n shouldRemember,\n showComponent,\n locale,\n persistUserAction,\n redirect,\n } = useRedirect(props)\n\n const autoCloseProgress = ref(0)\n\n // oxlint-disable-next-line unicorn/no-useless-undefined\n let autoCloseTimer: ReturnType<typeof setTimeout> | undefined = undefined\n // oxlint-disable-next-line unicorn/no-useless-undefined\n let progressInterval: ReturnType<typeof setInterval> | undefined = undefined\n\n const clearTimers = (): void => {\n clearTimeout(autoCloseTimer)\n clearInterval(progressInterval)\n }\n\n const startAutoClose = (): void => {\n autoCloseProgress.value = 0\n const startTime = Date.now()\n\n progressInterval = setInterval(() => {\n const elapsed = Date.now() - startTime\n autoCloseProgress.value = Math.min(elapsed / AUTO_CLOSE_DELAY, 1)\n }, 50)\n\n autoCloseTimer = setTimeout(() => {\n clearTimers()\n autoCloseProgress.value = 1\n showComponent.value = false\n }, AUTO_CLOSE_DELAY)\n }\n\n watch(showComponent, (value) => {\n if (value) startAutoClose()\n else clearTimers()\n })\n\n return (): VNode | null =>\n h(TransitionGroup, { name: 'fade-in-scale-up' }, () =>\n showComponent.value\n ? h('div', { key: 'popup', class: 'redirect-popup' }, [\n h(\n 'button',\n {\n 'type': 'button',\n 'class': 'redirect-close-button',\n 'aria-label': locale.value?.cancel,\n 'title': locale.value?.cancel,\n 'onClick': () => {\n clearTimers()\n persistUserAction()\n },\n },\n h(\n 'svg',\n {\n class: 'redirect-close-icon',\n viewBox: '0 0 24 24',\n xmlns: 'http://www.w3.org/2000/svg',\n },\n [\n h('circle', {\n 'class': 'redirect-progress-ring',\n 'cx': '12',\n 'cy': '12',\n 'r': RADIUS.toString(),\n 'fill': 'none',\n 'stroke-dasharray': CIRCUMFERENCE.toString(),\n 'stroke-dashoffset': (\n CIRCUMFERENCE * autoCloseProgress.value\n ).toString(),\n }),\n h('path', {\n 'd': 'M8 8l8 8M16 8l-8 8',\n 'stroke': 'currentColor',\n 'fill': 'none',\n 'stroke-linecap': 'round',\n 'stroke-linejoin': 'round',\n 'stroke-width': '1.5',\n }),\n ],\n ),\n ),\n h(\n 'button',\n {\n type: 'button',\n class: 'redirect-popup-redirect-button',\n onClick: () => {\n redirect()\n },\n },\n locale.value?.switch,\n ),\n h('div', { class: 'redirect-popup-hint' }, [\n h('input', {\n id: 'remember-redirect',\n type: 'checkbox',\n checked: 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 ])\n : null,\n )\n },\n})\n"],"mappings":"mMAQA,MAAM,EAAmB,IAEnB,EAAgB,EAAI,KAAK,GAAK,GAEpC,IAAA,EAAe,EAAgB,CAC7B,KAAM,gBAEN,MAAO,EAEP,MAAM,EAAO,CACX,GAAM,CACJ,iBACA,gBACA,SACA,oBACA,YACE,EAAY,CAAK,EAEf,EAAoB,EAAI,CAAC,EAG3B,EAEA,EAEE,MAA0B,CAC9B,aAAa,CAAc,EAC3B,cAAc,CAAgB,CAChC,EAEM,MAA6B,CACjC,EAAkB,MAAQ,EAC1B,IAAM,EAAY,KAAK,IAAI,EAE3B,EAAmB,gBAAkB,CACnC,IAAM,EAAU,KAAK,IAAI,EAAI,EAC7B,EAAkB,MAAQ,KAAK,IAAI,EAAU,EAAkB,CAAC,CAClE,EAAG,EAAE,EAEL,EAAiB,eAAiB,CAChC,EAAY,EACZ,EAAkB,MAAQ,EAC1B,EAAc,MAAQ,EACxB,EAAG,CAAgB,CACrB,EAOA,OALA,EAAM,EAAgB,GAAU,CAC1B,EAAO,EAAe,EACrB,EAAY,CACnB,CAAC,MAGC,EAAE,EAAiB,CAAE,KAAM,kBAAmB,MAC5C,EAAc,MACV,EAAE,MAAO,CAAE,IAAK,QAAS,MAAO,gBAAiB,EAAG,CAClD,EACE,SACA,CACE,KAAQ,SACR,MAAS,wBACT,aAAc,EAAO,OAAO,OAC5B,MAAS,EAAO,OAAO,OACvB,YAAiB,CACf,EAAY,EACZ,EAAkB,CACpB,CACF,EACA,EACE,MACA,CACE,MAAO,sBACP,QAAS,YACT,MAAO,4BACT,EACA,CACE,EAAE,SAAU,CACV,MAAS,yBACT,GAAM,KACN,GAAM,KACN,EAAK,KACL,KAAQ,OACR,mBAAoB,EAAc,SAAS,EAC3C,qBACE,EAAgB,EAAkB,
|
|
1
|
+
{"version":3,"file":"RedirectPopup.js","names":[],"sources":["../../../src/client/components/RedirectPopup.ts"],"sourcesContent":["import type { VNode } from 'vue'\nimport { TransitionGroup, defineComponent, h, ref, watch } from 'vue'\n\nimport { useRedirect, propsOptions } from '../composables/index.js'\n\nimport '@vuepress/helper/transition/fade-in-scale-up.css'\nimport '../styles/redirect-popup.scss'\n\nconst AUTO_CLOSE_DELAY = 5000\nconst RADIUS = 12\nconst CIRCUMFERENCE = 2 * Math.PI * RADIUS\n\nexport default defineComponent({\n name: 'RedirectPopup',\n\n props: propsOptions,\n\n setup(props) {\n const {\n shouldRemember,\n showComponent,\n locale,\n persistUserAction,\n redirect,\n } = useRedirect(props)\n\n const autoCloseProgress = ref(0)\n\n // oxlint-disable-next-line unicorn/no-useless-undefined\n let autoCloseTimer: ReturnType<typeof setTimeout> | undefined = undefined\n // oxlint-disable-next-line unicorn/no-useless-undefined\n let progressInterval: ReturnType<typeof setInterval> | undefined = undefined\n\n const clearTimers = (): void => {\n clearTimeout(autoCloseTimer)\n clearInterval(progressInterval)\n }\n\n const startAutoClose = (): void => {\n autoCloseProgress.value = 0\n const startTime = Date.now()\n\n progressInterval = setInterval(() => {\n const elapsed = Date.now() - startTime\n autoCloseProgress.value = Math.min(elapsed / AUTO_CLOSE_DELAY, 1)\n }, 50)\n\n autoCloseTimer = setTimeout(() => {\n clearTimers()\n autoCloseProgress.value = 1\n showComponent.value = false\n }, AUTO_CLOSE_DELAY)\n }\n\n watch(showComponent, (value) => {\n if (value) startAutoClose()\n else clearTimers()\n })\n\n return (): VNode | null =>\n h(TransitionGroup, { name: 'fade-in-scale-up' }, () =>\n showComponent.value\n ? h('div', { key: 'popup', class: 'redirect-popup' }, [\n h(\n 'button',\n {\n 'type': 'button',\n 'class': 'redirect-close-button',\n 'aria-label': locale.value?.cancel,\n 'title': locale.value?.cancel,\n 'onClick': () => {\n clearTimers()\n persistUserAction()\n },\n },\n h(\n 'svg',\n {\n class: 'redirect-close-icon',\n viewBox: '0 0 24 24',\n xmlns: 'http://www.w3.org/2000/svg',\n },\n [\n h('circle', {\n 'class': 'redirect-progress-ring',\n 'cx': '12',\n 'cy': '12',\n 'r': RADIUS.toString(),\n 'fill': 'none',\n 'stroke-dasharray': CIRCUMFERENCE.toString(),\n 'stroke-dashoffset': (\n CIRCUMFERENCE * autoCloseProgress.value\n ).toString(),\n }),\n h('path', {\n 'd': 'M8 8l8 8M16 8l-8 8',\n 'stroke': 'currentColor',\n 'fill': 'none',\n 'stroke-linecap': 'round',\n 'stroke-linejoin': 'round',\n 'stroke-width': '1.5',\n }),\n ],\n ),\n ),\n h(\n 'button',\n {\n type: 'button',\n class: 'redirect-popup-redirect-button',\n onClick: () => {\n redirect()\n },\n },\n locale.value?.switch,\n ),\n h('div', { class: 'redirect-popup-hint' }, [\n h('input', {\n id: 'remember-redirect',\n type: 'checkbox',\n checked: 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 ])\n : null,\n )\n },\n})\n"],"mappings":"mMAQA,MAAM,EAAmB,IAEnB,EAAgB,EAAI,KAAK,GAAK,GAEpC,IAAA,EAAe,EAAgB,CAC7B,KAAM,gBAEN,MAAO,EAEP,MAAM,EAAO,CACX,GAAM,CACJ,iBACA,gBACA,SACA,oBACA,YACE,EAAY,CAAK,EAEf,EAAoB,EAAI,CAAC,EAG3B,EAEA,EAEE,MAA0B,CAC9B,aAAa,CAAc,EAC3B,cAAc,CAAgB,CAChC,EAEM,MAA6B,CACjC,EAAkB,MAAQ,EAC1B,IAAM,EAAY,KAAK,IAAI,EAE3B,EAAmB,gBAAkB,CACnC,IAAM,EAAU,KAAK,IAAI,EAAI,EAC7B,EAAkB,MAAQ,KAAK,IAAI,EAAU,EAAkB,CAAC,CAClE,EAAG,EAAE,EAEL,EAAiB,eAAiB,CAChC,EAAY,EACZ,EAAkB,MAAQ,EAC1B,EAAc,MAAQ,EACxB,EAAG,CAAgB,CACrB,EAOA,OALA,EAAM,EAAgB,GAAU,CAC1B,EAAO,EAAe,EACrB,EAAY,CACnB,CAAC,MAGC,EAAE,EAAiB,CAAE,KAAM,kBAAmB,MAC5C,EAAc,MACV,EAAE,MAAO,CAAE,IAAK,QAAS,MAAO,gBAAiB,EAAG,CAClD,EACE,SACA,CACE,KAAQ,SACR,MAAS,wBACT,aAAc,EAAO,OAAO,OAC5B,MAAS,EAAO,OAAO,OACvB,YAAiB,CACf,EAAY,EACZ,EAAkB,CACpB,CACF,EACA,EACE,MACA,CACE,MAAO,sBACP,QAAS,YACT,MAAO,4BACT,EACA,CACE,EAAE,SAAU,CACV,MAAS,yBACT,GAAM,KACN,GAAM,KACN,EAAK,KACL,KAAQ,OACR,mBAAoB,EAAc,SAAS,EAC3C,qBACE,EAAgB,EAAkB,MAAA,CAClC,SAAS,CACb,CAAC,EACD,EAAE,OAAQ,CACR,EAAK,qBACL,OAAU,eACV,KAAQ,OACR,iBAAkB,QAClB,kBAAmB,QACnB,eAAgB,KAClB,CAAC,CACH,CACF,CACF,EACA,EACE,SACA,CACE,KAAM,SACN,MAAO,iCACP,YAAe,CACb,EAAS,CACX,CACF,EACA,EAAO,OAAO,MAChB,EACA,EAAE,MAAO,CAAE,MAAO,qBAAsB,EAAG,CACzC,EAAE,QAAS,CACT,GAAI,oBACJ,KAAM,WACN,QAAS,EAAe,MACxB,aAAgB,CACd,EAAe,MAAQ,CAAC,EAAe,KACzC,CACF,CAAC,EACD,EACE,QACA,CAAE,IAAK,mBAAoB,EAC3B,EAAO,OAAO,QAChB,CACF,CAAC,CACH,CAAC,EACD,IACN,CACJ,CACF,CAAC"}
|
package/dist/client/config.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { t as RedirectBehaviorConfig } from "../behavior-
|
|
2
|
-
import * as _$vuepress_client0 from "vuepress/client";
|
|
3
|
-
|
|
1
|
+
import { t as RedirectBehaviorConfig } from "../behavior-BFx86lvj.js";
|
|
4
2
|
//#region src/client/config.d.ts
|
|
5
|
-
declare const config: RedirectBehaviorConfig;
|
|
6
|
-
declare const _default:
|
|
3
|
+
export declare const config: RedirectBehaviorConfig;
|
|
4
|
+
declare const _default: import("vuepress/client").ClientConfig;
|
|
7
5
|
//#endregion
|
|
8
|
-
export {
|
|
6
|
+
export { _default as default };
|
|
9
7
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/client/config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import './config.css';
|
|
2
|
-
import{n as e,t}from"../setupRedirect-
|
|
2
|
+
import{n as e,t}from"../setupRedirect-Ca8WTELZ.js";import{h as n}from"vue";import{defineClientConfig as r}from"vuepress/client";import i from"@vuepress/plugin-redirect/component";const a=__REDIRECT_CONFIG__;var o=r({setup(){__REDIRECT_DIRECT__&&t(a),__VUEPRESS_DEV__&&e(a)},...__REDIRECT_COMPONENT__?{rootComponents:[()=>n(i,{config:a,locales:__REDIRECT_LOCALES__})]}:{}});export{a as config,o as default};
|
|
3
3
|
//# sourceMappingURL=config.js.map
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import { t as RedirectBehaviorConfig } from "../behavior-
|
|
2
|
-
import { t as RedirectPluginLocaleConfig } from "../types-
|
|
3
|
-
import { t as _default } from "../RedirectModal-
|
|
1
|
+
import { t as RedirectBehaviorConfig } from "../behavior-BFx86lvj.js";
|
|
2
|
+
import { t as RedirectPluginLocaleConfig } from "../types-C9kDILtX.js";
|
|
3
|
+
import { t as _default } from "../RedirectModal-Dk0TfIg8.js";
|
|
4
4
|
import { ComputedRef, ExtractPropTypes, PropType, Ref } from "vue";
|
|
5
|
-
|
|
6
5
|
//#region src/client/composables/setupDevServerRedirect.d.ts
|
|
7
|
-
declare const setupDevServerRedirect: ({
|
|
8
|
-
autoLocale,
|
|
9
|
-
config,
|
|
10
|
-
defaultBehavior,
|
|
11
|
-
defaultLocale: defaultLocalePath,
|
|
12
|
-
localeFallback
|
|
13
|
-
}: RedirectBehaviorConfig) => void;
|
|
6
|
+
export declare const setupDevServerRedirect: ({ autoLocale, config, defaultBehavior, defaultLocale: defaultLocalePath, localeFallback }: RedirectBehaviorConfig) => void;
|
|
14
7
|
//#endregion
|
|
15
8
|
//#region src/client/composables/setupRedirect.d.ts
|
|
16
|
-
interface LocaleInfo {
|
|
9
|
+
export interface LocaleInfo {
|
|
17
10
|
lang: string;
|
|
18
11
|
localePath: string;
|
|
19
12
|
}
|
|
20
|
-
declare const setupRedirect: (behaviorConfig: RedirectBehaviorConfig) => void;
|
|
13
|
+
export declare const setupRedirect: (behaviorConfig: RedirectBehaviorConfig) => void;
|
|
21
14
|
//#endregion
|
|
22
15
|
//#region src/client/composables/useRedirect.d.ts
|
|
23
|
-
declare const propsOptions: {
|
|
16
|
+
export declare const propsOptions: {
|
|
24
17
|
readonly config: {
|
|
25
18
|
readonly type: PropType<RedirectBehaviorConfig>;
|
|
26
19
|
readonly required: true;
|
|
@@ -31,7 +24,7 @@ declare const propsOptions: {
|
|
|
31
24
|
};
|
|
32
25
|
};
|
|
33
26
|
type Props = ExtractPropTypes<typeof propsOptions>;
|
|
34
|
-
interface Redirect {
|
|
27
|
+
export interface Redirect {
|
|
35
28
|
showComponent: Ref<boolean>;
|
|
36
29
|
shouldRemember: Ref<boolean>;
|
|
37
30
|
locale: ComputedRef<{
|
|
@@ -43,14 +36,14 @@ interface Redirect {
|
|
|
43
36
|
persistUserAction: () => void;
|
|
44
37
|
redirect: () => void;
|
|
45
38
|
}
|
|
46
|
-
declare const useRedirect: (props: Props) => Redirect;
|
|
39
|
+
export declare const useRedirect: (props: Props) => Redirect;
|
|
47
40
|
//#endregion
|
|
48
41
|
//#region src/client/composables/useRedirectLocation.d.ts
|
|
49
|
-
interface RedirectLocation {
|
|
42
|
+
export interface RedirectLocation {
|
|
50
43
|
lang: string;
|
|
51
44
|
localePath: string;
|
|
52
45
|
}
|
|
53
|
-
declare const useRedirectLocation: (behaviorConfig: RedirectBehaviorConfig) => ComputedRef<RedirectLocation | null>;
|
|
46
|
+
export declare const useRedirectLocation: (behaviorConfig: RedirectBehaviorConfig) => ComputedRef<RedirectLocation | null>;
|
|
54
47
|
//#endregion
|
|
55
|
-
export {
|
|
48
|
+
export { _default as RedirectModal };
|
|
56
49
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"../setupRedirect-
|
|
1
|
+
import{n as e,t}from"../setupRedirect-Ca8WTELZ.js";import{t as n}from"../useRedirectLocation-D83RJLxs.js";import{n as r,t as i}from"../useRedirect-CSm17u8x.js";import{t as a}from"../RedirectModal-ClNybd9M.js";export{a as RedirectModal,i as propsOptions,e as setupDevServerRedirect,t as setupRedirect,r as useRedirect,n as useRedirectLocation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRedirectHTML-
|
|
1
|
+
{"version":3,"file":"getRedirectHTML-Bb3v1fdn.js","names":[],"sources":["../src/node/generate/getRedirectHTML.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.slice(1);\n window.location.replace(\\`${redirectUrl}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`);\n </script>\n</head>\n<body>\n <p>Redirecting...</p>\n</body>\n</html>\n`\n"],"mappings":"AAAA,MAAa,EAAmB,GAAgC;;;;;+CAKjB,EAAY;gCAC3B,EAAY;;;;gCAIZ,EAAY"}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { n as RedirectBehaviorOptions } from "../behavior-
|
|
2
|
-
import { t as RedirectPluginLocaleData } from "../locales-
|
|
1
|
+
import { n as RedirectBehaviorOptions } from "../behavior-BFx86lvj.js";
|
|
2
|
+
import { t as RedirectPluginLocaleData } from "../locales-D7nbWdGO.js";
|
|
3
3
|
import { App, LocaleConfig, PluginFunction } from "vuepress/core";
|
|
4
4
|
import { PageFrontmatter } from "vuepress";
|
|
5
|
-
|
|
6
5
|
//#region src/node/types/frontmatter.d.ts
|
|
7
6
|
interface RedirectPluginFrontmatter extends PageFrontmatter {
|
|
8
7
|
redirectFrom?: string[] | string;
|
|
@@ -40,7 +39,7 @@ interface RedirectPluginOptions extends RedirectBehaviorOptions {
|
|
|
40
39
|
}
|
|
41
40
|
//#endregion
|
|
42
41
|
//#region src/node/redirectPlugin.d.ts
|
|
43
|
-
declare const redirectPlugin: (options?: RedirectPluginOptions) => PluginFunction;
|
|
42
|
+
export declare const redirectPlugin: (options?: RedirectPluginOptions) => PluginFunction;
|
|
44
43
|
//#endregion
|
|
45
|
-
export { RedirectPluginFrontmatter, RedirectPluginOptions
|
|
44
|
+
export type { RedirectPluginFrontmatter, RedirectPluginOptions };
|
|
46
45
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"../getRedirectHTML-
|
|
1
|
+
import{t as e}from"../getRedirectHTML-Bb3v1fdn.js";import{Logger as t,addViteSsrNoExternal as n,deepAssign as r,entries as i,fromEntries as a,getFullLocaleConfig as o,getModulePath as s,isArray as c,isFunction as l,isLinkAbsolute as u,isLinkHttp as d,isPlainObject as f,keys as p,normalizePath as m,removeEndingSlash as h,removeLeadingSlash as g}from"@vuepress/helper";import{createPage as _}from"vuepress/core";import{colors as v,fs as y,getDirname as b,path as x}from"vuepress/utils";const S=async e=>{e.pages.every(({path:e})=>e!==`/`)&&e.pages.push(await _(e,{path:`/`,frontmatter:{title:`Home`},content:`Redirecting to the correct locale...
|
|
2
2
|
`}))},C=`@vuepress/plugin-redirect`,w=new t(C),T=({config:e,defaultBehavior:t,defaultLocale:n,localeFallback:r},i,a)=>`<!doctype html>
|
|
3
3
|
<html lang="en">
|
|
4
4
|
<head>
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["logger","logger","logger"],"sources":["../../src/node/ensureRootHomePage.ts","../../src/node/logger.ts","../../src/node/generate/getLocaleRedirectHTML.ts","../../src/node/generate/generateAutoLocaleRedirectFiles.ts","../../src/node/generate/generateRedirectFiles.ts","../../src/node/getRedirectLocaleConfig.ts","../../src/node/getRedirectMap.ts","../../src/node/handleRedirectTo.ts","../../src/node/locales.ts","../../src/node/redirectPlugin.ts"],"sourcesContent":["import type { App } from 'vuepress/core'\nimport { createPage } from 'vuepress/core'\n\nexport const ensureRootHomePage = async (app: App): Promise<void> => {\n if (\n // root homepage not exists\n app.pages.every(({ path }) => path !== '/')\n ) {\n app.pages.push(\n await createPage(app, {\n path: '/',\n frontmatter: { title: 'Home' },\n // set markdown content\n content: `\\\nRedirecting to the correct locale...\n`,\n }),\n )\n }\n}\n","import { Logger } from '@vuepress/helper'\n\nexport const PLUGIN_NAME = '@vuepress/plugin-redirect'\n\nexport const logger = new Logger(PLUGIN_NAME)\n","import { removeEndingSlash } from '@vuepress/helper'\n\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\n\nexport const getLocaleRedirectHTML = (\n {\n config,\n defaultBehavior,\n defaultLocale,\n localeFallback,\n }: RedirectBehaviorConfig,\n availableLocales: string[],\n base: string,\n): string => `<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"robots\" content=\"noindex\">\n <title>Redirecting...</title>\n <script>\n const { hash, origin, pathname } = window.location;\n const routePath = pathname.slice(${base.length});\n const { languages } = window.navigator;\n const anchor = hash.slice(1);\n\n const config = ${JSON.stringify(config)};\n const availableLocales = ${JSON.stringify(availableLocales)};\n const defaultLocale = ${\n availableLocales.includes(defaultLocale)\n ? JSON.stringify(defaultLocale)\n : 'availableLocales.pop()'\n };\n const defaultBehavior = ${JSON.stringify(defaultBehavior)}\n\n let matchedLocalePath = null;\n\n // get matched locale\n findLanguage:\n for (const lang of languages)\n for (const [localePath, langs] of Object.entries(config))\n if (langs.includes(lang)) {\n${\n localeFallback\n ? `\\\n if (!availableLocales.includes(localePath))\n continue;\n`\n : ``\n}\\\n matchedLocalePath = localePath;\n break findLanguage;\n }\n\n // default link\n const defaultLink = defaultLocale? \\`\\${origin}${removeEndingSlash(\n base,\n )}\\${defaultLocale}\\${routePath}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`: null;\n\n // a locale matches\n if (matchedLocalePath) {\n const localeLink = \\`\\${origin}${removeEndingSlash(\n base,\n )}\\${matchedLocalePath}\\${routePath}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`;\n\n if (availableLocales.includes(matchedLocalePath)) {\n location.href = localeLink;\n }\n // the page does not exist\n else {\n // locale homepage\n if (defaultBehavior === \"homepage\") {\n location.href = \\`\\${origin}${removeEndingSlash(\n base,\n )}\\${matchedLocalePath}\\`;\n }\n // default locale page\n else if (defaultBehavior === \"defaultLocale\" && defaultLink) {\n location.href = defaultLink;\n }\n // as is to get a 404 page of that locale\n else {\n location.href = localeLink;\n }\n }\n }\n // we have a default page\n else if (defaultLink) {\n location.href = defaultLink;\n }\n else {\n location.href = \\`\\${origin}${removeEndingSlash(base)}/404.html\\`;\n }\n </script>\n</head>\n<body>\n <p>Redirecting...</p>\n</body>\n</html>\n`\n","import { entries, removeLeadingSlash } from '@vuepress/helper'\nimport type { App } from 'vuepress/core'\nimport { fs, path } from 'vuepress/utils'\n\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\nimport { logger } from '../logger.js'\nimport { getLocaleRedirectHTML } from './getLocaleRedirectHTML.js'\n\nexport const generateAutoLocaleRedirectFiles = async (\n app: App,\n localeOptions: RedirectBehaviorConfig,\n): Promise<void> => {\n const rootPaths = new Set(\n app.pages\n .filter(({ pathLocale }) => pathLocale === '/')\n .map(({ path: pagePath }) => pagePath),\n )\n const localeRedirectMap: Record<string, string[]> = {}\n\n app.pages\n .filter(({ pathLocale }) => pathLocale !== '/')\n .forEach(({ path: pagePath, pathLocale }) => {\n const rootPath = pagePath\n .replace(pathLocale, '/')\n .replace(/\\/$/u, '/index.html')\n\n if (!rootPaths.has(rootPath))\n (localeRedirectMap[rootPath] ??= []).push(pathLocale)\n })\n\n const { succeed } = logger.load('Generating locale redirect files')\n\n await Promise.all(\n entries(localeRedirectMap).map(async ([rootPath, availableLocales]) => {\n const filePath = app.dir.dest(removeLeadingSlash(rootPath))\n\n if (!fs.existsSync(filePath)) {\n await fs.ensureDir(path.dirname(filePath))\n await fs.writeFile(\n filePath,\n getLocaleRedirectHTML(\n localeOptions,\n availableLocales,\n app.siteData.base,\n ),\n )\n }\n }),\n )\n\n succeed()\n}\n","import {\n entries,\n isLinkAbsolute,\n isLinkHttp,\n removeEndingSlash,\n removeLeadingSlash,\n} from '@vuepress/helper'\nimport type { App } from 'vuepress/core'\nimport { fs, path } from 'vuepress/utils'\n\nimport { logger } from '../logger.js'\nimport { getRedirectHTML } from './getRedirectHTML.js'\n\nexport const generateRedirectFiles = async (\n app: App,\n config: Record<string, string>,\n hostname = '',\n): Promise<void> => {\n const resolvedHostname = hostname\n ? removeEndingSlash(isLinkHttp(hostname) ? hostname : `https://${hostname}`)\n : ''\n\n const { succeed } = logger.load('Generating redirect files')\n\n await Promise.all(\n entries(config).map(async ([from, to]) => {\n const filePath = app.dir.dest(removeLeadingSlash(from))\n\n if (!fs.existsSync(filePath)) {\n const redirectUrl = isLinkAbsolute(to)\n ? `${resolvedHostname}${app.siteData.base}${removeLeadingSlash(to)}`\n : to\n\n await fs.ensureDir(path.dirname(filePath))\n await fs.writeFile(filePath, getRedirectHTML(redirectUrl))\n }\n }),\n )\n\n succeed()\n}\n","import {\n deepAssign,\n entries,\n fromEntries,\n isArray,\n isPlainObject,\n keys,\n} from '@vuepress/helper'\nimport type { App } from 'vuepress/core'\nimport { colors } from 'vuepress/utils'\n\nimport type { RedirectBehaviorConfig } from '../shared/index.js'\nimport { logger } from './logger.js'\nimport type { RedirectPluginOptions } from './types/index.js'\n\nconst AVAILABLE_FALLBACK = ['defaultLocale', 'homepage', '404'] as const\n\nexport const getRedirectBehaviorConfig = (\n app: App,\n options: RedirectPluginOptions,\n): RedirectBehaviorConfig => {\n const { locales } = app.siteData\n\n const config = deepAssign(\n fromEntries(\n entries(locales)\n .filter(([key, { lang }]) => {\n if (!lang) {\n logger.error(\n `Missing ${colors.magenta(\n 'lang',\n )} option for locale \"${key}\", this locale will be ignored!`,\n )\n\n return false\n }\n\n return true\n })\n .map(([key, { lang }]) => [key, [lang!]]),\n ),\n isPlainObject(options.localeConfig)\n ? fromEntries(\n entries(options.localeConfig).map(([routePath, lang]) => [\n routePath,\n isArray(lang) ? lang : [lang],\n ]),\n )\n : {},\n )\n\n return {\n config,\n autoLocale: options.autoLocale ?? false,\n defaultLocale: options.defaultLocale || keys(config).pop()!,\n localeFallback: options.localeFallback ?? true,\n defaultBehavior:\n options.defaultBehavior &&\n AVAILABLE_FALLBACK.includes(options.defaultBehavior)\n ? options.defaultBehavior\n : 'defaultLocale',\n }\n}\n","import {\n entries,\n fromEntries,\n isArray,\n isFunction,\n isPlainObject,\n normalizePath,\n} from '@vuepress/helper'\nimport type { App, Page } from 'vuepress/core'\n\nimport type {\n RedirectPluginFrontmatter,\n RedirectPluginOptions,\n} from './types/index.js'\n\nexport const getRedirectMap = (\n app: App,\n options: RedirectPluginOptions,\n): Record<string, string> => {\n const config = isFunction(options.config)\n ? options.config(app)\n : isPlainObject(options.config)\n ? options.config\n : {}\n\n return {\n ...fromEntries(\n (\n app.pages as Page<Record<string, never>, RedirectPluginFrontmatter>[]\n ).flatMap(({ frontmatter, path }) =>\n isArray(frontmatter.redirectFrom)\n ? frontmatter.redirectFrom.map((from) => [\n normalizePath(from, true),\n path,\n ])\n : frontmatter.redirectFrom\n ? [[normalizePath(frontmatter.redirectFrom, true), path]]\n : [],\n ),\n ),\n ...fromEntries(\n entries(config).map(([from, to]) => [\n normalizePath(from, true),\n normalizePath(to),\n ]),\n ),\n }\n}\n","import {\n isLinkAbsolute,\n normalizePath,\n removeLeadingSlash,\n} from '@vuepress/helper'\nimport type { App, Page } from 'vuepress/core'\n\nimport type { RedirectPluginFrontmatter } from './types/index.js'\n\nexport const handleRedirectTo = ({ frontmatter }: Page, app: App): void => {\n const { base } = app.siteData\n const { redirectTo } = frontmatter as RedirectPluginFrontmatter\n\n if (redirectTo) {\n const redirectUrl = normalizePath(\n isLinkAbsolute(redirectTo)\n ? `${base}${removeLeadingSlash(redirectTo)}`\n : redirectTo,\n )\n\n ;(frontmatter.head ??= []).unshift([\n 'script',\n {},\n `{\\\nconst anchor = window.location.hash.slice(1);\\\nwindow.location.replace(\\`${redirectUrl}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`);\\\n}`,\n ])\n }\n}\n","import type { DefaultLocaleInfo } from '@vuepress/helper'\n\nimport type { RedirectPluginLocaleData } from '../shared/index.js'\n\n/** Default locale info for `@vuepress/plugin-redirect` */\nexport const redirectLocaleInfo: DefaultLocaleInfo<RedirectPluginLocaleData> = [\n [\n ['en', 'en-US'],\n {\n name: 'English',\n hint: 'Your primary language is $1, do you want to switch to it?',\n switch: 'Switch to $1',\n cancel: 'Cancel',\n remember: 'Remember my choice',\n },\n ],\n [\n ['zh', 'zh-CN', 'zh-Hans'],\n {\n name: '简体中文',\n hint: '你的首选语言是 $1,是否切换到该语言?',\n switch: '切换到 $1',\n cancel: '取消',\n remember: '记住我的选择',\n },\n ],\n [\n ['zh-TW', 'zh-Hant'],\n {\n name: '繁體中文',\n hint: '你的首選語言是 $1,是否切換到該語言?',\n switch: '切換到 $1',\n cancel: '取消',\n remember: '記住我的選擇',\n },\n ],\n [\n ['de', 'de-DE'],\n {\n name: 'Deutsch',\n hint: 'Ihre bevorzugte Sprache ist $1, möchten Sie zu dieser wechseln?',\n switch: 'Zu $1 wechseln',\n cancel: 'Abbrechen',\n remember: 'Meine Wahl merken',\n },\n ],\n [\n ['de-AT'],\n {\n name: 'Deutsch (Österreich)',\n hint: 'Ihre bevorzugte Sprache ist $1, möchten Sie zu dieser wechseln?',\n switch: 'Zu $1 wechseln',\n cancel: 'Abbrechen',\n remember: 'Meine Wahl merken',\n },\n ],\n [\n ['vi', 'vi-VN'],\n {\n name: 'Tiếng Việt',\n hint: 'Ngôn ngữ chính của bạn là $1, bạn có muốn chuyển sang nó?',\n switch: 'Chuyển sang $1',\n cancel: 'Hủy',\n remember: 'Nhớ lựa chọn của tôi',\n },\n ],\n [\n ['uk'],\n {\n name: 'Українська',\n hint: 'Вашою основною мовою є $1, чи бажаєте ви переключитися на неї?',\n switch: 'Переключитися на $1',\n cancel: 'Скасувати',\n remember: 'Запам’ятати мій вибір',\n },\n ],\n [\n ['ru', 'ru-RU'],\n {\n name: 'Русский',\n hint: 'Ваш основной язык - $1, вы хотите переключиться на него?',\n switch: 'Переключиться на $1',\n cancel: 'Отмена',\n remember: 'Запомнить мой выбор',\n },\n ],\n [\n ['br'],\n {\n name: 'Português (Brasil)',\n hint: 'A língua principal é $1, deseja mudar para ela?',\n switch: 'Mudar para $1',\n cancel: 'Cancelar',\n remember: 'Lembrar minha escolha',\n },\n ],\n [\n ['pl', 'pl-PL'],\n {\n name: 'Polski',\n hint: 'Twoim głównym językiem jest $1, czy chcesz przełączyć się na niego?',\n switch: 'Przełącz na $1',\n cancel: 'Anuluj',\n remember: 'Zapamiętaj moje wybory',\n },\n ],\n [\n ['sk', 'sk-SK'],\n {\n name: 'Slovenčina',\n hint: 'Vašou hlavnou jazykom je $1, chcete prepnúť naň?',\n switch: 'Prepnúť na $1',\n cancel: 'Zrušiť',\n remember: 'Zapamätať si moju voľbu',\n },\n ],\n [\n ['fr', 'fr-FR'],\n {\n name: 'Français',\n hint: 'Votre langue principale est $1, voulez-vous la changer ?',\n switch: 'Changer pour $1',\n cancel: 'Annuler',\n remember: 'Se souvenir de mon choix',\n },\n ],\n [\n ['tr', 'tr-TR'],\n {\n name: 'Türkçe',\n hint: 'Ana diliniz $1, ona geçmek ister misiniz?',\n switch: \"$1'e geç\",\n cancel: 'İptal',\n remember: 'Seçimimi hatırla',\n },\n ],\n [\n ['fi', 'fi-FI'],\n {\n name: 'Suomi',\n hint: 'Pääkielenäsi on $1, haluatko vaihtaa siihen?',\n switch: 'Vaihda $1:een',\n cancel: 'Peruuta',\n remember: 'Muista valintani',\n },\n ],\n [\n ['hu', 'hu-HU'],\n {\n name: 'Magyar',\n hint: 'A fő nyelvét $1, szeretné váltani?',\n switch: 'Váltás $1',\n cancel: 'Mégse',\n remember: 'Emlékezzen a választásomra',\n },\n ],\n [\n ['id', 'id-ID'],\n {\n name: 'Bahasa Indonesia',\n hint: 'Bahasa utama Anda adalah $1, apakah Anda ingin beralih ke sana?',\n switch: 'Beralih ke $1',\n cancel: 'Batal',\n remember: 'Ingat pilihan saya',\n },\n ],\n [\n ['nl', 'nl-NL'],\n {\n name: 'Nederlands',\n hint: 'Uw primaire taal is $1, wilt u overschakelen?',\n switch: 'Overschakelen naar $1',\n cancel: 'Annuleren',\n remember: 'Onthoud mijn keuze',\n },\n ],\n [\n ['ja', 'ja-JP'],\n {\n name: '日本語',\n hint: 'あなたの主要な言語は $1 です。それに切り替えますか?',\n switch: '$1 に切り替える',\n cancel: 'キャンセル',\n remember: '選択を記憶する',\n },\n ],\n [\n ['ko', 'ko-KO'],\n {\n name: '한국어',\n hint: '당신의 기본 언어는 $1입니다. 그것으로 전환 하시겠습니까?',\n switch: '$1로 전환',\n cancel: '취소',\n remember: '내 선택 기억하기',\n },\n ],\n [\n ['es', 'es-ES'],\n {\n name: 'Español',\n hint: 'Su idioma principal es $1, ¿desea cambiarlo?',\n switch: 'Cambiar a $1',\n cancel: 'Cancelar',\n remember: 'Recordar mi elección',\n },\n ],\n [\n ['/pt'],\n {\n name: 'Português',\n hint: 'Sua língua principal é $1, deseja mudar para ela?',\n switch: 'Mudar para $1',\n cancel: 'Cancelar',\n remember: 'Lembrar minha escolha',\n },\n ],\n]\n","import {\n addViteSsrNoExternal,\n getFullLocaleConfig,\n getModulePath,\n} from '@vuepress/helper'\nimport type { PluginFunction } from 'vuepress/core'\nimport { getDirname, path } from 'vuepress/utils'\n\nimport { ensureRootHomePage } from './ensureRootHomePage.js'\nimport {\n generateAutoLocaleRedirectFiles,\n generateRedirectFiles,\n} from './generate/index.js'\nimport { getRedirectBehaviorConfig } from './getRedirectLocaleConfig.js'\nimport { getRedirectMap } from './getRedirectMap.js'\nimport { handleRedirectTo } from './handleRedirectTo.js'\nimport { redirectLocaleInfo } from './locales.js'\nimport { PLUGIN_NAME, logger } from './logger.js'\nimport type { RedirectPluginOptions } from './types/index.js'\n\nconst { url } = import.meta\nconst __dirname = getDirname(url)\n\nexport const redirectPlugin =\n (options: RedirectPluginOptions = {}): PluginFunction =>\n (app) => {\n if (app.env.isDebug) logger.info('Options:', options)\n\n const behaviorConfig = getRedirectBehaviorConfig(app, options)\n let redirectMap: Record<string, string> | null = null\n\n return {\n name: PLUGIN_NAME,\n\n alias: {\n '@vuepress/plugin-redirect/component':\n options.switchLocale === 'modal'\n ? path.resolve(__dirname, '../client/components/RedirectModal.js')\n : options.switchLocale === 'popup'\n ? path.resolve(__dirname, '../client/components/RedirectPopup.js')\n : getModulePath('@vuepress/helper/noopComponent', import.meta),\n },\n\n define: {\n __REDIRECT_COMPONENT__:\n options.switchLocale === 'modal' || options.switchLocale === 'popup',\n __REDIRECT_CONFIG__: behaviorConfig,\n __REDIRECT_DIRECT__: options.switchLocale === 'direct',\n __REDIRECT_LOCALES__: getFullLocaleConfig({\n app,\n name: 'redirect',\n config: options.locales,\n default: redirectLocaleInfo,\n }),\n },\n\n extendsBundlerOptions: (bundlerOptions: unknown) => {\n addViteSsrNoExternal(bundlerOptions, app, '@vuepress/helper')\n },\n\n extendsPage: (page) => {\n handleRedirectTo(page, app)\n },\n\n onInitialized: async () => {\n redirectMap = getRedirectMap(app, options)\n\n if (app.env.isDebug) logger.info('Redirect Map:', redirectMap)\n\n if (options.autoLocale && app.env.isDebug) await ensureRootHomePage(app)\n },\n\n onPrepared: async () => {\n await app.writeTemp(\n 'redirect/map.js',\n `\\\nexport const redirectMap = ${\n app.env.isDev ? JSON.stringify(redirectMap, null, 2) : '{}'\n };\n`,\n )\n // clean redirectMap reference in dev server\n if (app.env.isDev) redirectMap = null\n },\n\n onGenerated: async () => {\n await generateRedirectFiles(app, redirectMap!)\n if (options.autoLocale)\n await generateAutoLocaleRedirectFiles(app, behaviorConfig)\n },\n\n clientConfigFile: path.join(__dirname, '../client/config.js'),\n }\n }\n"],"mappings":"seAGA,MAAa,EAAqB,KAAO,IAA4B,CAGjE,EAAI,MAAM,O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,QAChB,QAAS,CACX,CAAC,CACH,EAEA,sBAAwB,GAA4B,CAClD,EAAqB,EAAgB,EAAK,kBAAkB,CAC9D,EAEA,YAAc,GAAS,CACrB,EAAiB,EAAM,CAAG,CAC5B,EAEA,cAAe,SAAY,CACzB,EAAc,EAAe,EAAK,CAAO,EAErC,EAAI,IAAI,SAAS,EAAO,KAAK,gBAAiB,CAAW,EAEzD,EAAQ,YAAc,EAAI,IAAI,SAAS,MAAM,EAAmB,CAAG,CACzE,EAEA,WAAY,SAAY,CACtB,MAAM,EAAI,UACR,kBACA;6BAEE,EAAI,IAAI,MAAQ,KAAK,UAAU,EAAa,KAAM,CAAC,EAAI,KACxD;CAEH,EAEI,EAAI,IAAI,QAAO,EAAc,KACnC,EAEA,YAAa,SAAY,CACvB,MAAM,EAAsB,EAAK,CAAY,EACzC,EAAQ,YACV,MAAM,EAAgC,EAAK,CAAc,CAC7D,EAEA,iBAAkB,EAAK,KAAK,EAAW,qBAAqB,CAC9D,CACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["logger","logger","logger"],"sources":["../../src/node/ensureRootHomePage.ts","../../src/node/logger.ts","../../src/node/generate/getLocaleRedirectHTML.ts","../../src/node/generate/generateAutoLocaleRedirectFiles.ts","../../src/node/generate/generateRedirectFiles.ts","../../src/node/getRedirectLocaleConfig.ts","../../src/node/getRedirectMap.ts","../../src/node/handleRedirectTo.ts","../../src/node/locales.ts","../../src/node/redirectPlugin.ts"],"sourcesContent":["import type { App } from 'vuepress/core'\nimport { createPage } from 'vuepress/core'\n\nexport const ensureRootHomePage = async (app: App): Promise<void> => {\n if (\n // root homepage not exists\n app.pages.every(({ path }) => path !== '/')\n ) {\n app.pages.push(\n await createPage(app, {\n path: '/',\n frontmatter: { title: 'Home' },\n // set markdown content\n content: `\\\nRedirecting to the correct locale...\n`,\n }),\n )\n }\n}\n","import { Logger } from '@vuepress/helper'\n\nexport const PLUGIN_NAME = '@vuepress/plugin-redirect'\n\nexport const logger = new Logger(PLUGIN_NAME)\n","import { removeEndingSlash } from '@vuepress/helper'\n\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\n\nexport const getLocaleRedirectHTML = (\n {\n config,\n defaultBehavior,\n defaultLocale,\n localeFallback,\n }: RedirectBehaviorConfig,\n availableLocales: string[],\n base: string,\n): string => `<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"robots\" content=\"noindex\">\n <title>Redirecting...</title>\n <script>\n const { hash, origin, pathname } = window.location;\n const routePath = pathname.slice(${base.length});\n const { languages } = window.navigator;\n const anchor = hash.slice(1);\n\n const config = ${JSON.stringify(config)};\n const availableLocales = ${JSON.stringify(availableLocales)};\n const defaultLocale = ${\n availableLocales.includes(defaultLocale)\n ? JSON.stringify(defaultLocale)\n : 'availableLocales.pop()'\n };\n const defaultBehavior = ${JSON.stringify(defaultBehavior)}\n\n let matchedLocalePath = null;\n\n // get matched locale\n findLanguage:\n for (const lang of languages)\n for (const [localePath, langs] of Object.entries(config))\n if (langs.includes(lang)) {\n${\n localeFallback\n ? `\\\n if (!availableLocales.includes(localePath))\n continue;\n`\n : ``\n}\\\n matchedLocalePath = localePath;\n break findLanguage;\n }\n\n // default link\n const defaultLink = defaultLocale? \\`\\${origin}${removeEndingSlash(\n base,\n )}\\${defaultLocale}\\${routePath}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`: null;\n\n // a locale matches\n if (matchedLocalePath) {\n const localeLink = \\`\\${origin}${removeEndingSlash(\n base,\n )}\\${matchedLocalePath}\\${routePath}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`;\n\n if (availableLocales.includes(matchedLocalePath)) {\n location.href = localeLink;\n }\n // the page does not exist\n else {\n // locale homepage\n if (defaultBehavior === \"homepage\") {\n location.href = \\`\\${origin}${removeEndingSlash(\n base,\n )}\\${matchedLocalePath}\\`;\n }\n // default locale page\n else if (defaultBehavior === \"defaultLocale\" && defaultLink) {\n location.href = defaultLink;\n }\n // as is to get a 404 page of that locale\n else {\n location.href = localeLink;\n }\n }\n }\n // we have a default page\n else if (defaultLink) {\n location.href = defaultLink;\n }\n else {\n location.href = \\`\\${origin}${removeEndingSlash(base)}/404.html\\`;\n }\n </script>\n</head>\n<body>\n <p>Redirecting...</p>\n</body>\n</html>\n`\n","import { entries, removeLeadingSlash } from '@vuepress/helper'\nimport type { App } from 'vuepress/core'\nimport { fs, path } from 'vuepress/utils'\n\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\nimport { logger } from '../logger.js'\nimport { getLocaleRedirectHTML } from './getLocaleRedirectHTML.js'\n\nexport const generateAutoLocaleRedirectFiles = async (\n app: App,\n localeOptions: RedirectBehaviorConfig,\n): Promise<void> => {\n const rootPaths = new Set(\n app.pages\n .filter(({ pathLocale }) => pathLocale === '/')\n .map(({ path: pagePath }) => pagePath),\n )\n const localeRedirectMap: Record<string, string[]> = {}\n\n app.pages\n .filter(({ pathLocale }) => pathLocale !== '/')\n .forEach(({ path: pagePath, pathLocale }) => {\n const rootPath = pagePath\n .replace(pathLocale, '/')\n .replace(/\\/$/u, '/index.html')\n\n if (!rootPaths.has(rootPath))\n (localeRedirectMap[rootPath] ??= []).push(pathLocale)\n })\n\n const { succeed } = logger.load('Generating locale redirect files')\n\n await Promise.all(\n entries(localeRedirectMap).map(async ([rootPath, availableLocales]) => {\n const filePath = app.dir.dest(removeLeadingSlash(rootPath))\n\n if (!fs.existsSync(filePath)) {\n await fs.ensureDir(path.dirname(filePath))\n await fs.writeFile(\n filePath,\n getLocaleRedirectHTML(\n localeOptions,\n availableLocales,\n app.siteData.base,\n ),\n )\n }\n }),\n )\n\n succeed()\n}\n","import {\n entries,\n isLinkAbsolute,\n isLinkHttp,\n removeEndingSlash,\n removeLeadingSlash,\n} from '@vuepress/helper'\nimport type { App } from 'vuepress/core'\nimport { fs, path } from 'vuepress/utils'\n\nimport { logger } from '../logger.js'\nimport { getRedirectHTML } from './getRedirectHTML.js'\n\nexport const generateRedirectFiles = async (\n app: App,\n config: Record<string, string>,\n hostname = '',\n): Promise<void> => {\n const resolvedHostname = hostname\n ? removeEndingSlash(isLinkHttp(hostname) ? hostname : `https://${hostname}`)\n : ''\n\n const { succeed } = logger.load('Generating redirect files')\n\n await Promise.all(\n entries(config).map(async ([from, to]) => {\n const filePath = app.dir.dest(removeLeadingSlash(from))\n\n if (!fs.existsSync(filePath)) {\n const redirectUrl = isLinkAbsolute(to)\n ? `${resolvedHostname}${app.siteData.base}${removeLeadingSlash(to)}`\n : to\n\n await fs.ensureDir(path.dirname(filePath))\n await fs.writeFile(filePath, getRedirectHTML(redirectUrl))\n }\n }),\n )\n\n succeed()\n}\n","import {\n deepAssign,\n entries,\n fromEntries,\n isArray,\n isPlainObject,\n keys,\n} from '@vuepress/helper'\nimport type { App } from 'vuepress/core'\nimport { colors } from 'vuepress/utils'\n\nimport type { RedirectBehaviorConfig } from '../shared/index.js'\nimport { logger } from './logger.js'\nimport type { RedirectPluginOptions } from './types/index.js'\n\nconst AVAILABLE_FALLBACK = ['defaultLocale', 'homepage', '404'] as const\n\nexport const getRedirectBehaviorConfig = (\n app: App,\n options: RedirectPluginOptions,\n): RedirectBehaviorConfig => {\n const { locales } = app.siteData\n\n const config = deepAssign(\n fromEntries(\n entries(locales)\n .filter(([key, { lang }]) => {\n if (!lang) {\n logger.error(\n `Missing ${colors.magenta(\n 'lang',\n )} option for locale \"${key}\", this locale will be ignored!`,\n )\n\n return false\n }\n\n return true\n })\n .map(([key, { lang }]) => [key, [lang!]]),\n ),\n isPlainObject(options.localeConfig)\n ? fromEntries(\n entries(options.localeConfig).map(([routePath, lang]) => [\n routePath,\n isArray(lang) ? lang : [lang],\n ]),\n )\n : {},\n )\n\n return {\n config,\n autoLocale: options.autoLocale ?? false,\n defaultLocale: options.defaultLocale || keys(config).pop()!,\n localeFallback: options.localeFallback ?? true,\n defaultBehavior:\n options.defaultBehavior &&\n AVAILABLE_FALLBACK.includes(options.defaultBehavior)\n ? options.defaultBehavior\n : 'defaultLocale',\n }\n}\n","import {\n entries,\n fromEntries,\n isArray,\n isFunction,\n isPlainObject,\n normalizePath,\n} from '@vuepress/helper'\nimport type { App, Page } from 'vuepress/core'\n\nimport type {\n RedirectPluginFrontmatter,\n RedirectPluginOptions,\n} from './types/index.js'\n\nexport const getRedirectMap = (\n app: App,\n options: RedirectPluginOptions,\n): Record<string, string> => {\n const config = isFunction(options.config)\n ? options.config(app)\n : isPlainObject(options.config)\n ? options.config\n : {}\n\n return {\n ...fromEntries(\n (\n app.pages as Page<Record<string, never>, RedirectPluginFrontmatter>[]\n ).flatMap(({ frontmatter, path }) =>\n isArray(frontmatter.redirectFrom)\n ? frontmatter.redirectFrom.map((from) => [\n normalizePath(from, true),\n path,\n ])\n : frontmatter.redirectFrom\n ? [[normalizePath(frontmatter.redirectFrom, true), path]]\n : [],\n ),\n ),\n ...fromEntries(\n entries(config).map(([from, to]) => [\n normalizePath(from, true),\n normalizePath(to),\n ]),\n ),\n }\n}\n","import {\n isLinkAbsolute,\n normalizePath,\n removeLeadingSlash,\n} from '@vuepress/helper'\nimport type { App, Page } from 'vuepress/core'\n\nimport type { RedirectPluginFrontmatter } from './types/index.js'\n\nexport const handleRedirectTo = ({ frontmatter }: Page, app: App): void => {\n const { base } = app.siteData\n const { redirectTo } = frontmatter as RedirectPluginFrontmatter\n\n if (redirectTo) {\n const redirectUrl = normalizePath(\n isLinkAbsolute(redirectTo)\n ? `${base}${removeLeadingSlash(redirectTo)}`\n : redirectTo,\n )\n\n ;(frontmatter.head ??= []).unshift([\n 'script',\n {},\n `{\\\nconst anchor = window.location.hash.slice(1);\\\nwindow.location.replace(\\`${redirectUrl}\\${anchor? \\`#\\${anchor}\\`: \"\"}\\`);\\\n}`,\n ])\n }\n}\n","import type { DefaultLocaleInfo } from '@vuepress/helper'\n\nimport type { RedirectPluginLocaleData } from '../shared/index.js'\n\n/** Default locale info for `@vuepress/plugin-redirect` */\nexport const redirectLocaleInfo: DefaultLocaleInfo<RedirectPluginLocaleData> = [\n [\n ['en', 'en-US'],\n {\n name: 'English',\n hint: 'Your primary language is $1, do you want to switch to it?',\n switch: 'Switch to $1',\n cancel: 'Cancel',\n remember: 'Remember my choice',\n },\n ],\n [\n ['zh', 'zh-CN', 'zh-Hans'],\n {\n name: '简体中文',\n hint: '你的首选语言是 $1,是否切换到该语言?',\n switch: '切换到 $1',\n cancel: '取消',\n remember: '记住我的选择',\n },\n ],\n [\n ['zh-TW', 'zh-Hant'],\n {\n name: '繁體中文',\n hint: '你的首選語言是 $1,是否切換到該語言?',\n switch: '切換到 $1',\n cancel: '取消',\n remember: '記住我的選擇',\n },\n ],\n [\n ['de', 'de-DE'],\n {\n name: 'Deutsch',\n hint: 'Ihre bevorzugte Sprache ist $1, möchten Sie zu dieser wechseln?',\n switch: 'Zu $1 wechseln',\n cancel: 'Abbrechen',\n remember: 'Meine Wahl merken',\n },\n ],\n [\n ['de-AT'],\n {\n name: 'Deutsch (Österreich)',\n hint: 'Ihre bevorzugte Sprache ist $1, möchten Sie zu dieser wechseln?',\n switch: 'Zu $1 wechseln',\n cancel: 'Abbrechen',\n remember: 'Meine Wahl merken',\n },\n ],\n [\n ['vi', 'vi-VN'],\n {\n name: 'Tiếng Việt',\n hint: 'Ngôn ngữ chính của bạn là $1, bạn có muốn chuyển sang nó?',\n switch: 'Chuyển sang $1',\n cancel: 'Hủy',\n remember: 'Nhớ lựa chọn của tôi',\n },\n ],\n [\n ['uk'],\n {\n name: 'Українська',\n hint: 'Вашою основною мовою є $1, чи бажаєте ви переключитися на неї?',\n switch: 'Переключитися на $1',\n cancel: 'Скасувати',\n remember: 'Запам’ятати мій вибір',\n },\n ],\n [\n ['ru', 'ru-RU'],\n {\n name: 'Русский',\n hint: 'Ваш основной язык - $1, вы хотите переключиться на него?',\n switch: 'Переключиться на $1',\n cancel: 'Отмена',\n remember: 'Запомнить мой выбор',\n },\n ],\n [\n ['br'],\n {\n name: 'Português (Brasil)',\n hint: 'A língua principal é $1, deseja mudar para ela?',\n switch: 'Mudar para $1',\n cancel: 'Cancelar',\n remember: 'Lembrar minha escolha',\n },\n ],\n [\n ['pl', 'pl-PL'],\n {\n name: 'Polski',\n hint: 'Twoim głównym językiem jest $1, czy chcesz przełączyć się na niego?',\n switch: 'Przełącz na $1',\n cancel: 'Anuluj',\n remember: 'Zapamiętaj moje wybory',\n },\n ],\n [\n ['sk', 'sk-SK'],\n {\n name: 'Slovenčina',\n hint: 'Vašou hlavnou jazykom je $1, chcete prepnúť naň?',\n switch: 'Prepnúť na $1',\n cancel: 'Zrušiť',\n remember: 'Zapamätať si moju voľbu',\n },\n ],\n [\n ['fr', 'fr-FR'],\n {\n name: 'Français',\n hint: 'Votre langue principale est $1, voulez-vous la changer ?',\n switch: 'Changer pour $1',\n cancel: 'Annuler',\n remember: 'Se souvenir de mon choix',\n },\n ],\n [\n ['tr', 'tr-TR'],\n {\n name: 'Türkçe',\n hint: 'Ana diliniz $1, ona geçmek ister misiniz?',\n switch: \"$1'e geç\",\n cancel: 'İptal',\n remember: 'Seçimimi hatırla',\n },\n ],\n [\n ['fi', 'fi-FI'],\n {\n name: 'Suomi',\n hint: 'Pääkielenäsi on $1, haluatko vaihtaa siihen?',\n switch: 'Vaihda $1:een',\n cancel: 'Peruuta',\n remember: 'Muista valintani',\n },\n ],\n [\n ['hu', 'hu-HU'],\n {\n name: 'Magyar',\n hint: 'A fő nyelvét $1, szeretné váltani?',\n switch: 'Váltás $1',\n cancel: 'Mégse',\n remember: 'Emlékezzen a választásomra',\n },\n ],\n [\n ['id', 'id-ID'],\n {\n name: 'Bahasa Indonesia',\n hint: 'Bahasa utama Anda adalah $1, apakah Anda ingin beralih ke sana?',\n switch: 'Beralih ke $1',\n cancel: 'Batal',\n remember: 'Ingat pilihan saya',\n },\n ],\n [\n ['nl', 'nl-NL'],\n {\n name: 'Nederlands',\n hint: 'Uw primaire taal is $1, wilt u overschakelen?',\n switch: 'Overschakelen naar $1',\n cancel: 'Annuleren',\n remember: 'Onthoud mijn keuze',\n },\n ],\n [\n ['ja', 'ja-JP'],\n {\n name: '日本語',\n hint: 'あなたの主要な言語は $1 です。それに切り替えますか?',\n switch: '$1 に切り替える',\n cancel: 'キャンセル',\n remember: '選択を記憶する',\n },\n ],\n [\n ['ko', 'ko-KO'],\n {\n name: '한국어',\n hint: '당신의 기본 언어는 $1입니다. 그것으로 전환 하시겠습니까?',\n switch: '$1로 전환',\n cancel: '취소',\n remember: '내 선택 기억하기',\n },\n ],\n [\n ['es', 'es-ES'],\n {\n name: 'Español',\n hint: 'Su idioma principal es $1, ¿desea cambiarlo?',\n switch: 'Cambiar a $1',\n cancel: 'Cancelar',\n remember: 'Recordar mi elección',\n },\n ],\n [\n ['/pt'],\n {\n name: 'Português',\n hint: 'Sua língua principal é $1, deseja mudar para ela?',\n switch: 'Mudar para $1',\n cancel: 'Cancelar',\n remember: 'Lembrar minha escolha',\n },\n ],\n]\n","import {\n addViteSsrNoExternal,\n getFullLocaleConfig,\n getModulePath,\n} from '@vuepress/helper'\nimport type { PluginFunction } from 'vuepress/core'\nimport { getDirname, path } from 'vuepress/utils'\n\nimport { ensureRootHomePage } from './ensureRootHomePage.js'\nimport {\n generateAutoLocaleRedirectFiles,\n generateRedirectFiles,\n} from './generate/index.js'\nimport { getRedirectBehaviorConfig } from './getRedirectLocaleConfig.js'\nimport { getRedirectMap } from './getRedirectMap.js'\nimport { handleRedirectTo } from './handleRedirectTo.js'\nimport { redirectLocaleInfo } from './locales.js'\nimport { PLUGIN_NAME, logger } from './logger.js'\nimport type { RedirectPluginOptions } from './types/index.js'\n\nconst { url } = import.meta\nconst __dirname = getDirname(url)\n\nexport const redirectPlugin =\n (options: RedirectPluginOptions = {}): PluginFunction =>\n (app) => {\n if (app.env.isDebug) logger.info('Options:', options)\n\n const behaviorConfig = getRedirectBehaviorConfig(app, options)\n let redirectMap: Record<string, string> | null = null\n\n return {\n name: PLUGIN_NAME,\n\n alias: {\n '@vuepress/plugin-redirect/component':\n options.switchLocale === 'modal'\n ? path.resolve(__dirname, '../client/components/RedirectModal.js')\n : options.switchLocale === 'popup'\n ? path.resolve(__dirname, '../client/components/RedirectPopup.js')\n : getModulePath('@vuepress/helper/noopComponent', import.meta),\n },\n\n define: {\n __REDIRECT_COMPONENT__:\n options.switchLocale === 'modal' || options.switchLocale === 'popup',\n __REDIRECT_CONFIG__: behaviorConfig,\n __REDIRECT_DIRECT__: options.switchLocale === 'direct',\n __REDIRECT_LOCALES__: getFullLocaleConfig({\n app,\n name: 'redirect',\n config: options.locales,\n default: redirectLocaleInfo,\n }),\n },\n\n extendsBundlerOptions: (bundlerOptions: unknown) => {\n addViteSsrNoExternal(bundlerOptions, app, '@vuepress/helper')\n },\n\n extendsPage: (page) => {\n handleRedirectTo(page, app)\n },\n\n onInitialized: async () => {\n redirectMap = getRedirectMap(app, options)\n\n if (app.env.isDebug) logger.info('Redirect Map:', redirectMap)\n\n if (options.autoLocale && app.env.isDebug) await ensureRootHomePage(app)\n },\n\n onPrepared: async () => {\n await app.writeTemp(\n 'redirect/map.js',\n `\\\nexport const redirectMap = ${\n app.env.isDev ? JSON.stringify(redirectMap, null, 2) : '{}'\n };\n`,\n )\n // clean redirectMap reference in dev server\n if (app.env.isDev) redirectMap = null\n },\n\n onGenerated: async () => {\n await generateRedirectFiles(app, redirectMap!)\n if (options.autoLocale)\n await generateAutoLocaleRedirectFiles(app, behaviorConfig)\n },\n\n clientConfigFile: path.join(__dirname, '../client/config.js'),\n }\n }\n"],"mappings":"seAGA,MAAa,EAAqB,KAAO,IAA4B,CAGjE,EAAI,MAAM,OAAO,CAAE,UAAW,IAAS,GAAG,GAE1C,EAAI,MAAM,KACR,MAAM,EAAW,EAAK,CACpB,KAAM,IACN,YAAa,CAAE,MAAO,MAAO,EAE7B,QAAS;CAGX,CAAC,CACH,CAEJ,ECjBa,EAAc,4BAEdA,EAAS,IAAI,EAAO,CAAW,ECA/B,GACX,CACE,SACA,kBACA,gBACA,kBAEF,EACA,IACW;;;;;;;;uCAQ0B,EAAK,OAAO;;;;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KAAK,gBAAiB,CAAW,EAEzD,EAAQ,YAAc,EAAI,IAAI,SAAS,MAAM,EAAmB,CAAG,CACzE,EAEA,WAAY,SAAY,CACtB,MAAM,EAAI,UACR,kBACA;6BAEE,EAAI,IAAI,MAAQ,KAAK,UAAU,EAAa,KAAM,CAAC,EAAI,KACxD;CAEH,EAEI,EAAI,IAAI,QAAO,EAAc,KACnC,EAEA,YAAa,SAAY,CACvB,MAAM,EAAsB,EAAK,CAAY,EACzC,EAAQ,YACV,MAAM,EAAgC,EAAK,CAAc,CAC7D,EAEA,iBAAkB,EAAK,KAAK,EAAW,qBAAqB,CAC9D,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e,t}from"./useRedirectLocation-
|
|
2
|
-
//# sourceMappingURL=setupRedirect-
|
|
1
|
+
import{r as e,t}from"./useRedirectLocation-D83RJLxs.js";import{usePreferredLanguages as n,watchImmediate as r}from"@vueuse/core";import{computed as i,onMounted as a}from"vue";import{entries as o,isLinkHttp as s,normalizePath as c}from"@vuepress/helper/client";import{useData as l,useRoute as u,useRouteLocale as d,useRoutePath as f,useRouter as p}from"vuepress/client";import{redirectMap as m}from"@temp/redirect/map.js";const h=({autoLocale:e,config:t,defaultBehavior:a,defaultLocale:l,localeFallback:h})=>{let g=Object.entries(t),_=n(),v=u(),y=p(),b=d(),x=f(),S=i(()=>b.value===`/`),C=()=>{let e=x.value,t=y.getRoutes(),n=l&&t.some(({path:t})=>t===e.replace(`/`,l))?l:t.find(({path:t})=>e.split(`/`).length>=3&&t===e.replace(/^\/[^/]+\//u,`/`))?.path,r=null;findLanguage:for(let n of _.value)for(let[i,a]of g)if(a.includes(n)){if(h&&t.every(({path:t})=>t!==e.replace(`/`,t)))continue;r=i;break findLanguage}let i=n?v.fullPath.replace(`/`,n):null;if(r){let n=t.some(({path:t})=>e.replace(`/`,r)===t),o=v.fullPath.replace(`/`,r),s=n?o:a===`homepage`?r:a===`defaultLocale`&&i?i:o;y.replace(s)}else i?y.replace(i):x.value!==`/404.html`&&y.replace(`/404.html`)};r(x,t=>{for(let[e,n]of o(m))if(c(t.toLowerCase())===e.toLowerCase()){s(n)?window.open(n):y.replace(n);return}e&&S.value&&C()})},g=n=>{let{routeLocale:r,routePath:i}=l(),o=p(),s=t(n);a(()=>{s.value&&!e.value[r.value]&&(o.replace(i.value.replace(r.value,s.value.localePath)),e.value[r.value]=!0)})};export{h as n,g as t};
|
|
2
|
+
//# sourceMappingURL=setupRedirect-Ca8WTELZ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupRedirect-
|
|
1
|
+
{"version":3,"file":"setupRedirect-Ca8WTELZ.js","names":[],"sources":["../src/client/composables/setupDevServerRedirect.ts","../src/client/composables/setupRedirect.ts"],"sourcesContent":["import { entries, normalizePath, isLinkHttp } from '@vuepress/helper/client'\nimport { usePreferredLanguages, watchImmediate } from '@vueuse/core'\nimport { computed } from 'vue'\nimport {\n useRoute,\n useRouteLocale,\n useRoutePath,\n useRouter,\n} from 'vuepress/client'\n\nimport { redirectMap } from '@temp/redirect/map.js'\n\nimport type { RedirectBehaviorConfig } 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 const routePath = useRoutePath()\n\n const isRootLocale = computed(() => routeLocale.value === '/')\n\n const handleLocaleRedirect = (): void => {\n const routePathValue = routePath.value\n const routes = router.getRoutes()\n const defaultLocale =\n defaultLocalePath &&\n routes.some(\n ({ path }) => path === routePathValue.replace('/', defaultLocalePath),\n )\n ? defaultLocalePath\n : routes.find(\n ({ path }) =>\n routePathValue.split('/').length >= 3 &&\n path === routePathValue.replace(/^\\/[^/]+\\//u, '/'),\n )?.path\n\n let matchedLocalePath: string | null = null\n\n // get matched locale\n // oxlint-disable-next-line no-labels\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(\n ({ path }) => path !== routePathValue.replace('/', path),\n )\n )\n continue\n\n matchedLocalePath = localePath\n // oxlint-disable-next-line no-labels\n break findLanguage\n }\n }\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 }) => routePathValue.replace('/', matchedLocalePath) === path,\n )\n const localeRoute = route.fullPath.replace('/', matchedLocalePath)\n\n const redirectPath =\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 void router.replace(redirectPath)\n }\n // we have a default page\n else if (defaultRoute) {\n void router.replace(defaultRoute)\n } else if (routePath.value !== '/404.html') {\n void router.replace('/404.html')\n }\n }\n\n watchImmediate(routePath, (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 void router.replace(to)\n\n return\n }\n }\n\n if (autoLocale && isRootLocale.value) handleLocaleRedirect()\n })\n}\n","import { onMounted } from 'vue'\nimport { useData, useRouter } from 'vuepress/client'\n\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\nimport { statusSessionStorage } from '../utils/index.js'\nimport { useRedirectLocation } from './useRedirectLocation.js'\n\nexport interface LocaleInfo {\n lang: string\n localePath: string\n}\n\nexport const setupRedirect = (behaviorConfig: RedirectBehaviorConfig): void => {\n const { routeLocale, routePath } = useData()\n const router = useRouter()\n const redirectLocation = useRedirectLocation(behaviorConfig)\n\n onMounted(() => {\n if (\n redirectLocation.value &&\n !statusSessionStorage.value[routeLocale.value]\n ) {\n void router.replace(\n routePath.value.replace(\n routeLocale.value,\n redirectLocation.value.localePath,\n ),\n )\n statusSessionStorage.value[routeLocale.value] = true\n }\n })\n}\n"],"mappings":"qaAcA,MAAa,GAA0B,CACrC,aACA,SACA,kBACA,cAAe,EACf,oBACkC,CAClC,IAAM,EAAgB,OAAO,QAAQ,CAAM,EACrC,EAAY,EAAsB,EAClC,EAAQ,EAAS,EACjB,EAAS,EAAU,EACnB,EAAc,EAAe,EAC7B,EAAY,EAAa,EAEzB,EAAe,MAAe,EAAY,QAAU,GAAG,EAEvD,MAAmC,CACvC,IAAM,EAAiB,EAAU,MAC3B,EAAS,EAAO,UAAU,EAC1B,EACJ,GACA,EAAO,MACJ,CAAE,UAAW,IAAS,EAAe,QAAQ,IAAK,CAAiB,CACtE,EACI,EACA,EAAO,MACJ,CAAE,UACD,EAAe,MAAM,GAAG,CAAC,CAAC,QAAU,GACpC,IAAS,EAAe,QAAQ,cAAe,GAAG,CACtD,CAAC,EAAE,KAEL,EAAmC,KAIvC,aAAc,IAAK,IAAM,KAAQ,EAAU,MACzC,IAAK,GAAM,CAAC,EAAY,KAAU,EAChC,GAAI,EAAM,SAAS,CAAI,EAAG,CACxB,GACE,GACA,EAAO,OACJ,CAAE,UAAW,IAAS,EAAe,QAAQ,IAAK,CAAI,CACzD,EAEA,SAEF,EAAoB,EAEpB,MAAM,YACR,CAKJ,IAAM,EAAe,EACjB,EAAM,SAAS,QAAQ,IAAK,CAAa,EACzC,KAGJ,GAAI,EAAmB,CACrB,IAAM,EAAgB,EAAO,MAC1B,CAAE,UAAW,EAAe,QAAQ,IAAK,CAAiB,IAAM,CACnE,EACM,EAAc,EAAM,SAAS,QAAQ,IAAK,CAAiB,EAE3D,EAEJ,EACI,EAEA,IAAoB,WAElB,EACA,IAAoB,iBAAmB,EAErC,EAEA,EAEV,EAAY,QAAQ,CAAY,CAClC,MAES,EACP,EAAY,QAAQ,CAAY,EACvB,EAAU,QAAU,aAC7B,EAAY,QAAQ,WAAW,CAEnC,EAEA,EAAe,EAAY,GAAS,CAElC,IAAK,GAAM,CAAC,EAAM,KAAO,EAAQ,CAAW,EAC1C,GAAI,EAAc,EAAK,YAAY,CAAC,IAAM,EAAK,YAAY,EAAG,CACxD,EAAW,CAAE,EAAG,OAAO,KAAK,CAAE,EAC7B,EAAY,QAAQ,CAAE,EAE3B,MACF,CAGE,GAAc,EAAa,OAAO,EAAqB,CAC7D,CAAC,CACH,ECxGa,EAAiB,GAAiD,CAC7E,GAAM,CAAE,cAAa,aAAc,EAAQ,EACrC,EAAS,EAAU,EACnB,EAAmB,EAAoB,CAAc,EAE3D,MAAgB,CAEZ,EAAiB,OACjB,CAAC,EAAqB,MAAM,EAAY,SAExC,EAAY,QACV,EAAU,MAAM,QACd,EAAY,MACZ,EAAiB,MAAM,UACzB,CACF,EACA,EAAqB,MAAM,EAAY,OAAS,GAEpD,CAAC,CACH"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { t as RedirectPluginLocaleData } from "./locales-
|
|
1
|
+
import { t as RedirectPluginLocaleData } from "./locales-D7nbWdGO.js";
|
|
2
2
|
import { ExactLocaleConfig } from "@vuepress/helper/client";
|
|
3
|
-
|
|
4
3
|
//#region src/client/types.d.ts
|
|
5
4
|
type RedirectPluginLocaleConfig = ExactLocaleConfig<RedirectPluginLocaleData>;
|
|
6
5
|
//#endregion
|
|
7
6
|
export { RedirectPluginLocaleConfig as t };
|
|
8
|
-
//# sourceMappingURL=types-
|
|
7
|
+
//# sourceMappingURL=types-C9kDILtX.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./useRedirectLocation-
|
|
2
|
-
//# sourceMappingURL=useRedirect-
|
|
1
|
+
import{n as e,r as t,t as n}from"./useRedirectLocation-D83RJLxs.js";import{computed as r,onBeforeUnmount as i,onMounted as a,ref as o,watch as s}from"vue";import{useData as c,useRouter as l}from"vuepress/client";const u={config:{type:Object,required:!0},locales:{type:Object,required:!0}},d=u=>{let{routeLocale:d,routePath:f}=c(),p=n(u.config),m=l(),h=o(!1),g=o(!1),_=r(()=>{if(!p.value)return null;let{lang:e,localePath:t}=p.value,n=u.locales[t],r=u.locales[d.value];return{hint:[n,r].map(({hint:t})=>t.replace(`$1`,e)),switch:n.switch.replace(`$1`,n.name),cancel:r.cancel,remember:n.remember}}),v=()=>{t.value[d.value]=!0,g.value&&(e.value[d.value]=!0),h.value=!1};return a(()=>{s(f,()=>{h.value=!1}),p.value&&!t.value[d.value]&&!e.value[d.value]&&(h.value=!0)}),i(()=>{h.value=!1}),{showComponent:h,shouldRemember:g,locale:_,persistUserAction:v,redirect:()=>{m.replace(f.value.replace(d.value,p.value.localePath)),v()}}};export{d as n,u as t};
|
|
2
|
+
//# sourceMappingURL=useRedirect-CSm17u8x.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedirect-
|
|
1
|
+
{"version":3,"file":"useRedirect-CSm17u8x.js","names":[],"sources":["../src/client/composables/useRedirect.ts"],"sourcesContent":["import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport type { ComputedRef, ExtractPropTypes, PropType, Ref } from 'vue'\nimport { useData, useRouter } from 'vuepress/client'\n\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\nimport type { RedirectPluginLocaleConfig } from '../types.js'\nimport { statusLocalStorage, statusSessionStorage } from '../utils/index.js'\nimport { useRedirectLocation } from './useRedirectLocation.js'\n\nexport const propsOptions = {\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} as const\n\ntype Props = ExtractPropTypes<typeof propsOptions>\n\nexport interface Redirect {\n showComponent: Ref<boolean>\n shouldRemember: Ref<boolean>\n locale: ComputedRef<{\n hint: string[]\n switch: string\n cancel: string\n remember: string\n } | null>\n persistUserAction: () => void\n redirect: () => void\n}\n\nexport const useRedirect = (props: Props): Redirect => {\n const { routeLocale, routePath } = useData()\n const redirectInfo = useRedirectLocation(props.config)\n const router = useRouter()\n\n const showComponent = ref(false)\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 targetLocale = props.locales[localePath]\n const currentLocale = props.locales[routeLocale.value]\n\n return {\n hint: [targetLocale, currentLocale].map(({ hint }) =>\n hint.replace('$1', lang),\n ),\n switch: targetLocale.switch.replace('$1', targetLocale.name),\n cancel: currentLocale.cancel,\n remember: targetLocale.remember,\n }\n })\n\n const persistUserAction = (): void => {\n statusSessionStorage.value[routeLocale.value] = true\n if (shouldRemember.value) statusLocalStorage.value[routeLocale.value] = true\n\n showComponent.value = false\n }\n\n const redirect = (): void => {\n void router.replace(\n routePath.value.replace(\n routeLocale.value,\n redirectInfo.value!.localePath,\n ),\n )\n persistUserAction()\n }\n\n onMounted(() => {\n watch(routePath, () => {\n showComponent.value = false\n })\n\n if (\n redirectInfo.value &&\n !statusSessionStorage.value[routeLocale.value] &&\n !statusLocalStorage.value[routeLocale.value]\n )\n showComponent.value = true\n })\n\n onBeforeUnmount(() => {\n showComponent.value = false\n })\n\n return {\n showComponent,\n shouldRemember,\n locale,\n persistUserAction,\n redirect,\n }\n}\n"],"mappings":"oNASA,MAAa,EAAe,CAC1B,OAAQ,CACN,KAAM,OACN,SAAU,EACZ,EAEA,QAAS,CACP,KAAM,OACN,SAAU,EACZ,CACF,EAiBa,EAAe,GAA2B,CACrD,GAAM,CAAE,cAAa,aAAc,EAAQ,EACrC,EAAe,EAAoB,EAAM,MAAM,EAC/C,EAAS,EAAU,EAEnB,EAAgB,EAAI,EAAK,EACzB,EAAiB,EAAI,EAAK,EAE1B,EAAS,MAAe,CAC5B,GAAI,CAAC,EAAa,MAAO,OAAO,KAEhC,GAAM,CAAE,OAAM,cAAe,EAAa,MACpC,EAAe,EAAM,QAAQ,GAC7B,EAAgB,EAAM,QAAQ,EAAY,OAEhD,MAAO,CACL,KAAM,CAAC,EAAc,CAAa,CAAC,CAAC,KAAK,CAAE,UACzC,EAAK,QAAQ,KAAM,CAAI,CACzB,EACA,OAAQ,EAAa,OAAO,QAAQ,KAAM,EAAa,IAAI,EAC3D,OAAQ,EAAc,OACtB,SAAU,EAAa,QACzB,CACF,CAAC,EAEK,MAAgC,CACpC,EAAqB,MAAM,EAAY,OAAS,GAC5C,EAAe,QAAO,EAAmB,MAAM,EAAY,OAAS,IAExE,EAAc,MAAQ,EACxB,EA6BA,OAjBA,MAAgB,CACd,EAAM,MAAiB,CACrB,EAAc,MAAQ,EACxB,CAAC,EAGC,EAAa,OACb,CAAC,EAAqB,MAAM,EAAY,QACxC,CAAC,EAAmB,MAAM,EAAY,SAEtC,EAAc,MAAQ,GAC1B,CAAC,EAED,MAAsB,CACpB,EAAc,MAAQ,EACxB,CAAC,EAEM,CACL,gBACA,iBACA,SACA,oBACA,aAhC2B,CAC3B,EAAY,QACV,EAAU,MAAM,QACd,EAAY,MACZ,EAAa,MAAO,UACtB,CACF,EACA,EAAkB,CACpB,CAyBA,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{useLocalStorage as e,usePreferredLanguages as t,useSessionStorage as n}from"@vueuse/core";import{computed as r}from"vue";import{entries as i}from"@vuepress/helper/client";import{useRouteLocale as a}from"vuepress/client";const o=`VUEPRESS_REDIRECT_STATUS`,s=e(o,{}),c=n(o,{}),l=e=>{let n=t(),o=a(),s=i(e.config);return r(()=>{if(s.some(([e])=>o.value===e)){for(let e of n.value)for(let[t,n]of s)if(n.includes(e))return t===o.value?null:{lang:e,localePath:t}}return null})};export{s as n,c as r,l as t};
|
|
2
|
-
//# sourceMappingURL=useRedirectLocation-
|
|
2
|
+
//# sourceMappingURL=useRedirectLocation-D83RJLxs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedirectLocation-
|
|
1
|
+
{"version":3,"file":"useRedirectLocation-D83RJLxs.js","names":[],"sources":["../src/client/utils/storage.ts","../src/client/composables/useRedirectLocation.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'\n\nimport type { RedirectBehaviorConfig } from '../../shared/index.js'\n\nexport interface RedirectLocation {\n lang: string\n localePath: string\n}\n\nexport const useRedirectLocation = (\n behaviorConfig: RedirectBehaviorConfig,\n): ComputedRef<RedirectLocation | 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 // oxlint-disable-next-line max-depth\n if (localePath === routeLocale.value) return null\n\n return {\n lang: language,\n localePath,\n }\n }\n }\n }\n }\n\n return null\n })\n}\n"],"mappings":"mOAEA,MAAM,EAAuB,2BAEhB,EAAqB,EAChC,EACA,CAAC,CACH,EAEa,EAAuB,EAClC,EACA,CAAC,CACH,ECCa,EACX,GACyC,CACzC,IAAM,EAAY,EAAsB,EAClC,EAAc,EAAe,EAE7B,EAAgB,EAAQ,EAAe,MAAM,EAEnD,OAAO,MAAe,CACpB,GAAI,EAAc,MAAM,CAAC,KAAS,EAAY,QAAU,CAAG,EACpD,KAAA,IAAM,KAAY,EAAU,MAC/B,IAAK,GAAM,CAAC,EAAY,KAAU,EAChC,GAAI,EAAM,SAAS,CAAQ,EAIzB,OAFI,IAAe,EAAY,MAAc,KAEtC,CACL,KAAM,EACN,YACF,CACF,CAKN,OAAO,IACT,CAAC,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/plugin-redirect",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.134",
|
|
4
4
|
"description": "VuePress plugin - redirect",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@vuepress/helper": "2.0.0-rc.
|
|
52
|
-
"@vueuse/core": "^14.
|
|
53
|
-
"commander": "^
|
|
54
|
-
"vue": "^3.5.
|
|
51
|
+
"@vuepress/helper": "2.0.0-rc.134",
|
|
52
|
+
"@vueuse/core": "^14.4.0",
|
|
53
|
+
"commander": "^15.0.0",
|
|
54
|
+
"vue": "^3.5.42"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"vuepress": "2.0.0-rc.
|
|
57
|
+
"vuepress": "2.0.0-rc.31"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "938b80193c26fb617270f6d86729e52ee298da03"
|
|
60
60
|
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { t as RedirectBehaviorConfig } from "./behavior-C4MffXxI.js";
|
|
2
|
-
import { t as RedirectPluginLocaleConfig } from "./types-DXUJF0Nm.js";
|
|
3
|
-
import * as _$vue from "vue";
|
|
4
|
-
import { VNode } from "vue";
|
|
5
|
-
//#region src/client/components/RedirectModal.d.ts
|
|
6
|
-
declare const _default: _$vue.DefineComponent<_$vue.ExtractPropTypes<{
|
|
7
|
-
readonly config: {
|
|
8
|
-
readonly type: _$vue.PropType<RedirectBehaviorConfig>;
|
|
9
|
-
readonly required: true;
|
|
10
|
-
};
|
|
11
|
-
readonly locales: {
|
|
12
|
-
readonly type: _$vue.PropType<RedirectPluginLocaleConfig>;
|
|
13
|
-
readonly required: true;
|
|
14
|
-
};
|
|
15
|
-
}>, () => VNode | null, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{
|
|
16
|
-
readonly config: {
|
|
17
|
-
readonly type: _$vue.PropType<RedirectBehaviorConfig>;
|
|
18
|
-
readonly required: true;
|
|
19
|
-
};
|
|
20
|
-
readonly locales: {
|
|
21
|
-
readonly type: _$vue.PropType<RedirectPluginLocaleConfig>;
|
|
22
|
-
readonly required: true;
|
|
23
|
-
};
|
|
24
|
-
}>> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, true, {}, any>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { _default as t };
|
|
27
|
-
//# sourceMappingURL=RedirectModal-B6mWTqIR.d.ts.map
|
|
File without changes
|