@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/cli.mjs CHANGED
@@ -34,6 +34,17 @@ function normalizeAssetUrl(value) {
34
34
  return value;
35
35
  }
36
36
  }
37
+ function normalizePublicAssetPath(src) {
38
+ if (!src || /^(https?:)?\/\//i.test(src) || src.startsWith("data:")) {
39
+ return src;
40
+ }
41
+ let normalized = normalizeAssetUrl(src).replace(/^(\.\.\/)+/, "").replace(/^\.\//, "");
42
+ normalized = toOriginalImageCandidate(normalized);
43
+ if (normalized.startsWith("/assets/")) {
44
+ return normalized.replace(/\/\.\.\//g, "/");
45
+ }
46
+ return `/assets/${normalized.replace(/^\/+/, "")}`;
47
+ }
37
48
  function normalizeImageSeedPath(imageSrc) {
38
49
  if (!imageSrc) return "";
39
50
  if (/^(https?:)?\/\//i.test(imageSrc) || imageSrc.startsWith("data:")) return imageSrc;
@@ -161,17 +172,20 @@ async function writeVueComponent(outputDir, fileName, content, target = "nuxt",
161
172
  const vuePath = path2.join(componentDir, vueName2);
162
173
  const astroPath = path2.join(astroPagesDir, astroName);
163
174
  const relativeVueImport = ensureRelativeImport(path2.relative(path2.dirname(astroPath), vuePath));
164
- const cssImports = cssFiles.map((file) => `import '${ensureRelativeImport(path2.relative(path2.dirname(astroPath), path2.join(outputDir, "assets", "css", path2.relative("css", file))))}';`).join("\n");
175
+ const cssLinks = [
176
+ ...cssFiles.map((file) => `/assets/css/${path2.basename(file)}`),
177
+ "/assets/css/main.css"
178
+ ].map((href) => `<link rel="stylesheet" href="${href}" />`).join("\n");
165
179
  const editorScript = editorEnabled ? "\n<script>\n import '../cms-editor';\n</script>\n" : "";
166
180
  await fs.ensureDir(path2.dirname(vuePath));
167
181
  await fs.ensureDir(path2.dirname(astroPath));
168
182
  await fs.writeFile(vuePath, content, "utf-8");
169
183
  await fs.writeFile(astroPath, `---
170
184
  import Page from '${relativeVueImport}';
171
- ${cssImports}
172
185
  ---
173
186
 
174
- <Page client:load />
187
+ ${cssLinks}
188
+ <Page client:only="vue" />
175
189
  ${editorScript}
176
190
  `, "utf-8");
177
191
  return;
@@ -226,18 +240,6 @@ function normalizeRoute(href, currentFile) {
226
240
  }
227
241
  return `${normalized}${suffix}`;
228
242
  }
229
- function normalizeAssetPath(src) {
230
- if (!src || src.startsWith("http") || src.startsWith("https")) {
231
- return src;
232
- }
233
- let normalized = normalizeAssetUrl(src).replace(/^(\.\.\/)+/, "").replace(/^\.\//, "");
234
- normalized = toOriginalImageCandidate(normalized);
235
- if (normalized.startsWith("/assets/")) {
236
- normalized = normalized.replace(/\/\.\.\//g, "/");
237
- return normalized;
238
- }
239
- return `/assets/${normalized}`;
240
- }
241
243
  function parseHTML(html, fileName) {
242
244
  const $ = cheerio.load(html);
243
245
  const title = $("title").text() || fileName.replace(".html", "");
@@ -287,8 +289,9 @@ function parseHTML(html, fileName) {
287
289
  links
288
290
  };
289
291
  }
290
- function transformForNuxt(html, currentFile) {
292
+ function transformForNuxt(html, currentFile, options = {}) {
291
293
  const $ = cheerio.load(html);
294
+ const linkMode = options.linkMode || "nuxt";
292
295
  $("html, head, body").each((_, el) => {
293
296
  const $el = $(el);
294
297
  $el.replaceWith($el.html() || "");
@@ -299,7 +302,7 @@ function transformForNuxt(html, currentFile) {
299
302
  const href = $el.attr("href");
300
303
  if (!href) return;
301
304
  const isExternal = href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:") || href.startsWith("tel:") || href.startsWith("#");
302
- if (!isExternal) {
305
+ if (!isExternal && linkMode === "nuxt") {
303
306
  const route = normalizeRoute(href, currentFile);
304
307
  const content = $el.html();
305
308
  const attrs = { ...$el.attr() };
@@ -307,13 +310,15 @@ function transformForNuxt(html, currentFile) {
307
310
  attrs.to = route;
308
311
  const attrString = Object.entries(attrs).map(([name, value]) => `${name}="${escapeAttribute(value ?? "")}"`).join(" ");
309
312
  $el.replaceWith(`<nuxt-link ${attrString}>${content}</nuxt-link>`);
313
+ } else if (!isExternal) {
314
+ $el.attr("href", normalizeRoute(href, currentFile));
310
315
  }
311
316
  });
312
317
  $("img").each((_, el) => {
313
318
  const $el = $(el);
314
319
  const src = $el.attr("src");
315
320
  if (src) {
316
- const normalizedSrc = normalizeAssetPath(src);
321
+ const normalizedSrc = normalizePublicAssetPath(src);
317
322
  $el.attr("src", normalizedSrc);
318
323
  }
319
324
  $el.removeAttr("srcset");
@@ -3612,6 +3617,7 @@ function createVueComponent(component) {
3612
3617
  html = html.replace(/\s*data-w-id="[^"]*"/g, "");
3613
3618
  html = html.replace(/\s*data-wf-page="[^"]*"/g, "");
3614
3619
  html = html.replace(/\s*data-wf-site="[^"]*"/g, "");
3620
+ html = sanitizeVueComponentHtml(html);
3615
3621
  return `<script setup lang="ts">
3616
3622
  /**
3617
3623
  * ${component.name} Component
@@ -3631,6 +3637,20 @@ ${html}
3631
3637
  </style>
3632
3638
  `;
3633
3639
  }
3640
+ function sanitizeVueComponentHtml(html) {
3641
+ const $ = cheerio5.load(html);
3642
+ $("script, style").remove();
3643
+ $("img").each((_, el) => {
3644
+ const $el = $(el);
3645
+ const src = $el.attr("src");
3646
+ if (src) {
3647
+ $el.attr("src", normalizePublicAssetPath(src));
3648
+ }
3649
+ $el.removeAttr("srcset");
3650
+ $el.removeAttr("sizes");
3651
+ });
3652
+ return $.html();
3653
+ }
3634
3654
  function replaceWithComponent($, selector, componentName) {
3635
3655
  const $element = $(selector);
3636
3656
  if ($element.length > 0) {
@@ -4012,7 +4032,9 @@ async function convertWebflowExport(options) {
4012
4032
  ${parsed.embeddedStyles}
4013
4033
  `;
4014
4034
  }
4015
- const transformed = transformForNuxt(parsed.htmlContent, htmlFile);
4035
+ const transformed = transformForNuxt(parsed.htmlContent, htmlFile, {
4036
+ linkMode: target === "astro-vue" ? "anchor" : "nuxt"
4037
+ });
4016
4038
  const componentImports = pageComponentMap.get(pageName);
4017
4039
  const vueComponent = htmlToVueComponent(transformed, pageName, componentImports);
4018
4040
  await writeVueComponent(outputDir, htmlFile, vueComponent, target, assets.css, editorEnabled);