@vuepress/plugin-redirect 2.0.0-rc.10 → 2.0.0-rc.12
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/client/config.d.ts +1 -0
- package/lib/client/config.js +1 -0
- package/lib/client/styles/language-switch.css +8 -8
- package/lib/client/styles/vars.css +10 -0
- package/lib/node/ensureRootHomePage.d.ts +1 -2
- package/lib/node/ensureRootHomePage.js +3 -56
- package/lib/node/generate/getLocaleRedirectHTML.js +1 -1
- package/lib/node/generate/getRedirectHTML.js +1 -1
- package/lib/node/redirectPlugin.js +2 -2
- package/package.json +4 -4
package/lib/client/config.d.ts
CHANGED
package/lib/client/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineClientConfig } from 'vuepress/client';
|
|
2
2
|
import LanguageSwitch from './components/LanguageSwitch.js';
|
|
3
3
|
import { setupDevServerRedirect } from './composables/setupDevServerRedirect.js';
|
|
4
|
+
import './styles/vars.css';
|
|
4
5
|
export default defineClientConfig({
|
|
5
6
|
setup() {
|
|
6
7
|
if (__VUEPRESS_DEV__)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
.lang-modal-mask {
|
|
12
12
|
position: fixed;
|
|
13
13
|
inset: 0;
|
|
14
|
-
z-index:
|
|
14
|
+
z-index: var(--redirect-z-index);
|
|
15
15
|
display: flex;
|
|
16
16
|
align-items: center;
|
|
17
17
|
justify-content: center;
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
max-width: 80vw;
|
|
31
31
|
padding: 1rem 2rem;
|
|
32
32
|
border-radius: 8px;
|
|
33
|
-
background: var(--
|
|
33
|
+
background: var(--redirect-bg-color);
|
|
34
34
|
box-shadow: 0 2px 6px 0 var(--card-shadow);
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
padding: 0.5rem 0.75rem;
|
|
42
42
|
border: none;
|
|
43
43
|
border-radius: 8px;
|
|
44
|
-
background-color: var(--
|
|
45
|
-
color:
|
|
44
|
+
background-color: var(--redirect-bg-color-lighter);
|
|
45
|
+
color: inherit;
|
|
46
46
|
cursor: pointer;
|
|
47
47
|
}
|
|
48
48
|
.lang-modal-action:hover {
|
|
49
|
-
background-color: var(--
|
|
49
|
+
background-color: var(--redirect-bg-color-light);
|
|
50
50
|
}
|
|
51
51
|
.lang-modal-action.primary {
|
|
52
|
-
background-color: var(--
|
|
53
|
-
color: var(--
|
|
52
|
+
background-color: var(--redirect-primary-color);
|
|
53
|
+
color: var(--redirect-primary-text-color);
|
|
54
54
|
}
|
|
55
55
|
.lang-modal-action.primary:hover {
|
|
56
|
-
background-color: var(--
|
|
56
|
+
background-color: var(--redirect-primary-hover-color);
|
|
57
57
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--redirect-z-index: 1499;
|
|
3
|
+
--redirect-bg-color: #fff;
|
|
4
|
+
--redirect-bg-color-light: #f3f4f5;
|
|
5
|
+
--redirect-bg-color-lighter: #eeeeee;
|
|
6
|
+
--redirect-text-color: #2c3e50;
|
|
7
|
+
--redirect-primary-bg-color: #3eaf7c;
|
|
8
|
+
--redirect-primary-hover-bg-color: #4abf8a;
|
|
9
|
+
--redirect-primary-text-color: #fff;
|
|
10
|
+
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import type { App } from 'vuepress/core';
|
|
2
|
-
|
|
3
|
-
export declare const ensureRootHomePage: (app: App, localeOptions: RedirectLocaleConfig) => Promise<void>;
|
|
2
|
+
export declare const ensureRootHomePage: (app: App) => Promise<void>;
|
|
@@ -1,67 +1,14 @@
|
|
|
1
|
-
import { removeEndingSlash } from '@vuepress/helper';
|
|
2
1
|
import { createPage } from 'vuepress/core';
|
|
3
|
-
export const ensureRootHomePage = async (app
|
|
4
|
-
const { options: { base }, pages, } = app;
|
|
2
|
+
export const ensureRootHomePage = async (app) => {
|
|
5
3
|
if (
|
|
6
4
|
// root homepage not exists
|
|
7
|
-
pages.every(({ path }) => path !== '/')) {
|
|
8
|
-
|
|
9
|
-
.filter(({ pathLocale, path }) => pathLocale === path)
|
|
10
|
-
.map(({ pathLocale }) => pathLocale);
|
|
11
|
-
pages.push(await createPage(app, {
|
|
5
|
+
app.pages.every(({ path }) => path !== '/')) {
|
|
6
|
+
app.pages.push(await createPage(app, {
|
|
12
7
|
path: '/',
|
|
13
8
|
frontmatter: { title: 'Home' },
|
|
14
9
|
// set markdown content
|
|
15
10
|
content: `\
|
|
16
11
|
Redirecting to the correct locale...
|
|
17
|
-
|
|
18
|
-
<script setup>
|
|
19
|
-
import { onMounted } from "vue";
|
|
20
|
-
|
|
21
|
-
if(!__VUEPRESS_DEV__)
|
|
22
|
-
onMounted(() => {
|
|
23
|
-
const { languages } = window.navigator;
|
|
24
|
-
const { hash, origin } = window.location;
|
|
25
|
-
const anchor = hash.substring(1);
|
|
26
|
-
|
|
27
|
-
const localeConfig = ${JSON.stringify(localeOptions.localeConfig)};
|
|
28
|
-
const availableLocales = ${JSON.stringify(availableLocales)};
|
|
29
|
-
const defaultLocale = availableLocales.pop();
|
|
30
|
-
|
|
31
|
-
let matchedLocalePath = null;
|
|
32
|
-
|
|
33
|
-
// get matched locale
|
|
34
|
-
findLanguage:
|
|
35
|
-
for (const lang of languages)
|
|
36
|
-
for (const [localePath, langs] of Object.entries(localeConfig))
|
|
37
|
-
if (langs.includes(lang)) {
|
|
38
|
-
${localeOptions.localeFallback
|
|
39
|
-
? `\
|
|
40
|
-
if (!availableLocales.includes(localePath))
|
|
41
|
-
continue;
|
|
42
|
-
`
|
|
43
|
-
: ``}\
|
|
44
|
-
matchedLocalePath = localePath;
|
|
45
|
-
break findLanguage;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// default link
|
|
49
|
-
const defaultLink = defaultLocale? \`\${origin}${removeEndingSlash(base)}\${defaultLocale}\${anchor? \`#\${anchor}\`: ""}\`: null;
|
|
50
|
-
|
|
51
|
-
// a locale homepage exists
|
|
52
|
-
if (matchedLocalePath && availableLocales.includes(matchedLocalePath)) {
|
|
53
|
-
location.href = \`\${origin}${removeEndingSlash(base)}\${matchedLocalePath}\${anchor? \`#\${anchor}\`: ""}\`;
|
|
54
|
-
}
|
|
55
|
-
// we have a default page
|
|
56
|
-
else if (defaultLink) {
|
|
57
|
-
location.href = defaultLink;
|
|
58
|
-
}
|
|
59
|
-
// no homepage? WTF, just go to 404
|
|
60
|
-
else {
|
|
61
|
-
location.href = \`\${origin}${removeEndingSlash(base)}/404.html\`;
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
</script>
|
|
65
12
|
`,
|
|
66
13
|
}));
|
|
67
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { removeEndingSlash } from '@vuepress/helper';
|
|
2
|
-
export const getLocaleRedirectHTML = ({ localeConfig, defaultBehavior, defaultLocale, localeFallback, }, availableLocales, base) => `<!
|
|
2
|
+
export const getLocaleRedirectHTML = ({ localeConfig, defaultBehavior, defaultLocale, localeFallback, }, availableLocales, base) => `<!doctype html>
|
|
3
3
|
<html lang="en">
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8">
|
|
@@ -35,8 +35,8 @@ export const redirectPlugin = (options = {}) => (app) => {
|
|
|
35
35
|
redirectMap = getRedirectMap(app, options);
|
|
36
36
|
if (app.env.isDebug)
|
|
37
37
|
logger.info('Redirect Map:', redirectMap);
|
|
38
|
-
if (redirectLocaleConfig.autoLocale)
|
|
39
|
-
await ensureRootHomePage(app
|
|
38
|
+
if (redirectLocaleConfig.autoLocale && app.env.isDebug)
|
|
39
|
+
await ensureRootHomePage(app);
|
|
40
40
|
},
|
|
41
41
|
onPrepared: async (app) => {
|
|
42
42
|
await app.writeTemp('redirect/map.js', `\
|
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.12",
|
|
4
4
|
"description": "VuePress plugin - redirect",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vuepress-plugin",
|
|
@@ -42,17 +42,17 @@
|
|
|
42
42
|
"style": "sass src:lib --no-source-map"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@vuepress/helper": "~2.0.0-rc.
|
|
45
|
+
"@vuepress/helper": "~2.0.0-rc.12",
|
|
46
46
|
"@vueuse/core": "^10.7.2",
|
|
47
47
|
"cac": "^6.7.14",
|
|
48
48
|
"vue": "^3.4.15",
|
|
49
49
|
"vue-router": "^4.2.5"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"vuepress": "2.0.0-rc.
|
|
52
|
+
"vuepress": "2.0.0-rc.7"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "ec1ce0f857e9b05bee848bedcfb395a00bdda4c6"
|
|
58
58
|
}
|