@blinkk/root 1.4.5 → 1.4.6

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/render.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
 
14
14
  // src/render/render.tsx
15
15
  import crypto from "node:crypto";
16
+ import path2 from "node:path";
16
17
  import {
17
18
  options as preactOptions
18
19
  } from "preact";
@@ -12949,7 +12950,7 @@ var Router = class {
12949
12950
  }
12950
12951
  async getAllPathsForRoute(urlPathFormat, route) {
12951
12952
  const routeModule = route.module;
12952
- if (!routeModule.default) {
12953
+ if (!routeModule.default && !routeModule.getStaticContent) {
12953
12954
  return [];
12954
12955
  }
12955
12956
  const trailingSlash = this.rootConfig.server?.trailingSlash;
@@ -13010,8 +13011,8 @@ function replaceParams(urlPathFormat, params) {
13010
13011
  }
13011
13012
  function normalizeUrlPath(urlPath, options) {
13012
13013
  urlPath = urlPath.replace(/\/+/g, "/");
13013
- if (options?.trailingSlash === false && urlPath !== "/" && urlPath.endsWith("/")) {
13014
- urlPath = urlPath.replace(/\/*$/g, "");
13014
+ if (testPathHasFileExt(urlPath) || options?.trailingSlash === false && urlPath !== "/" && urlPath.endsWith("/")) {
13015
+ urlPath = removeTrailingSlash(urlPath);
13015
13016
  }
13016
13017
  if (urlPath.endsWith("/index")) {
13017
13018
  urlPath = urlPath.slice(0, -6);
@@ -13019,7 +13020,7 @@ function normalizeUrlPath(urlPath, options) {
13019
13020
  if (!urlPath.startsWith("/")) {
13020
13021
  urlPath = `/${urlPath}`;
13021
13022
  }
13022
- if (options?.trailingSlash && !urlPath.endsWith("/")) {
13023
+ if (options?.trailingSlash && !testPathHasFileExt(urlPath) && !urlPath.endsWith("/")) {
13023
13024
  urlPath = `${urlPath}/`;
13024
13025
  }
13025
13026
  return urlPath;
@@ -13027,11 +13028,21 @@ function normalizeUrlPath(urlPath, options) {
13027
13028
  function testPathHasParams(urlPath) {
13028
13029
  const segments = urlPath.split("/");
13029
13030
  return segments.some((segment) => {
13030
- return segment.startsWith("[") && segment.endsWith("]");
13031
+ return segment.startsWith("[") && segment.includes("]");
13031
13032
  });
13032
13033
  }
13034
+ function testPathHasFileExt(urlPath) {
13035
+ const basename = path.basename(removeTrailingSlash(urlPath));
13036
+ return basename.includes(".");
13037
+ }
13033
13038
  function removeSlashes(str) {
13034
- return str.replace(/^\/*/g, "").replace(/\/*$/g, "");
13039
+ return removeTrailingSlash(removeLeadingSlash(str));
13040
+ }
13041
+ function removeLeadingSlash(str) {
13042
+ return str.replace(/^\/*/g, "");
13043
+ }
13044
+ function removeTrailingSlash(str) {
13045
+ return str.replace(/\/*$/g, "");
13035
13046
  }
13036
13047
  function toSquareBrackets(str) {
13037
13048
  if (str.includes("{") || str.includes("}")) {
@@ -13044,6 +13055,31 @@ function toSquareBrackets(str) {
13044
13055
 
13045
13056
  // src/render/render.tsx
13046
13057
  import { jsx as jsx4, jsxs as jsxs4 } from "preact/jsx-runtime";
13058
+ var CONTENT_TYPES = {
13059
+ "html": "text/html",
13060
+ "htm": "text/html",
13061
+ "css": "text/css",
13062
+ "js": "application/javascript",
13063
+ "json": "application/json",
13064
+ "png": "image/png",
13065
+ "jpg": "image/jpeg",
13066
+ "jpeg": "image/jpeg",
13067
+ "gif": "image/gif",
13068
+ "svg": "image/svg+xml",
13069
+ "txt": "text/plain",
13070
+ "xml": "application/xml",
13071
+ "pdf": "application/pdf",
13072
+ "zip": "application/zip",
13073
+ "mp4": "video/mp4",
13074
+ "webm": "video/webm",
13075
+ "mp3": "audio/mpeg",
13076
+ "wav": "audio/wav",
13077
+ "woff": "font/woff",
13078
+ "woff2": "font/woff2",
13079
+ "ttf": "font/ttf",
13080
+ "otf": "font/otf",
13081
+ "wasm": "application/wasm"
13082
+ };
13047
13083
  var Renderer = class {
13048
13084
  rootConfig;
13049
13085
  // private routes: RouteTrie<Route>;
@@ -13144,6 +13180,34 @@ var Renderer = class {
13144
13180
  });
13145
13181
  res.end(html);
13146
13182
  };
13183
+ if (route.module.getStaticContent) {
13184
+ let props2;
13185
+ if (route.module.getStaticProps) {
13186
+ props2 = await route.module.getStaticProps({
13187
+ rootConfig: this.rootConfig,
13188
+ params: routeParams
13189
+ });
13190
+ } else {
13191
+ props2 = { rootConfig: this.rootConfig, params: routeParams };
13192
+ }
13193
+ const result = await route.module.getStaticContent(props2);
13194
+ let body;
13195
+ let contentType;
13196
+ if (typeof result === "string" || Buffer.isBuffer(result)) {
13197
+ body = result;
13198
+ } else if (result && typeof result === "object") {
13199
+ body = result.body;
13200
+ contentType = result.contentType;
13201
+ } else {
13202
+ body = "";
13203
+ }
13204
+ res.status(200);
13205
+ const ext = path2.extname(route.routePath);
13206
+ res.set({
13207
+ "Content-Type": contentType || guessContentType(ext)
13208
+ });
13209
+ return res.end(body);
13210
+ }
13147
13211
  if (route.module.handle) {
13148
13212
  const handlerContext = {
13149
13213
  route,
@@ -13620,6 +13684,10 @@ function sortLocales(a, b) {
13620
13684
  }
13621
13685
  return a.localeCompare(b);
13622
13686
  }
13687
+ function guessContentType(ext) {
13688
+ const normalized = ext.trim().toLowerCase().replace(/^\./, "");
13689
+ return CONTENT_TYPES[normalized] || "application/octet-stream";
13690
+ }
13623
13691
  export {
13624
13692
  Renderer
13625
13693
  };