@rspress/shared 0.1.1 → 0.2.0
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/index.d.ts +35 -1
- package/dist/index.js +23 -13
- package/dist/index.mjs +22 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -126,6 +126,10 @@ interface Config$1 {
|
|
126
126
|
* Whether to hide the navbar
|
127
127
|
*/
|
128
128
|
hideNavbar?: boolean;
|
129
|
+
/**
|
130
|
+
* Whether to enable the animation for translation pages
|
131
|
+
*/
|
132
|
+
enableContentAnimation?: boolean;
|
129
133
|
}
|
130
134
|
/**
|
131
135
|
* locale config
|
@@ -339,6 +343,7 @@ interface RouteMeta {
|
|
339
343
|
relativePath: string;
|
340
344
|
pageName: string;
|
341
345
|
lang: string;
|
346
|
+
version: string;
|
342
347
|
}
|
343
348
|
interface ReplaceRule {
|
344
349
|
search: string | RegExp;
|
@@ -455,12 +460,29 @@ interface UserConfig<ThemeConfig = Config$1> {
|
|
455
460
|
* Add some extra builder plugins
|
456
461
|
*/
|
457
462
|
builderPlugins?: BuilderPlugin[];
|
463
|
+
/**
|
464
|
+
* Multi version config
|
465
|
+
*/
|
466
|
+
multiVersion?: {
|
467
|
+
/**
|
468
|
+
* The default version
|
469
|
+
*/
|
470
|
+
default?: string;
|
471
|
+
/**
|
472
|
+
* The version list, such as ['v1', 'v2']
|
473
|
+
*/
|
474
|
+
versions: string[];
|
475
|
+
};
|
458
476
|
}
|
459
477
|
type BaseRuntimePageInfo = Omit<PageIndexInfo, 'id' | 'content' | 'domain'>;
|
460
478
|
interface SiteData<ThemeConfig = NormalizedConfig> {
|
461
479
|
root: string;
|
462
480
|
base: string;
|
463
481
|
lang: string;
|
482
|
+
locales: {
|
483
|
+
lang: string;
|
484
|
+
label: string;
|
485
|
+
}[];
|
464
486
|
title: string;
|
465
487
|
description: string;
|
466
488
|
icon: string;
|
@@ -474,6 +496,10 @@ interface SiteData<ThemeConfig = NormalizedConfig> {
|
|
474
496
|
markdown: {
|
475
497
|
showLineNumbers: boolean;
|
476
498
|
};
|
499
|
+
multiVersion: {
|
500
|
+
default: string;
|
501
|
+
versions: string[];
|
502
|
+
};
|
477
503
|
}
|
478
504
|
type PageIndexInfo = {
|
479
505
|
id: number;
|
@@ -483,6 +509,7 @@ type PageIndexInfo = {
|
|
483
509
|
content: string;
|
484
510
|
frontmatter: Record<string, unknown>;
|
485
511
|
lang: string;
|
512
|
+
version: string;
|
486
513
|
domain: string;
|
487
514
|
_filepath: string;
|
488
515
|
_relativePath: string;
|
@@ -616,7 +643,14 @@ declare function removeLeadingSlash(url: string): string;
|
|
616
643
|
declare function removeTrailingSlash(url: string): string;
|
617
644
|
declare function normalizeSlash(url: string): string;
|
618
645
|
declare function isExternalUrl(url: string): boolean;
|
619
|
-
declare function replaceLang(rawUrl: string,
|
646
|
+
declare function replaceLang(rawUrl: string, lang: {
|
647
|
+
current: string;
|
648
|
+
target: string;
|
649
|
+
default: string;
|
650
|
+
}, version: {
|
651
|
+
current: string;
|
652
|
+
default: string;
|
653
|
+
}, base?: string): string;
|
620
654
|
declare const omit: (obj: Record<string, unknown>, keys: string[]) => {
|
621
655
|
[x: string]: unknown;
|
622
656
|
};
|
package/dist/index.js
CHANGED
@@ -1159,26 +1159,36 @@ function normalizeSlash(url) {
|
|
1159
1159
|
function isExternalUrl(url) {
|
1160
1160
|
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
|
1161
1161
|
}
|
1162
|
-
function replaceLang(rawUrl,
|
1162
|
+
function replaceLang(rawUrl, lang, version, base = "") {
|
1163
1163
|
let url = removeBase(rawUrl, base);
|
1164
1164
|
if (!url) {
|
1165
1165
|
url = "/index.html";
|
1166
1166
|
}
|
1167
|
-
|
1168
|
-
|
1169
|
-
let
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1167
|
+
let versionPart = "";
|
1168
|
+
let langPart = "";
|
1169
|
+
let purePathPart = "";
|
1170
|
+
const parts = url.split("/").filter(Boolean);
|
1171
|
+
if (version.current && version.current !== version.default) {
|
1172
|
+
versionPart = parts.shift() || "";
|
1173
|
+
}
|
1174
|
+
if (lang.target !== lang.default) {
|
1175
|
+
langPart = lang.target;
|
1176
|
+
if (lang.current !== lang.default) {
|
1177
|
+
parts.shift();
|
1175
1178
|
}
|
1176
|
-
} else if (targetLang === defaultLang) {
|
1177
|
-
result = url.replace(`/${originalLang}`, "");
|
1178
1179
|
} else {
|
1179
|
-
|
1180
|
+
parts.shift();
|
1181
|
+
}
|
1182
|
+
purePathPart = parts.join("/") || "";
|
1183
|
+
if ((versionPart || langPart) && !purePathPart) {
|
1184
|
+
purePathPart = "index.html";
|
1180
1185
|
}
|
1181
|
-
return withBase(
|
1186
|
+
return withBase(
|
1187
|
+
addLeadingSlash(
|
1188
|
+
[versionPart, langPart, purePathPart].filter(Boolean).join("/")
|
1189
|
+
),
|
1190
|
+
base
|
1191
|
+
);
|
1182
1192
|
}
|
1183
1193
|
var omit = (obj, keys) => {
|
1184
1194
|
const ret = { ...obj };
|
package/dist/index.mjs
CHANGED
@@ -1113,26 +1113,35 @@ function normalizeSlash(url) {
|
|
1113
1113
|
function isExternalUrl(url) {
|
1114
1114
|
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:") || url.startsWith("tel:");
|
1115
1115
|
}
|
1116
|
-
function replaceLang(rawUrl,
|
1116
|
+
function replaceLang(rawUrl, lang, version, base = "") {
|
1117
1117
|
let url = removeBase(rawUrl, base);
|
1118
1118
|
if (!url) {
|
1119
1119
|
url = "/index.html";
|
1120
1120
|
}
|
1121
|
-
|
1122
|
-
|
1123
|
-
let
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1121
|
+
let versionPart = "";
|
1122
|
+
let langPart = "";
|
1123
|
+
let purePathPart = "";
|
1124
|
+
const parts = url.split("/").filter(Boolean);
|
1125
|
+
if (version.current && version.current !== version.default) {
|
1126
|
+
versionPart = parts.shift() || "";
|
1127
|
+
}
|
1128
|
+
if (lang.target !== lang.default) {
|
1129
|
+
langPart = lang.target;
|
1130
|
+
if (lang.current !== lang.default) {
|
1131
|
+
parts.shift();
|
1129
1132
|
}
|
1130
|
-
} else if (targetLang === defaultLang) {
|
1131
|
-
result = url.replace(`/${originalLang}`, "");
|
1132
1133
|
} else {
|
1133
|
-
|
1134
|
+
parts.shift();
|
1135
|
+
}
|
1136
|
+
purePathPart = parts.join("/") || "";
|
1137
|
+
if ((versionPart || langPart) && !purePathPart) {
|
1138
|
+
purePathPart = "index.html";
|
1134
1139
|
}
|
1135
|
-
return withBase(
|
1140
|
+
return withBase(addLeadingSlash([
|
1141
|
+
versionPart,
|
1142
|
+
langPart,
|
1143
|
+
purePathPart
|
1144
|
+
].filter(Boolean).join("/")), base);
|
1136
1145
|
}
|
1137
1146
|
var omit = (obj, keys) => {
|
1138
1147
|
const ret = {
|