@rspress/core 2.0.0-beta.29 → 2.0.0-beta.30
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/395.js +74 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +11 -41
- package/dist/renderPageWorker.js +1 -1
- package/dist/runtime/ClientApp.js +2 -3
- package/dist/runtime/initPageData.js +1 -1
- package/dist/runtime/ssrServerEntry.js +2 -3
- package/package.json +15 -15
- package/dist/220.js +0 -38
package/dist/395.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_buffer_fb286294__ from "node:buffer";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:child_process";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__ from "node:timers/promises";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
|
|
10
|
+
export const __webpack_id__ = "395";
|
|
11
|
+
export const __webpack_ids__ = [
|
|
12
|
+
"395"
|
|
13
|
+
];
|
|
14
|
+
export const __webpack_modules__ = {
|
|
15
|
+
"./src/node/last-updated/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
16
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
17
|
+
pluginLastUpdated: ()=>pluginLastUpdated
|
|
18
|
+
});
|
|
19
|
+
var execa__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../../node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.js");
|
|
20
|
+
function transform(timestamp, lang) {
|
|
21
|
+
return new Date(timestamp).toLocaleString(lang || 'zh');
|
|
22
|
+
}
|
|
23
|
+
async function getGitLastUpdatedTimeStamp(filePath) {
|
|
24
|
+
let lastUpdated;
|
|
25
|
+
try {
|
|
26
|
+
const { stdout } = await (0, execa__WEBPACK_IMPORTED_MODULE_0__.Ho)('git', [
|
|
27
|
+
'log',
|
|
28
|
+
'-1',
|
|
29
|
+
'--format=%at',
|
|
30
|
+
filePath
|
|
31
|
+
]);
|
|
32
|
+
lastUpdated = 1000 * Number(stdout);
|
|
33
|
+
} catch (_e) {}
|
|
34
|
+
return lastUpdated;
|
|
35
|
+
}
|
|
36
|
+
function pluginLastUpdated() {
|
|
37
|
+
return {
|
|
38
|
+
name: '@rspress/plugin-last-updated',
|
|
39
|
+
async extendPageData (pageData) {
|
|
40
|
+
const { _filepath, lang } = pageData;
|
|
41
|
+
const lastUpdated = await getGitLastUpdatedTimeStamp(_filepath);
|
|
42
|
+
if (lastUpdated) pageData.lastUpdatedTime = transform(lastUpdated, lang);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
child_process: function(module) {
|
|
48
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_child_process__;
|
|
49
|
+
},
|
|
50
|
+
fs: function(module) {
|
|
51
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_fs__;
|
|
52
|
+
},
|
|
53
|
+
"node:buffer": function(module) {
|
|
54
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_buffer_fb286294__;
|
|
55
|
+
},
|
|
56
|
+
"node:child_process": function(module) {
|
|
57
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__;
|
|
58
|
+
},
|
|
59
|
+
"node:process": function(module) {
|
|
60
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__;
|
|
61
|
+
},
|
|
62
|
+
"node:timers/promises": function(module) {
|
|
63
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__;
|
|
64
|
+
},
|
|
65
|
+
"node:util": function(module) {
|
|
66
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__;
|
|
67
|
+
},
|
|
68
|
+
path: function(module) {
|
|
69
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
|
|
70
|
+
},
|
|
71
|
+
stream: function(module) {
|
|
72
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_stream__;
|
|
73
|
+
}
|
|
74
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import picocolors from "picocolors";
|
|
|
6
6
|
import { build, dev, serve } from "./index.js";
|
|
7
7
|
import node_fs from "node:fs";
|
|
8
8
|
import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "@rspress/shared/constants";
|
|
9
|
-
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.
|
|
9
|
+
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.30"}');
|
|
10
10
|
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
|
|
11
11
|
async function loadConfigFile(customConfigFile) {
|
|
12
12
|
const baseDir = process.cwd();
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
3
|
-
import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
|
|
4
|
-
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
5
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_buffer_fb286294__ from "node:buffer";
|
|
6
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__ from "node:child_process";
|
|
7
3
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
8
4
|
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
9
5
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
10
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__ from "node:process";
|
|
11
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__ from "node:timers/promises";
|
|
12
6
|
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
13
|
-
import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
|
|
14
|
-
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
15
|
-
import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
|
|
16
7
|
import { matchPath } from "@rspress/runtime/server";
|
|
17
8
|
import { logger } from "@rspress/shared/logger";
|
|
18
9
|
import { extractTextAndId, getIconUrlPath, getNodeAttribute, loadFrontMatter, mergeDocConfig } from "@rspress/shared/node-utils";
|
|
@@ -35,18 +26,6 @@ var __webpack_modules__ = {
|
|
|
35
26
|
"@rspress/shared": function(module) {
|
|
36
27
|
module.exports = __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__;
|
|
37
28
|
},
|
|
38
|
-
child_process: function(module) {
|
|
39
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_child_process__;
|
|
40
|
-
},
|
|
41
|
-
fs: function(module) {
|
|
42
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_fs__;
|
|
43
|
-
},
|
|
44
|
-
"node:buffer": function(module) {
|
|
45
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_buffer_fb286294__;
|
|
46
|
-
},
|
|
47
|
-
"node:child_process": function(module) {
|
|
48
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_child_process_27f17141__;
|
|
49
|
-
},
|
|
50
29
|
"node:fs": function(module) {
|
|
51
30
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__;
|
|
52
31
|
},
|
|
@@ -56,23 +35,8 @@ var __webpack_modules__ = {
|
|
|
56
35
|
"node:path": function(module) {
|
|
57
36
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__;
|
|
58
37
|
},
|
|
59
|
-
"node:process": function(module) {
|
|
60
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_process_786449bf__;
|
|
61
|
-
},
|
|
62
|
-
"node:timers/promises": function(module) {
|
|
63
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_timers_promises_aedbf14c__;
|
|
64
|
-
},
|
|
65
38
|
"node:url": function(module) {
|
|
66
39
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__;
|
|
67
|
-
},
|
|
68
|
-
"node:util": function(module) {
|
|
69
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__;
|
|
70
|
-
},
|
|
71
|
-
path: function(module) {
|
|
72
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
|
|
73
|
-
},
|
|
74
|
-
stream: function(module) {
|
|
75
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE_stream__;
|
|
76
40
|
}
|
|
77
41
|
};
|
|
78
42
|
var __webpack_module_cache__ = {};
|
|
@@ -150,7 +114,7 @@ function defineConfig(config) {
|
|
|
150
114
|
}
|
|
151
115
|
var external_node_path_ = __webpack_require__("node:path");
|
|
152
116
|
var external_node_url_ = __webpack_require__("node:url");
|
|
153
|
-
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.
|
|
117
|
+
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.30"}');
|
|
154
118
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
155
119
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
156
120
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
@@ -964,9 +928,11 @@ function getI18nData(docConfig) {
|
|
|
964
928
|
const i18nVMPlugin = (context)=>{
|
|
965
929
|
const { config } = context;
|
|
966
930
|
return {
|
|
967
|
-
["virtual-i18n-text"]: ({ addDependency, addMissingDependency })=>{
|
|
968
|
-
|
|
969
|
-
|
|
931
|
+
["virtual-i18n-text"]: async ({ addDependency, addMissingDependency })=>{
|
|
932
|
+
const configPath = config.i18nSourcePath || DEFAULT_I18N_SOURCE;
|
|
933
|
+
const isExist = await pathExists(configPath);
|
|
934
|
+
if (isExist) addDependency(configPath);
|
|
935
|
+
else addMissingDependency(configPath);
|
|
970
936
|
const i18nData = getI18nData(config);
|
|
971
937
|
return `export default ${JSON.stringify(i18nData, null, 2)}`;
|
|
972
938
|
}
|
|
@@ -2099,6 +2065,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
2099
2065
|
routeService,
|
|
2100
2066
|
pluginDriver
|
|
2101
2067
|
}).end();
|
|
2068
|
+
chain.experiments({
|
|
2069
|
+
...chain.get('experiments'),
|
|
2070
|
+
nativeWatcher: 'false' !== process.env.RSPRESS_NATIVE_WATCHER
|
|
2071
|
+
});
|
|
2102
2072
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((options)=>{
|
|
2103
2073
|
options[0] ??= {};
|
|
2104
2074
|
options[0].include = [
|
|
@@ -2223,7 +2193,7 @@ class PluginDriver {
|
|
|
2223
2193
|
if (enableLastUpdated) {
|
|
2224
2194
|
const { pluginLastUpdated } = await Promise.all([
|
|
2225
2195
|
__webpack_require__.e("101"),
|
|
2226
|
-
__webpack_require__.e("
|
|
2196
|
+
__webpack_require__.e("395")
|
|
2227
2197
|
]).then(__webpack_require__.bind(__webpack_require__, "./src/node/last-updated/index.ts"));
|
|
2228
2198
|
this.addPlugin(pluginLastUpdated());
|
|
2229
2199
|
}
|
package/dist/renderPageWorker.js
CHANGED
|
@@ -102,7 +102,7 @@ function hintSSGFailed() {
|
|
|
102
102
|
1. Fix code to make it SSR-compatible.
|
|
103
103
|
2. Set \`ssg: false\` if the code in node_modules may be difficult to fix, but the SSG feature will be lost.`);
|
|
104
104
|
}
|
|
105
|
-
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.
|
|
105
|
+
var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.30"}');
|
|
106
106
|
const RSPRESS_VERSION = package_namespaceObject.rE;
|
|
107
107
|
`{
|
|
108
108
|
const saved = localStorage.getItem('${APPEARANCE_KEY}')
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { BrowserRouter, PageContext, ThemeContext } from "@rspress/runtime";
|
|
2
|
+
import { BrowserRouter, PageContext, ThemeContext, removeTrailingSlash, withBase } from "@rspress/runtime";
|
|
3
3
|
import { useThemeState } from "@theme";
|
|
4
4
|
import { UnheadProvider, createHead } from "@unhead/react/client";
|
|
5
5
|
import { useMemo, useState } from "react";
|
|
6
|
-
import virtual_site_data from "virtual-site-data";
|
|
7
6
|
import { App } from "./App.js";
|
|
8
7
|
const head = createHead();
|
|
9
8
|
function ClientApp({ initialPageData = null }) {
|
|
@@ -30,7 +29,7 @@ function ClientApp({ initialPageData = null }) {
|
|
|
30
29
|
v7_relativeSplatPath: true,
|
|
31
30
|
v7_startTransition: true
|
|
32
31
|
},
|
|
33
|
-
basename:
|
|
32
|
+
basename: removeTrailingSlash(withBase('/')),
|
|
34
33
|
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
35
34
|
head: head,
|
|
36
35
|
children: /*#__PURE__*/ jsx(App, {})
|
|
@@ -25,7 +25,7 @@ async function initPageData(routePath) {
|
|
|
25
25
|
let lang = virtual_site_data.lang || '';
|
|
26
26
|
let version = virtual_site_data.multiVersion?.default || '';
|
|
27
27
|
if (virtual_site_data.lang && 'undefined' != typeof window) {
|
|
28
|
-
const path = location.pathname.replace(virtual_site_data.base, '').split('/').slice(0, 2);
|
|
28
|
+
const path = window.location.pathname.replace(virtual_site_data.base, '').split('/').slice(0, 2);
|
|
29
29
|
if (virtual_site_data.locales.length) {
|
|
30
30
|
const result = virtual_site_data.locales.find(({ lang })=>path.includes(lang));
|
|
31
31
|
if (result) lang = result.lang;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { PassThrough } from "node:stream";
|
|
3
3
|
import { text as consumers_text } from "node:stream/consumers";
|
|
4
|
-
import { PageContext, ThemeContext, pathnameToRouteService, withBase } from "@rspress/runtime";
|
|
4
|
+
import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/runtime";
|
|
5
5
|
import { StaticRouter } from "@rspress/runtime/server";
|
|
6
6
|
import { UnheadProvider } from "@unhead/react/server";
|
|
7
7
|
import { renderToPipeableStream } from "react-dom/server";
|
|
8
|
-
import virtual_site_data from "virtual-site-data";
|
|
9
8
|
import { App } from "./App.js";
|
|
10
9
|
import { initPageData } from "./initPageData.js";
|
|
11
10
|
import { routes } from "virtual-routes";
|
|
@@ -41,7 +40,7 @@ async function render(routePath, head) {
|
|
|
41
40
|
},
|
|
42
41
|
children: /*#__PURE__*/ jsx(StaticRouter, {
|
|
43
42
|
location: withBase(routePath),
|
|
44
|
-
basename:
|
|
43
|
+
basename: removeTrailingSlash(withBase('/')),
|
|
45
44
|
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
46
45
|
value: head,
|
|
47
46
|
children: /*#__PURE__*/ jsx(App, {})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.30",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"index.html"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@mdx-js/mdx": "^3.1.
|
|
55
|
-
"@mdx-js/react": "^3.1.
|
|
56
|
-
"@rsbuild/core": "~1.
|
|
57
|
-
"@rsbuild/plugin-react": "~1.
|
|
54
|
+
"@mdx-js/mdx": "^3.1.1",
|
|
55
|
+
"@mdx-js/react": "^3.1.1",
|
|
56
|
+
"@rsbuild/core": "~1.5.3",
|
|
57
|
+
"@rsbuild/plugin-react": "~1.4.0",
|
|
58
58
|
"@rspress/mdx-rs": "0.6.6",
|
|
59
|
-
"@shikijs/rehype": "^3.
|
|
59
|
+
"@shikijs/rehype": "^3.12.0",
|
|
60
60
|
"@types/unist": "^3.0.3",
|
|
61
61
|
"@unhead/react": "^2.0.14",
|
|
62
62
|
"cac": "^6.7.14",
|
|
@@ -76,36 +76,36 @@
|
|
|
76
76
|
"rehype-external-links": "^3.0.0",
|
|
77
77
|
"rehype-raw": "^7.0.0",
|
|
78
78
|
"remark-gfm": "^4.0.1",
|
|
79
|
-
"shiki": "^3.
|
|
79
|
+
"shiki": "^3.12.0",
|
|
80
80
|
"tinyglobby": "^0.2.14",
|
|
81
81
|
"tinypool": "^1.1.1",
|
|
82
82
|
"unified": "^11.0.5",
|
|
83
83
|
"unist-util-visit": "^5.0.0",
|
|
84
84
|
"unist-util-visit-children": "^3.0.0",
|
|
85
|
-
"@rspress/runtime": "2.0.0-beta.
|
|
86
|
-
"@rspress/
|
|
87
|
-
"@rspress/
|
|
85
|
+
"@rspress/runtime": "2.0.0-beta.30",
|
|
86
|
+
"@rspress/shared": "2.0.0-beta.30",
|
|
87
|
+
"@rspress/theme-default": "2.0.0-beta.30"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@microsoft/api-extractor": "^7.52.11",
|
|
91
|
-
"@rslib/core": "0.12.
|
|
91
|
+
"@rslib/core": "0.12.4",
|
|
92
92
|
"@types/hast": "^3.0.4",
|
|
93
93
|
"@types/html-to-text": "^9.0.4",
|
|
94
94
|
"@types/jest": "~29.5.14",
|
|
95
95
|
"@types/lodash-es": "^4.17.12",
|
|
96
96
|
"@types/mdast": "^4.0.4",
|
|
97
97
|
"@types/node": "^22.8.1",
|
|
98
|
-
"@types/react": "^19.1.
|
|
99
|
-
"@types/react-dom": "^19.1.
|
|
98
|
+
"@types/react": "^19.1.12",
|
|
99
|
+
"@types/react-dom": "^19.1.9",
|
|
100
100
|
"execa": "8.0.1",
|
|
101
101
|
"mdast-util-directive": "^3.1.0",
|
|
102
102
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
103
|
-
"memfs": "^4.38.
|
|
103
|
+
"memfs": "^4.38.2",
|
|
104
104
|
"p-map": "^7.0.3",
|
|
105
105
|
"postcss": "8.5.6",
|
|
106
106
|
"rehype-stringify": "^10.0.1",
|
|
107
107
|
"remark-directive": "^4.0.0",
|
|
108
|
-
"remark-mdx": "^3.1.
|
|
108
|
+
"remark-mdx": "^3.1.1",
|
|
109
109
|
"remark-parse": "^11.0.0",
|
|
110
110
|
"remark-rehype": "^11.1.2",
|
|
111
111
|
"remark-stringify": "^11.0.0",
|
package/dist/220.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export const __webpack_id__ = "220";
|
|
2
|
-
export const __webpack_ids__ = [
|
|
3
|
-
"220"
|
|
4
|
-
];
|
|
5
|
-
export const __webpack_modules__ = {
|
|
6
|
-
"./src/node/last-updated/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
7
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
8
|
-
pluginLastUpdated: ()=>pluginLastUpdated
|
|
9
|
-
});
|
|
10
|
-
var execa__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../../node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.js");
|
|
11
|
-
function transform(timestamp, lang) {
|
|
12
|
-
return new Date(timestamp).toLocaleString(lang || 'zh');
|
|
13
|
-
}
|
|
14
|
-
async function getGitLastUpdatedTimeStamp(filePath) {
|
|
15
|
-
let lastUpdated;
|
|
16
|
-
try {
|
|
17
|
-
const { stdout } = await (0, execa__WEBPACK_IMPORTED_MODULE_0__.Ho)('git', [
|
|
18
|
-
'log',
|
|
19
|
-
'-1',
|
|
20
|
-
'--format=%at',
|
|
21
|
-
filePath
|
|
22
|
-
]);
|
|
23
|
-
lastUpdated = 1000 * Number(stdout);
|
|
24
|
-
} catch (_e) {}
|
|
25
|
-
return lastUpdated;
|
|
26
|
-
}
|
|
27
|
-
function pluginLastUpdated() {
|
|
28
|
-
return {
|
|
29
|
-
name: '@rspress/plugin-last-updated',
|
|
30
|
-
async extendPageData (pageData) {
|
|
31
|
-
const { _filepath, lang } = pageData;
|
|
32
|
-
const lastUpdated = await getGitLastUpdatedTimeStamp(_filepath);
|
|
33
|
-
if (lastUpdated) pageData.lastUpdatedTime = transform(lastUpdated, lang);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|