site-config-stack 0.8.11 → 0.8.13

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.cjs CHANGED
@@ -67,17 +67,26 @@ function normalizeSiteConfig(config) {
67
67
  config.url = ufo.withHttps(config.url);
68
68
  return config;
69
69
  }
70
- function resolveSitePath(path, options) {
70
+ function resolveSitePath(pathOrUrl, options) {
71
+ let path = pathOrUrl;
72
+ if (ufo.hasProtocol(pathOrUrl, { strict: false, acceptRelative: true })) {
73
+ const parsed = ufo.parseURL(pathOrUrl);
74
+ path = parsed.pathname;
75
+ }
76
+ if (!options.withBase && path.startsWith(`/${options.base}`)) {
77
+ path = path.slice(options.base.length + 1);
78
+ }
71
79
  const origin = options.absolute ? options.siteUrl : "";
72
- const baseWithOrigin = options.withBase ? ufo.joinURL(origin || "/", options.base) : origin;
73
- const resolvedUrl = ufo.joinURL(baseWithOrigin, path);
74
- return fixSlashes(options.trailingSlash, resolvedUrl);
80
+ const baseWithOrigin = options.withBase ? ufo.withBase(options.base, origin || "/") : origin;
81
+ const resolvedUrl = ufo.withBase(path, baseWithOrigin);
82
+ return path === "/" ? ufo.withTrailingSlash(resolvedUrl) : fixSlashes(options.trailingSlash, resolvedUrl);
75
83
  }
76
- function fixSlashes(trailingSlash, path) {
77
- const isFileUrl = path.includes(".");
84
+ function fixSlashes(trailingSlash, pathOrUrl) {
85
+ const parsed = ufo.parseURL(pathOrUrl);
86
+ const isFileUrl = parsed.pathname.includes(".");
78
87
  if (isFileUrl)
79
- return path;
80
- return trailingSlash ? ufo.withTrailingSlash(path) : ufo.withoutTrailingSlash(path);
88
+ return pathOrUrl;
89
+ return trailingSlash ? ufo.withTrailingSlash(pathOrUrl) : ufo.withoutTrailingSlash(pathOrUrl);
81
90
  }
82
91
 
83
92
  exports.createSiteConfigStack = createSiteConfigStack;
package/dist/index.d.ts CHANGED
@@ -73,13 +73,13 @@ declare const envSiteConfig: SiteConfigInput;
73
73
  declare function createSiteConfigStack(): SiteConfigStack;
74
74
 
75
75
  declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
76
- declare function resolveSitePath(path: string, options: {
76
+ declare function resolveSitePath(pathOrUrl: string, options: {
77
77
  siteUrl: string;
78
78
  trailingSlash: boolean;
79
79
  base: string;
80
80
  absolute?: boolean;
81
81
  withBase?: boolean;
82
82
  }): string;
83
- declare function fixSlashes(trailingSlash: boolean, path: string): string;
83
+ declare function fixSlashes(trailingSlash: boolean, pathOrUrl: string): string;
84
84
 
85
85
  export { SiteConfig, SiteConfigInput, SiteConfigStack, createSiteConfigStack, envSiteConfig, fixSlashes, normalizeSiteConfig, resolveSitePath };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { hasProtocol, withHttps, joinURL, withTrailingSlash, withoutTrailingSlash } from 'ufo';
1
+ import { hasProtocol, withHttps, parseURL, withBase, withTrailingSlash, withoutTrailingSlash } from 'ufo';
2
2
 
3
3
  const processShim = typeof process !== "undefined" ? process : {};
4
4
  const envShim = processShim.env || {};
@@ -65,17 +65,26 @@ function normalizeSiteConfig(config) {
65
65
  config.url = withHttps(config.url);
66
66
  return config;
67
67
  }
68
- function resolveSitePath(path, options) {
68
+ function resolveSitePath(pathOrUrl, options) {
69
+ let path = pathOrUrl;
70
+ if (hasProtocol(pathOrUrl, { strict: false, acceptRelative: true })) {
71
+ const parsed = parseURL(pathOrUrl);
72
+ path = parsed.pathname;
73
+ }
74
+ if (!options.withBase && path.startsWith(`/${options.base}`)) {
75
+ path = path.slice(options.base.length + 1);
76
+ }
69
77
  const origin = options.absolute ? options.siteUrl : "";
70
- const baseWithOrigin = options.withBase ? joinURL(origin || "/", options.base) : origin;
71
- const resolvedUrl = joinURL(baseWithOrigin, path);
72
- return fixSlashes(options.trailingSlash, resolvedUrl);
78
+ const baseWithOrigin = options.withBase ? withBase(options.base, origin || "/") : origin;
79
+ const resolvedUrl = withBase(path, baseWithOrigin);
80
+ return path === "/" ? withTrailingSlash(resolvedUrl) : fixSlashes(options.trailingSlash, resolvedUrl);
73
81
  }
74
- function fixSlashes(trailingSlash, path) {
75
- const isFileUrl = path.includes(".");
82
+ function fixSlashes(trailingSlash, pathOrUrl) {
83
+ const parsed = parseURL(pathOrUrl);
84
+ const isFileUrl = parsed.pathname.includes(".");
76
85
  if (isFileUrl)
77
- return path;
78
- return trailingSlash ? withTrailingSlash(path) : withoutTrailingSlash(path);
86
+ return pathOrUrl;
87
+ return trailingSlash ? withTrailingSlash(pathOrUrl) : withoutTrailingSlash(pathOrUrl);
79
88
  }
80
89
 
81
90
  export { createSiteConfigStack, envSiteConfig, fixSlashes, normalizeSiteConfig, resolveSitePath };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "site-config-stack",
3
3
  "type": "module",
4
- "version": "0.8.11",
4
+ "version": "0.8.13",
5
5
  "description": "Shared site configuration utilities.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",