@pithyjs/ssr 0.2.0-beta.23 → 0.2.0-beta.24

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.
@@ -9,6 +9,7 @@
9
9
  * href="/about" → href="../../about/index.html"
10
10
  * src="/assets/client.js" → src="../../assets/client.js"
11
11
  * href="/assets/style.css" → href="../../assets/style.css"
12
+ * href="/ui-kit/for#api" → href="#api" (same page; not when the HTML has a <base>)
12
13
  */
13
14
  export interface MakeLinksRelativeOptions {
14
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"relative-links.d.ts","sourceRoot":"","sources":["../../src/build/relative-links.ts"],"names":[],"mappings":"AAAA,sHAAsH;AAEtH;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,4MAA4M;AAC5M,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAoFR"}
1
+ {"version":3,"file":"relative-links.d.ts","sourceRoot":"","sources":["../../src/build/relative-links.ts"],"names":[],"mappings":"AAAA,sHAAsH;AAEtH;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,4MAA4M;AAC5M,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CA2FR"}
@@ -12,6 +12,9 @@ export function makeLinksRelative(html, currentPath, options) {
12
12
  const assetsOnly = options?.assetsOnly ?? false;
13
13
  const depth = currentPath.split('/').filter(Boolean).length;
14
14
  const prefix = depth > 0 ? '../'.repeat(depth) : '';
15
+ const self = currentPath.replace(/^\/+|\/+$/g, '');
16
+ // A bare fragment resolves against <base>, which pass 1 moves to the root.
17
+ const keepSamePageFragment = !/<base[\s>]/i.test(html);
15
18
  // Pass 1: Rewrite <base> tags separately — they define directory URLs,
16
19
  // never append /index.html. Dedicated pass avoids fragile lookbehind.
17
20
  // In assetsOnly mode, skip <base> rewriting entirely — the client
@@ -47,6 +50,9 @@ export function makeLinksRelative(html, currentPath, options) {
47
50
  // client router can still match them by their absolute pattern
48
51
  if (assetsOnly)
49
52
  return _match;
53
+ if (keepSamePageFragment && target === self && suffix.startsWith('#')) {
54
+ return `href=${quote}${suffix}${quote}`;
55
+ }
50
56
  if (!target) {
51
57
  return `href=${quote}${prefix}index.html${suffix}${quote}`;
52
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"relative-links.js","sourceRoot":"","sources":["../../src/build/relative-links.ts"],"names":[],"mappings":"AAAA,sHAAsH;AAuBtH;;;;;;;GAOG;AACH,4MAA4M;AAC5M,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,WAAmB,EACnB,OAAkC;IAElC,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC;IAChD,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC5D,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAEpD,uEAAuE;IACvE,sEAAsE;IACtE,kEAAkE;IAClE,gEAAgE;IAChE,IAAI,MAAM,GAAG,UAAU;QACrB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,IAAI,CAAC,OAAO,CACV,2CAA2C,EAC3C,CAAC,MAAM,EAAE,MAAc,EAAE,KAAa,EAAE,OAAe,EAAE,EAAE;YACzD,mDAAmD;YACnD,IAAI,OAAO,CAAC,UAAU,C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links in HTML to relative paths.\n *\n * Makes SSG output portable — works from file:// (double-click) and\n * any static hosting root without requiring server-side URL rewriting.\n *\n * From /ui-kit/for/index.html:\n * href=\"/about\" → href=\"../../about/index.html\"\n * src=\"/assets/client.js\" → src=\"../../assets/client.js\"\n * href=\"/assets/style.css\" → href=\"../../assets/style.css\"\n */\n\nexport interface MakeLinksRelativeOptions {\n /**\n * When true, only rewrite asset URLs (with file extensions like .css, .js)\n * and leave route-like URLs (/about, /dashboard) absolute.\n * Use this in hydrate mode where the client router needs absolute paths.\n */\n assetsOnly?: boolean;\n}\n\n/**\n * Convert all absolute href=\"/...\" and src=\"/...\" to relative paths.\n *\n * @param html - Full HTML string\n * @param currentPath - The route path this HTML was rendered for (e.g., '/ui-kit/for')\n * @param options - Options for link rewriting\n * @returns HTML with relative links\n */\n/** @codexApi {\"parent\":\"pithy.ssr.build.relative-links\",\"name\":\"makeLinksRelative\",\"stability\":\"stable\",\"signature\":\"(html: string, currentPath: string, options?: MakeLinksRelativeOptions) => string\"} */\nexport function makeLinksRelative(\n html: string,\n currentPath: string,\n options?: MakeLinksRelativeOptions\n): string {\n const assetsOnly = options?.assetsOnly ?? false;\n const depth = currentPath.split('/').filter(Boolean).length;\n const prefix = depth > 0 ? '../'.repeat(depth) : '';\n\n // Pass 1: Rewrite <base> tags separately — they define directory URLs,\n // never append /index.html. Dedicated pass avoids fragile lookbehind.\n // In assetsOnly mode, skip <base> rewriting entirely — the client\n // router relies on <base href=\"/\"> for absolute route matching.\n let result = assetsOnly\n ? html\n : html.replace(\n /(<base\\s[^>]*?)href=([\"'])\\/([^\"']*?)\\2/gi,\n (_match, before: string, quote: string, rawPath: string) => {\n // Skip protocol-relative URLs (//cdn.example.com/)\n if (rawPath.startsWith('/')) return _match;\n\n const target = rawPath.replace(/\\/$/, '');\n if (!target) return `${before}href=${quote}${prefix || './'}${quote}`;\n return `${before}href=${quote}${prefix}${target}/${quote}`;\n }\n );\n\n // Pass 2: Rewrite remaining href=\"/...\" (supports double and single quotes)\n // For file-like paths (with extension): always rewrite\n // For route-like paths: append /index.html (unless assetsOnly)\n // Preserves query strings and hash fragments\n result = result.replace(\n /href=([\"'])\\/([^\"']*?)\\1/g,\n (_match, quote: string, rawPath: string) => {\n // Skip protocol-relative URLs (//cdn.example.com/...)\n if (rawPath.startsWith('/')) return _match;\n\n // Split off query and hash\n const [pathPart, ...rest] = rawPath.split(/([?#])/);\n const suffix = rest.join(''); // preserves ?query#hash\n const target = pathPart.replace(/\\/$/, '');\n\n // If path has a file extension (e.g. .css, .js, .png), it's an asset — always rewrite\n if (target && /\\.\\w+$/.test(target)) {\n return `href=${quote}${prefix}${target}${suffix}${quote}`;\n }\n\n // In assetsOnly mode, skip route-like paths (no extension) so the\n // client router can still match them by their absolute pattern\n if (assetsOnly) return _match;\n\n if (!target) {\n return `href=${quote}${prefix}index.html${suffix}${quote}`;\n }\n\n return `href=${quote}${prefix}${target}/index.html${suffix}${quote}`;\n }\n );\n\n // Pass 3: Rewrite src=\"/...\" (supports double and single quotes)\n // Same asset-vs-route logic as href: only rewrite assets in assetsOnly mode\n result = result.replace(\n /src=([\"'])\\/([^\"']*?)\\1/g,\n (_match, quote: string, rawPath: string) => {\n if (rawPath.startsWith('/')) return _match;\n\n // Split off query and hash (same as href logic)\n const [pathPart, ...rest] = rawPath.split(/([?#])/);\n const suffix = rest.join('');\n\n // If path has a file extension, it's an asset — always rewrite\n if (pathPart && /\\.\\w+$/.test(pathPart)) {\n return `src=${quote}${prefix}${pathPart}${suffix}${quote}`;\n }\n\n // In assetsOnly mode, skip route-like src (e.g. <iframe src=\"/about\">)\n if (assetsOnly) return _match;\n\n // Route-like src: append /index.html (same as href) for file:// portability\n const target = pathPart.replace(/\\/$/, '');\n if (!target) {\n return `src=${quote}${prefix}index.html${suffix}${quote}`;\n }\n return `src=${quote}${prefix}${target}/index.html${suffix}${quote}`;\n }\n );\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"relative-links.js","sourceRoot":"","sources":["../../src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,MAAM,CAAC,OAAO,CACrB,0BAA0B,EAC1B,CAAC,MAAM,EAAE,KAAa,EAAE,OAAe,EAAE,EAAE;QACzC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,MAAM,CAAC;QAE3C,gDAAgD;QAChD,MAAM,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACpD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE7B,+DAA+D;QAC/D,IAAI,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,OAAO,OAAO,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,EAAE,CAAC;QAC7D,CAAC;QAED,uEAAuE;QACvE,IAAI,UAAU;YAAE,OAAO,MAAM,CAAC;QAE9B,4EAA4E;QAC5E,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,OAAO,KAAK,GAAG,MAAM,aAAa,MAAM,GAAG,KAAK,EAAE,CAAC;QAC5D,CAAC;QACD,OAAO,OAAO,KAAK,GAAG,MAAM,GAAG,MAAM,cAAc,MAAM,GAAG,KAAK,EAAE,CAAC;IACtE,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** @codex { \"id\": \"pithy.ssr.build.relative-links\", \"title\": \"SSG Relative Link Rewriter\", \"category\": \"runtime\" } */\n\n/**\n * Convert absolute links in HTML to relative paths.\n *\n * Makes SSG output portable — works from file:// (double-click) and\n * any static hosting root without requiring server-side URL rewriting.\n *\n * From /ui-kit/for/index.html:\n * href=\"/about\" → href=\"../../about/index.html\"\n * src=\"/assets/client.js\" → src=\"../../assets/client.js\"\n * href=\"/assets/style.css\" → href=\"../../assets/style.css\"\n * href=\"/ui-kit/for#api\" → href=\"#api\" (same page; not when the HTML has a <base>)\n */\n\nexport interface MakeLinksRelativeOptions {\n /**\n * When true, only rewrite asset URLs (with file extensions like .css, .js)\n * and leave route-like URLs (/about, /dashboard) absolute.\n * Use this in hydrate mode where the client router needs absolute paths.\n */\n assetsOnly?: boolean;\n}\n\n/**\n * Convert all absolute href=\"/...\" and src=\"/...\" to relative paths.\n *\n * @param html - Full HTML string\n * @param currentPath - The route path this HTML was rendered for (e.g., '/ui-kit/for')\n * @param options - Options for link rewriting\n * @returns HTML with relative links\n */\n/** @codexApi {\"parent\":\"pithy.ssr.build.relative-links\",\"name\":\"makeLinksRelative\",\"stability\":\"stable\",\"signature\":\"(html: string, currentPath: string, options?: MakeLinksRelativeOptions) => string\"} */\nexport function makeLinksRelative(\n html: string,\n currentPath: string,\n options?: MakeLinksRelativeOptions\n): string {\n const assetsOnly = options?.assetsOnly ?? false;\n const depth = currentPath.split('/').filter(Boolean).length;\n const prefix = depth > 0 ? '../'.repeat(depth) : '';\n const self = currentPath.replace(/^\\/+|\\/+$/g, '');\n // A bare fragment resolves against <base>, which pass 1 moves to the root.\n const keepSamePageFragment = !/<base[\\s>]/i.test(html);\n\n // Pass 1: Rewrite <base> tags separately — they define directory URLs,\n // never append /index.html. Dedicated pass avoids fragile lookbehind.\n // In assetsOnly mode, skip <base> rewriting entirely — the client\n // router relies on <base href=\"/\"> for absolute route matching.\n let result = assetsOnly\n ? html\n : html.replace(\n /(<base\\s[^>]*?)href=([\"'])\\/([^\"']*?)\\2/gi,\n (_match, before: string, quote: string, rawPath: string) => {\n // Skip protocol-relative URLs (//cdn.example.com/)\n if (rawPath.startsWith('/')) return _match;\n\n const target = rawPath.replace(/\\/$/, '');\n if (!target) return `${before}href=${quote}${prefix || './'}${quote}`;\n return `${before}href=${quote}${prefix}${target}/${quote}`;\n }\n );\n\n // Pass 2: Rewrite remaining href=\"/...\" (supports double and single quotes)\n // For file-like paths (with extension): always rewrite\n // For route-like paths: append /index.html (unless assetsOnly)\n // Preserves query strings and hash fragments\n result = result.replace(\n /href=([\"'])\\/([^\"']*?)\\1/g,\n (_match, quote: string, rawPath: string) => {\n // Skip protocol-relative URLs (//cdn.example.com/...)\n if (rawPath.startsWith('/')) return _match;\n\n // Split off query and hash\n const [pathPart, ...rest] = rawPath.split(/([?#])/);\n const suffix = rest.join(''); // preserves ?query#hash\n const target = pathPart.replace(/\\/$/, '');\n\n // If path has a file extension (e.g. .css, .js, .png), it's an asset — always rewrite\n if (target && /\\.\\w+$/.test(target)) {\n return `href=${quote}${prefix}${target}${suffix}${quote}`;\n }\n\n // In assetsOnly mode, skip route-like paths (no extension) so the\n // client router can still match them by their absolute pattern\n if (assetsOnly) return _match;\n\n if (keepSamePageFragment && target === self && suffix.startsWith('#')) {\n return `href=${quote}${suffix}${quote}`;\n }\n\n if (!target) {\n return `href=${quote}${prefix}index.html${suffix}${quote}`;\n }\n\n return `href=${quote}${prefix}${target}/index.html${suffix}${quote}`;\n }\n );\n\n // Pass 3: Rewrite src=\"/...\" (supports double and single quotes)\n // Same asset-vs-route logic as href: only rewrite assets in assetsOnly mode\n result = result.replace(\n /src=([\"'])\\/([^\"']*?)\\1/g,\n (_match, quote: string, rawPath: string) => {\n if (rawPath.startsWith('/')) return _match;\n\n // Split off query and hash (same as href logic)\n const [pathPart, ...rest] = rawPath.split(/([?#])/);\n const suffix = rest.join('');\n\n // If path has a file extension, it's an asset — always rewrite\n if (pathPart && /\\.\\w+$/.test(pathPart)) {\n return `src=${quote}${prefix}${pathPart}${suffix}${quote}`;\n }\n\n // In assetsOnly mode, skip route-like src (e.g. <iframe src=\"/about\">)\n if (assetsOnly) return _match;\n\n // Route-like src: append /index.html (same as href) for file:// portability\n const target = pathPart.replace(/\\/$/, '');\n if (!target) {\n return `src=${quote}${prefix}index.html${suffix}${quote}`;\n }\n return `src=${quote}${prefix}${target}/index.html${suffix}${quote}`;\n }\n );\n\n return result;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithyjs/ssr",
3
- "version": "0.2.0-beta.23",
3
+ "version": "0.2.0-beta.24",
4
4
  "description": "Server-side rendering and static site generation for PithyJS framework",
5
5
  "type": "module",
6
6
  "engines": {