portosaurus 2.1.12 → 3.0.2
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/package.json +1 -1
- package/src/cli/build.mjs +2 -2
- package/src/cli/dev.mjs +2 -2
- package/src/cli/init.mjs +3 -3
- package/src/cli/serve.mjs +1 -1
- package/src/core/buildDocuConfig.mjs +25 -14
- package/src/core/constants.mjs +21 -0
- package/src/plugins/favicon.mjs +5 -1
- package/src/template/config.js +3 -3
- package/src/theme/MDXComponents.js +0 -1
- package/src/utils/{cliHelpers.mjs → cliUtils.mjs} +2 -9
- package/src/utils/configUtils.mjs +34 -21
- package/src/template/notes/index.mdx +0 -9
package/package.json
CHANGED
package/src/cli/build.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
ensureContentDirs,
|
|
7
7
|
writePortoConfigShim,
|
|
8
8
|
runDocusaurus,
|
|
9
|
-
|
|
10
|
-
} from "../
|
|
9
|
+
} from "../utils/cliUtils.mjs";
|
|
10
|
+
import { PortoRoot } from "../core/constants.mjs";
|
|
11
11
|
|
|
12
12
|
export async function buildCommand(siteDir, extraArgs) {
|
|
13
13
|
const UserRoot = siteDir
|
package/src/cli/dev.mjs
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
ensureContentDirs,
|
|
7
7
|
writePortoConfigShim,
|
|
8
8
|
runDocusaurus,
|
|
9
|
-
|
|
10
|
-
} from "../
|
|
9
|
+
} from "../utils/cliUtils.mjs";
|
|
10
|
+
import { PortoRoot } from "../core/constants.mjs";
|
|
11
11
|
|
|
12
12
|
export async function devCommand(siteDir, extraArgs) {
|
|
13
13
|
const UserRoot = siteDir
|
package/src/cli/init.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { logger } from "../utils/logger.mjs";
|
|
4
4
|
import { getPackageManager } from "../utils/packageManager.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { mirrorSync } from "../utils/cliUtils.mjs";
|
|
6
|
+
import { PortoRoot } from "../core/constants.mjs";
|
|
6
7
|
|
|
7
8
|
export async function initCommand(projectName, options) {
|
|
8
9
|
const UsrProjDir = path.resolve(process.cwd(), projectName);
|
|
@@ -116,9 +117,8 @@ export async function initCommand(projectName, options) {
|
|
|
116
117
|
// Install dependencies
|
|
117
118
|
const pm = getPackageManager(UsrProjDir);
|
|
118
119
|
|
|
119
|
-
logger.info(`Installing dependencies with ${pm.name}...`);
|
|
120
|
-
|
|
121
120
|
if (options.install !== false) {
|
|
121
|
+
logger.info(`Installing dependencies with ${pm.name}...`);
|
|
122
122
|
logger.info(`Running ${pm.install}...`);
|
|
123
123
|
try {
|
|
124
124
|
const { execSync } = await import("child_process");
|
package/src/cli/serve.mjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
3
|
import { createRequire } from "module";
|
|
5
|
-
import { logger } from "../utils/logger.mjs";
|
|
6
4
|
|
|
7
5
|
import {
|
|
8
6
|
deepMerge,
|
|
@@ -13,9 +11,7 @@ import {
|
|
|
13
11
|
useEnabled,
|
|
14
12
|
createStaticAssetResolver,
|
|
15
13
|
} from "../utils/configUtils.mjs";
|
|
16
|
-
|
|
17
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
-
const PortoRoot = path.resolve(__dirname, "../../");
|
|
14
|
+
import { PortoRoot } from "./constants.mjs";
|
|
19
15
|
|
|
20
16
|
// ─── Main Config Generator ─────────────────────────────────
|
|
21
17
|
|
|
@@ -43,10 +39,20 @@ export function buildDocuConfig(rawUserConfig, UserRoot) {
|
|
|
43
39
|
// This ensures that even if the user deletes nested fields, the structure remains safe.
|
|
44
40
|
const merged = deepMerge(templateDefaults, UserConfigRaw);
|
|
45
41
|
|
|
46
|
-
//
|
|
42
|
+
// Find Docusaurus root for reference
|
|
43
|
+
let docuRoot = "";
|
|
44
|
+
try {
|
|
45
|
+
docuRoot = path.dirname(require.resolve("@docusaurus/core/package.json"));
|
|
46
|
+
} catch {
|
|
47
|
+
// If not found (e.g. during some build stages), fallback to node_modules relative to PortoRoot
|
|
48
|
+
docuRoot = path.resolve(PortoRoot, "node_modules/@docusaurus/core");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Resolve {{...}} template variables path prefixes in one pass
|
|
47
52
|
const UserConfig = resolveVars(merged, merged, {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
siteRoot: UserRoot,
|
|
54
|
+
portoRoot: PortoRoot,
|
|
55
|
+
docuRoot: docuRoot,
|
|
50
56
|
});
|
|
51
57
|
|
|
52
58
|
// Compute derived values
|
|
@@ -81,16 +87,22 @@ export function buildDocuConfig(rawUserConfig, UserRoot) {
|
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
// Paths for content — these point directly to the user's project
|
|
84
|
-
const UserNotesDir =
|
|
85
|
-
const UserBlogDir =
|
|
90
|
+
const UserNotesDir = "notes";
|
|
91
|
+
const UserBlogDir = "blog";
|
|
86
92
|
|
|
87
|
-
const
|
|
88
|
-
|
|
93
|
+
const PortoFaviconCacheDir = path.resolve(
|
|
94
|
+
UserRoot,
|
|
95
|
+
".docusaurus/portosaurus/favicon",
|
|
89
96
|
);
|
|
90
97
|
|
|
98
|
+
const StaticDirs = [
|
|
99
|
+
UserStaticDir,
|
|
100
|
+
PortoAssetDir,
|
|
101
|
+
PortoFaviconCacheDir,
|
|
102
|
+
].filter((d) => fs.existsSync(d));
|
|
103
|
+
|
|
91
104
|
/**
|
|
92
105
|
* Validates a static asset path with fallback.
|
|
93
|
-
* Aliases (@porto/, @site/) are already resolved globally by resolveAliases().
|
|
94
106
|
* - Remote URLs (http/https) pass through as-is.
|
|
95
107
|
* - Local paths are checked against UserStaticDir, then PortoAssetDir.
|
|
96
108
|
*/
|
|
@@ -99,7 +111,6 @@ export function buildDocuConfig(rawUserConfig, UserRoot) {
|
|
|
99
111
|
PortoAssetDir,
|
|
100
112
|
);
|
|
101
113
|
|
|
102
|
-
|
|
103
114
|
// Pages
|
|
104
115
|
const PortoPagesDir = path.resolve(PortoRoot, "src/theme/pages");
|
|
105
116
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The absolute path to the Portosaurus package root.
|
|
8
|
+
* Calculated relative to this file's location in src/utils/
|
|
9
|
+
*/
|
|
10
|
+
export const PortoRoot = path.resolve(__dirname, "../../");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Common paths inside the framework
|
|
14
|
+
*/
|
|
15
|
+
export const Paths = {
|
|
16
|
+
template: path.join(PortoRoot, "src/template"),
|
|
17
|
+
assets: path.join(PortoRoot, "src/assets"),
|
|
18
|
+
theme: path.join(PortoRoot, "src/theme"),
|
|
19
|
+
core: path.join(PortoRoot, "src/core"),
|
|
20
|
+
plugins: path.join(PortoRoot, "src/plugins"),
|
|
21
|
+
};
|
package/src/plugins/favicon.mjs
CHANGED
|
@@ -63,7 +63,11 @@ export async function generateFavicons(context, options = {}) {
|
|
|
63
63
|
|
|
64
64
|
const staticBaseDir = path.resolve(context.siteDir, "static");
|
|
65
65
|
const imgDir = path.join(staticBaseDir, "img", "svg");
|
|
66
|
-
const outputDir = path.join(
|
|
66
|
+
const outputDir = path.join(
|
|
67
|
+
context.siteDir,
|
|
68
|
+
".docusaurus/portosaurus",
|
|
69
|
+
options.outputPath || "favicon",
|
|
70
|
+
);
|
|
67
71
|
|
|
68
72
|
// --- Smart Caching ---
|
|
69
73
|
const configHash = Buffer.from(
|
package/src/template/config.js
CHANGED
|
@@ -8,8 +8,8 @@ exports.usrConf = {
|
|
|
8
8
|
site_url: "auto",
|
|
9
9
|
site_path: "auto",
|
|
10
10
|
robots_txt: true,
|
|
11
|
-
favicon: "
|
|
12
|
-
social_card: "
|
|
11
|
+
favicon: "{{portoRoot}}/src/assets/img/icon.png", // Default Portosaurus Image
|
|
12
|
+
social_card: "{{portoRoot}}/src/assets/img/social-card.jpeg",
|
|
13
13
|
collapsable_sidebar: true,
|
|
14
14
|
hide_navbar_on_scroll: true,
|
|
15
15
|
disable_theme_switch: false,
|
|
@@ -24,7 +24,7 @@ exports.usrConf = {
|
|
|
24
24
|
profession: "Your Profession",
|
|
25
25
|
description: "Short description about your profession, passion, goals.",
|
|
26
26
|
learn_more_button_txt: "Learn More",
|
|
27
|
-
profile_pic: "
|
|
27
|
+
profile_pic: "{{portoRoot}}/src/assets/img/icon.png",
|
|
28
28
|
},
|
|
29
29
|
|
|
30
30
|
about_me: {
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
3
|
import { spawn } from "child_process";
|
|
5
4
|
import { logger } from "./logger.mjs";
|
|
6
5
|
import { getDocuCmd } from "./packageManager.mjs";
|
|
7
|
-
|
|
8
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
export const PortoRoot = path.resolve(__dirname, "../..");
|
|
6
|
+
import { PortoRoot } from "../core/constants.mjs";
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Write the ephemeral .portosaurus/docusaurus.config.mjs shim.
|
|
@@ -72,11 +69,7 @@ export function ensureContentDirs(UserRoot) {
|
|
|
72
69
|
* Spawn a Docusaurus command and wait for it to complete.
|
|
73
70
|
*/
|
|
74
71
|
export function runDocusaurus(command, extraArgs, UserRoot, configPath) {
|
|
75
|
-
const {
|
|
76
|
-
command: cmd,
|
|
77
|
-
args: pmArgs,
|
|
78
|
-
packageManager,
|
|
79
|
-
} = getDocuCmd(UserRoot);
|
|
72
|
+
const { command: cmd, args: pmArgs, packageManager } = getDocuCmd(UserRoot);
|
|
80
73
|
|
|
81
74
|
logger.info(`Running docusaurus ${command} (via ${packageManager})`);
|
|
82
75
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { logger } from "./logger.mjs";
|
|
4
|
-
import { PortoRoot } from "
|
|
4
|
+
import { PortoRoot } from "../core/constants.mjs";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Deep merge two objects. Source values override target values.
|
|
@@ -34,7 +34,7 @@ export function deepMerge(target, source) {
|
|
|
34
34
|
export function resolveVars(
|
|
35
35
|
obj,
|
|
36
36
|
UserConfig,
|
|
37
|
-
|
|
37
|
+
systemVars = {},
|
|
38
38
|
pathStack = new Set(),
|
|
39
39
|
depth = 0,
|
|
40
40
|
) {
|
|
@@ -46,6 +46,10 @@ export function resolveVars(
|
|
|
46
46
|
|
|
47
47
|
if (singleMatch && !obj.includes("{{", 2)) {
|
|
48
48
|
const refPath = singleMatch[1];
|
|
49
|
+
|
|
50
|
+
// Check system variables first
|
|
51
|
+
if (systemVars[refPath] !== undefined) return systemVars[refPath];
|
|
52
|
+
|
|
49
53
|
const parts = refPath.split(".");
|
|
50
54
|
let val = UserConfig;
|
|
51
55
|
|
|
@@ -54,7 +58,7 @@ export function resolveVars(
|
|
|
54
58
|
val = val[p];
|
|
55
59
|
}
|
|
56
60
|
if (val !== undefined && val !== obj) {
|
|
57
|
-
return resolveVars(val, UserConfig,
|
|
61
|
+
return resolveVars(val, UserConfig, systemVars, pathStack, depth + 1);
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
@@ -63,6 +67,10 @@ export function resolveVars(
|
|
|
63
67
|
/(\\?)\{\{([^}]+)\}\}/g,
|
|
64
68
|
(match, escape, refPath) => {
|
|
65
69
|
if (escape === "\\") return `{{${refPath}}}`;
|
|
70
|
+
|
|
71
|
+
// Support system variables from systemVars
|
|
72
|
+
if (systemVars[refPath] !== undefined) return systemVars[refPath];
|
|
73
|
+
|
|
66
74
|
if (pathStack.has(refPath)) return match;
|
|
67
75
|
|
|
68
76
|
const parts = refPath.split(".");
|
|
@@ -77,40 +85,32 @@ export function resolveVars(
|
|
|
77
85
|
const newStack = new Set(pathStack);
|
|
78
86
|
newStack.add(refPath);
|
|
79
87
|
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
(val.includes("{{") || val.startsWith("@"))
|
|
83
|
-
) {
|
|
84
|
-
return resolveVars(val, UserConfig, aliases, newStack, depth + 1);
|
|
88
|
+
if (typeof val === "string" && val.includes("{{")) {
|
|
89
|
+
return resolveVars(val, UserConfig, systemVars, newStack, depth + 1);
|
|
85
90
|
}
|
|
86
91
|
return val;
|
|
87
92
|
},
|
|
88
93
|
);
|
|
89
94
|
|
|
90
|
-
// Resolve @alias/ path prefixes
|
|
91
|
-
for (const [prefix, dir] of Object.entries(aliases)) {
|
|
92
|
-
if (result.startsWith(prefix)) {
|
|
93
|
-
const relative = result.slice(prefix.length);
|
|
94
|
-
if (dir && !fs.existsSync(path.resolve(dir, relative))) {
|
|
95
|
-
logger.warn(`Asset not found: "${result}"`);
|
|
96
|
-
}
|
|
97
|
-
return relative;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
95
|
return result;
|
|
102
96
|
}
|
|
103
97
|
|
|
104
98
|
if (Array.isArray(obj)) {
|
|
105
99
|
return obj.map((item) =>
|
|
106
|
-
resolveVars(item, UserConfig,
|
|
100
|
+
resolveVars(item, UserConfig, systemVars, pathStack, depth),
|
|
107
101
|
);
|
|
108
102
|
}
|
|
109
103
|
|
|
110
104
|
if (obj && typeof obj === "object") {
|
|
111
105
|
const result = {};
|
|
112
106
|
for (const [key, value] of Object.entries(obj)) {
|
|
113
|
-
result[key] = resolveVars(
|
|
107
|
+
result[key] = resolveVars(
|
|
108
|
+
value,
|
|
109
|
+
UserConfig,
|
|
110
|
+
systemVars,
|
|
111
|
+
pathStack,
|
|
112
|
+
depth,
|
|
113
|
+
);
|
|
114
114
|
}
|
|
115
115
|
return result;
|
|
116
116
|
}
|
|
@@ -208,8 +208,21 @@ export function useEnabled(items) {
|
|
|
208
208
|
*/
|
|
209
209
|
export function createStaticAssetResolver(UserStaticDir, PortoAssetDir) {
|
|
210
210
|
return function resolveStaticAsset(userPath, portoFallback) {
|
|
211
|
+
if (!userPath && !portoFallback) return "";
|
|
211
212
|
if (userPath && /^https?:\/\//.test(userPath)) return userPath;
|
|
212
213
|
|
|
214
|
+
// Handle absolute paths (e.g. from {{portoRoot}} resolution)
|
|
215
|
+
if (userPath && path.isAbsolute(userPath)) {
|
|
216
|
+
if (userPath.startsWith(UserStaticDir)) {
|
|
217
|
+
return path.relative(UserStaticDir, userPath);
|
|
218
|
+
}
|
|
219
|
+
if (userPath.startsWith(PortoAssetDir)) {
|
|
220
|
+
return path.relative(PortoAssetDir, userPath);
|
|
221
|
+
}
|
|
222
|
+
// If absolute but outside our known static dirs, check if it exists
|
|
223
|
+
if (fs.existsSync(userPath)) return userPath;
|
|
224
|
+
}
|
|
225
|
+
|
|
213
226
|
if (userPath && fs.existsSync(path.resolve(UserStaticDir, userPath))) {
|
|
214
227
|
return userPath;
|
|
215
228
|
}
|