@see-ms/converter 1.1.0 → 1.1.1

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.mjs CHANGED
@@ -25,6 +25,17 @@ function normalizeAssetUrl(value) {
25
25
  return value;
26
26
  }
27
27
  }
28
+ function normalizePublicAssetPath(src) {
29
+ if (!src || /^(https?:)?\/\//i.test(src) || src.startsWith("data:")) {
30
+ return src;
31
+ }
32
+ let normalized = normalizeAssetUrl(src).replace(/^(\.\.\/)+/, "").replace(/^\.\//, "");
33
+ normalized = toOriginalImageCandidate(normalized);
34
+ if (normalized.startsWith("/assets/")) {
35
+ return normalized.replace(/\/\.\.\//g, "/");
36
+ }
37
+ return `/assets/${normalized.replace(/^\/+/, "")}`;
38
+ }
28
39
  function normalizeImageSeedPath(imageSrc) {
29
40
  if (!imageSrc) return "";
30
41
  if (/^(https?:)?\/\//i.test(imageSrc) || imageSrc.startsWith("data:")) return imageSrc;
@@ -152,17 +163,20 @@ async function writeVueComponent(outputDir, fileName, content, target = "nuxt",
152
163
  const vuePath = path2.join(componentDir, vueName2);
153
164
  const astroPath = path2.join(astroPagesDir, astroName);
154
165
  const relativeVueImport = ensureRelativeImport(path2.relative(path2.dirname(astroPath), vuePath));
155
- const cssImports = cssFiles.map((file) => `import '${ensureRelativeImport(path2.relative(path2.dirname(astroPath), path2.join(outputDir, "assets", "css", path2.relative("css", file))))}';`).join("\n");
166
+ const cssLinks = [
167
+ ...cssFiles.map((file) => `/assets/css/${path2.basename(file)}`),
168
+ "/assets/css/main.css"
169
+ ].map((href) => `<link rel="stylesheet" href="${href}" />`).join("\n");
156
170
  const editorScript = editorEnabled ? "\n<script>\n import '../cms-editor';\n</script>\n" : "";
157
171
  await fs.ensureDir(path2.dirname(vuePath));
158
172
  await fs.ensureDir(path2.dirname(astroPath));
159
173
  await fs.writeFile(vuePath, content, "utf-8");
160
174
  await fs.writeFile(astroPath, `---
161
175
  import Page from '${relativeVueImport}';
162
- ${cssImports}
163
176
  ---
164
177
 
165
- <Page client:load />
178
+ ${cssLinks}
179
+ <Page client:only="vue" />
166
180
  ${editorScript}
167
181
  `, "utf-8");
168
182
  return;
@@ -217,18 +231,6 @@ function normalizeRoute(href, currentFile) {
217
231
  }
218
232
  return `${normalized}${suffix}`;
219
233
  }
220
- function normalizeAssetPath(src) {
221
- if (!src || src.startsWith("http") || src.startsWith("https")) {
222
- return src;
223
- }
224
- let normalized = normalizeAssetUrl(src).replace(/^(\.\.\/)+/, "").replace(/^\.\//, "");
225
- normalized = toOriginalImageCandidate(normalized);
226
- if (normalized.startsWith("/assets/")) {
227
- normalized = normalized.replace(/\/\.\.\//g, "/");
228
- return normalized;
229
- }
230
- return `/assets/${normalized}`;
231
- }
232
234
  function parseHTML(html, fileName) {
233
235
  const $ = cheerio.load(html);
234
236
  const title = $("title").text() || fileName.replace(".html", "");
@@ -278,8 +280,9 @@ function parseHTML(html, fileName) {
278
280
  links
279
281
  };
280
282
  }
281
- function transformForNuxt(html, currentFile) {
283
+ function transformForNuxt(html, currentFile, options = {}) {
282
284
  const $ = cheerio.load(html);
285
+ const linkMode = options.linkMode || "nuxt";
283
286
  $("html, head, body").each((_, el) => {
284
287
  const $el = $(el);
285
288
  $el.replaceWith($el.html() || "");
@@ -290,7 +293,7 @@ function transformForNuxt(html, currentFile) {
290
293
  const href = $el.attr("href");
291
294
  if (!href) return;
292
295
  const isExternal = href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:") || href.startsWith("tel:") || href.startsWith("#");
293
- if (!isExternal) {
296
+ if (!isExternal && linkMode === "nuxt") {
294
297
  const route = normalizeRoute(href, currentFile);
295
298
  const content = $el.html();
296
299
  const attrs = { ...$el.attr() };
@@ -298,13 +301,15 @@ function transformForNuxt(html, currentFile) {
298
301
  attrs.to = route;
299
302
  const attrString = Object.entries(attrs).map(([name, value]) => `${name}="${escapeAttribute(value ?? "")}"`).join(" ");
300
303
  $el.replaceWith(`<nuxt-link ${attrString}>${content}</nuxt-link>`);
304
+ } else if (!isExternal) {
305
+ $el.attr("href", normalizeRoute(href, currentFile));
301
306
  }
302
307
  });
303
308
  $("img").each((_, el) => {
304
309
  const $el = $(el);
305
310
  const src = $el.attr("src");
306
311
  if (src) {
307
- const normalizedSrc = normalizeAssetPath(src);
312
+ const normalizedSrc = normalizePublicAssetPath(src);
308
313
  $el.attr("src", normalizedSrc);
309
314
  }
310
315
  $el.removeAttr("srcset");
@@ -3608,6 +3613,7 @@ function createVueComponent(component) {
3608
3613
  html = html.replace(/\s*data-w-id="[^"]*"/g, "");
3609
3614
  html = html.replace(/\s*data-wf-page="[^"]*"/g, "");
3610
3615
  html = html.replace(/\s*data-wf-site="[^"]*"/g, "");
3616
+ html = sanitizeVueComponentHtml(html);
3611
3617
  return `<script setup lang="ts">
3612
3618
  /**
3613
3619
  * ${component.name} Component
@@ -3627,6 +3633,20 @@ ${html}
3627
3633
  </style>
3628
3634
  `;
3629
3635
  }
3636
+ function sanitizeVueComponentHtml(html) {
3637
+ const $ = cheerio5.load(html);
3638
+ $("script, style").remove();
3639
+ $("img").each((_, el) => {
3640
+ const $el = $(el);
3641
+ const src = $el.attr("src");
3642
+ if (src) {
3643
+ $el.attr("src", normalizePublicAssetPath(src));
3644
+ }
3645
+ $el.removeAttr("srcset");
3646
+ $el.removeAttr("sizes");
3647
+ });
3648
+ return $.html();
3649
+ }
3630
3650
  function replaceWithComponent($, selector, componentName) {
3631
3651
  const $element = $(selector);
3632
3652
  if ($element.length > 0) {
@@ -4008,7 +4028,9 @@ async function convertWebflowExport(options) {
4008
4028
  ${parsed.embeddedStyles}
4009
4029
  `;
4010
4030
  }
4011
- const transformed = transformForNuxt(parsed.htmlContent, htmlFile);
4031
+ const transformed = transformForNuxt(parsed.htmlContent, htmlFile, {
4032
+ linkMode: target === "astro-vue" ? "anchor" : "nuxt"
4033
+ });
4012
4034
  const componentImports = pageComponentMap.get(pageName);
4013
4035
  const vueComponent = htmlToVueComponent(transformed, pageName, componentImports);
4014
4036
  await writeVueComponent(outputDir, htmlFile, vueComponent, target, assets.css, editorEnabled);