@daz4126/swifty 1.7.0 → 1.8.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/swifty.js +10 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daz4126/swifty",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "bin": {
package/swifty.js CHANGED
@@ -343,8 +343,17 @@ const generateLinkList = async (name,pages) => {
343
343
  const render = async page => {
344
344
  const replacedContent = await replacePlaceholders(page.content, page);
345
345
  const htmlContent = marked.parse(replacedContent); // Markdown processed once
346
+ turboHTML = htmlContent.replace(
347
+ /<a\s+([^>]*?)href="(\/[^"#?]+?)"(.*?)>/g,
348
+ (match, beforeHref, href, afterHref) => {
349
+ // Don't double-add .html
350
+ const fullHref = href.endsWith('.html') ? href : `${href}.html`;
351
+
352
+ return `<a ${beforeHref}href="${fullHref}" data-turbo-frame="content" data-turbo-action="advance"${afterHref}>`;
353
+ }
354
+ );
346
355
 
347
- const wrappedContent = await applyLayoutAndWrapContent(page, htmlContent);
356
+ const wrappedContent = await applyLayoutAndWrapContent(page, turboHTML);
348
357
  return wrappedContent;
349
358
  };
350
359
 
@@ -389,13 +398,6 @@ const renderIndexTemplate = async (content, config) => {
389
398
  window.history.pushState({}, "", newPath);
390
399
  }
391
400
  }
392
- document.querySelectorAll('#content a[href]').forEach(link => {
393
- const href = link.getAttribute('href');
394
- if (href.startsWith('#') || href.startsWith('http') || href === "/") return;
395
- link.setAttribute('data-turbo-frame', 'content');
396
- link.setAttribute('data-turbo-action', 'advance');
397
- link.setAttribute('href', href.endsWith(".html") ? href : href + ".html");
398
- });
399
401
  });
400
402
  </script>
401
403
  `;