sdocs 0.0.11 → 0.0.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/dist/app-gen.js +3 -2
- package/dist/server/snippet-compiler.js +10 -2
- package/package.json +1 -1
package/dist/app-gen.js
CHANGED
|
@@ -58,15 +58,16 @@ 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('./') ? href.slice(1) : href.startsWith('/') || href.startsWith('http') ? href : '/' + href;
|
|
61
62
|
let cssLinks = '';
|
|
62
63
|
if (css) {
|
|
63
64
|
if (typeof css === 'string') {
|
|
64
|
-
cssLinks = `<link rel="stylesheet" href="${css}">`;
|
|
65
|
+
cssLinks = `<link rel="stylesheet" href="${normHref(css)}">`;
|
|
65
66
|
}
|
|
66
67
|
else {
|
|
67
68
|
const names = Object.keys(css);
|
|
68
69
|
cssLinks = names
|
|
69
|
-
.map((name, i) => `<link rel="stylesheet" href="${css[name]}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
|
|
70
|
+
.map((name, i) => `<link rel="stylesheet" href="${normHref(css[name])}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
|
|
70
71
|
.join('\n\t');
|
|
71
72
|
}
|
|
72
73
|
}
|
|
@@ -63,17 +63,25 @@ export function generateIframeComponent(absoluteImports, snippetBody) {
|
|
|
63
63
|
${snippetBody}
|
|
64
64
|
</div>`;
|
|
65
65
|
}
|
|
66
|
+
/** Normalize a CSS path to root-relative so it works inside deeply nested virtual URLs */
|
|
67
|
+
function normalizeCssHref(href) {
|
|
68
|
+
if (href.startsWith('./'))
|
|
69
|
+
return href.slice(1);
|
|
70
|
+
if (href.startsWith('/') || href.startsWith('http'))
|
|
71
|
+
return href;
|
|
72
|
+
return '/' + href;
|
|
73
|
+
}
|
|
66
74
|
/** Generate CSS link tags for the preview HTML */
|
|
67
75
|
function generateCssLinks(css) {
|
|
68
76
|
if (!css)
|
|
69
77
|
return '';
|
|
70
78
|
if (typeof css === 'string') {
|
|
71
|
-
return `<link rel="stylesheet" href="${css}">`;
|
|
79
|
+
return `<link rel="stylesheet" href="${normalizeCssHref(css)}">`;
|
|
72
80
|
}
|
|
73
81
|
// Named stylesheets: first one active, rest disabled
|
|
74
82
|
const names = Object.keys(css);
|
|
75
83
|
return names
|
|
76
|
-
.map((name, i) => `<link rel="stylesheet" href="${css[name]}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
|
|
84
|
+
.map((name, i) => `<link rel="stylesheet" href="${normalizeCssHref(css[name])}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
|
|
77
85
|
.join('\n\t');
|
|
78
86
|
}
|
|
79
87
|
/** Generate the HTML page served inside the iframe */
|