sdocs 0.0.12 → 0.0.13
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/app-gen.js +1 -1
- package/dist/config.js +16 -1
- package/dist/server/snippet-compiler.js +5 -4
- package/package.json +1 -1
package/dist/app-gen.js
CHANGED
|
@@ -58,7 +58,7 @@ mount(App, {
|
|
|
58
58
|
}
|
|
59
59
|
/** Generate a preview HTML page for an iframe snippet */
|
|
60
60
|
function generatePreviewHtml(iframeVirtualId, css) {
|
|
61
|
-
const normHref = (href) => href.startsWith('
|
|
61
|
+
const normHref = (href) => href.startsWith('http') ? href : href.startsWith('/') ? `/@fs${href}` : '/' + href;
|
|
62
62
|
let cssLinks = '';
|
|
63
63
|
if (css) {
|
|
64
64
|
if (typeof css === 'string') {
|
package/dist/config.js
CHANGED
|
@@ -22,13 +22,28 @@ export function findConfigFile(root) {
|
|
|
22
22
|
}
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
+
/** Resolve CSS paths to absolute filesystem paths */
|
|
26
|
+
function resolveCssPaths(css, root) {
|
|
27
|
+
if (!css)
|
|
28
|
+
return null;
|
|
29
|
+
if (typeof css === 'string') {
|
|
30
|
+
return css.startsWith('/') || css.startsWith('http') ? css : resolve(root, css);
|
|
31
|
+
}
|
|
32
|
+
const resolved = {};
|
|
33
|
+
for (const [name, href] of Object.entries(css)) {
|
|
34
|
+
resolved[name] = href.startsWith('/') || href.startsWith('http') ? href : resolve(root, href);
|
|
35
|
+
}
|
|
36
|
+
return resolved;
|
|
37
|
+
}
|
|
25
38
|
/** Load and resolve the sdocs config with defaults */
|
|
26
39
|
export async function loadConfig(root) {
|
|
27
40
|
const configPath = findConfigFile(root);
|
|
28
41
|
if (!configPath)
|
|
29
42
|
return { ...DEFAULTS };
|
|
30
43
|
const userConfig = await importConfig(configPath);
|
|
31
|
-
|
|
44
|
+
const resolved = resolveConfig(userConfig);
|
|
45
|
+
resolved.css = resolveCssPaths(resolved.css, root);
|
|
46
|
+
return resolved;
|
|
32
47
|
}
|
|
33
48
|
/** Import a config file (supports .js, .mjs, .ts via Vite) */
|
|
34
49
|
async function importConfig(configPath) {
|
|
@@ -63,12 +63,13 @@ export function generateIframeComponent(absoluteImports, snippetBody) {
|
|
|
63
63
|
${snippetBody}
|
|
64
64
|
</div>`;
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
66
|
+
/** Convert a CSS path to a Vite-servable URL */
|
|
67
67
|
function normalizeCssHref(href) {
|
|
68
|
-
if (href.startsWith('
|
|
69
|
-
return href.slice(1);
|
|
70
|
-
if (href.startsWith('/') || href.startsWith('http'))
|
|
68
|
+
if (href.startsWith('http'))
|
|
71
69
|
return href;
|
|
70
|
+
// Absolute filesystem path → use Vite's /@fs/ prefix
|
|
71
|
+
if (href.startsWith('/'))
|
|
72
|
+
return `/@fs${href}`;
|
|
72
73
|
return '/' + href;
|
|
73
74
|
}
|
|
74
75
|
/** Generate CSS link tags for the preview HTML */
|