fumapress 0.5.0 → 0.5.2

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 (63) hide show
  1. package/css/generated.css +217 -3
  2. package/dist/adapters/mdx.d.ts +1 -1
  3. package/dist/client.d.ts +2 -23
  4. package/dist/client.js +3 -9
  5. package/dist/components/blog.js +4 -4
  6. package/dist/components/image.d.ts +30 -0
  7. package/dist/components/image.js +143 -0
  8. package/dist/components/link.d.ts +25 -0
  9. package/dist/components/link.js +18 -0
  10. package/dist/components/provider.d.ts +6 -0
  11. package/dist/components/provider.js +39 -0
  12. package/dist/config.d.ts +73 -30
  13. package/dist/config.js +14 -7
  14. package/dist/image.d.ts +2 -0
  15. package/dist/image.js +2 -0
  16. package/dist/index.d.ts +2 -2
  17. package/dist/layouts/blog.d.ts +1 -1
  18. package/dist/layouts/blog.index.js +3 -3
  19. package/dist/layouts/blog.js +3 -3
  20. package/dist/layouts/blog.tags.js +2 -2
  21. package/dist/layouts/docs.d.ts +2 -2
  22. package/dist/layouts/home.d.ts +1 -1
  23. package/dist/layouts/notebook.d.ts +2 -2
  24. package/dist/layouts/root.d.ts +5 -3
  25. package/dist/layouts/root.js +13 -16
  26. package/dist/layouts/switch.d.ts +2 -2
  27. package/dist/lib/pathname.js +14 -0
  28. package/dist/lib/shared.d.ts +10 -15
  29. package/dist/lib/shared.js +68 -33
  30. package/dist/lib/types.d.ts +30 -16
  31. package/dist/node_modules/.pnpm/http-cache-semantics@4.2.0/node_modules/http-cache-semantics/index.js +596 -0
  32. package/dist/plugins/blog.d.ts +3 -6
  33. package/dist/plugins/blog.js +6 -6
  34. package/dist/plugins/flexsearch.d.ts +1 -1
  35. package/dist/plugins/image/self-hosted.client.js +40 -0
  36. package/dist/plugins/image/self-hosted.d.ts +29 -0
  37. package/dist/plugins/image/self-hosted.js +30 -0
  38. package/dist/plugins/image/self-hosted.utils.js +270 -0
  39. package/dist/plugins/image/vercel.client.js +34 -0
  40. package/dist/plugins/image/vercel.d.ts +39 -0
  41. package/dist/plugins/image/vercel.enhancer.d.ts +10 -0
  42. package/dist/plugins/image/vercel.enhancer.js +16 -0
  43. package/dist/plugins/image/vercel.js +30 -0
  44. package/dist/plugins/image/vercel.utils.d.ts +10 -0
  45. package/dist/plugins/image/vercel.utils.js +30 -0
  46. package/dist/plugins/link-validation.d.ts +24 -0
  47. package/dist/plugins/link-validation.js +30 -0
  48. package/dist/plugins/llms.txt.d.ts +1 -1
  49. package/dist/plugins/llms.txt.js +2 -2
  50. package/dist/plugins/openapi.d.ts +2 -0
  51. package/dist/plugins/openapi.js +8 -1
  52. package/dist/plugins/orama-search.d.ts +1 -1
  53. package/dist/plugins/sitemap.d.ts +196 -0
  54. package/dist/plugins/sitemap.js +90 -0
  55. package/dist/plugins/takumi.d.ts +1 -1
  56. package/dist/plugins/takumi.js +3 -4
  57. package/dist/router/fs.js +1 -1
  58. package/dist/router/index.d.ts +17 -0
  59. package/dist/{router.js → router/index.js} +41 -26
  60. package/dist/vite.js +10 -10
  61. package/package.json +27 -9
  62. package/dist/lib/join-pathname.js +0 -9
  63. package/dist/router.d.ts +0 -15
@@ -0,0 +1,596 @@
1
+ import { __commonJSMin } from "../../../../../_virtual/_rolldown/runtime.js";
2
+ //#region ../../node_modules/.pnpm/http-cache-semantics@4.2.0/node_modules/http-cache-semantics/index.js
3
+ var require_http_cache_semantics = /* @__PURE__ */ __commonJSMin(((exports, module) => {
4
+ /**
5
+ * @typedef {Object} HttpRequest
6
+ * @property {Record<string, string>} headers - Request headers
7
+ * @property {string} [method] - HTTP method
8
+ * @property {string} [url] - Request URL
9
+ */
10
+ /**
11
+ * @typedef {Object} HttpResponse
12
+ * @property {Record<string, string>} headers - Response headers
13
+ * @property {number} [status] - HTTP status code
14
+ */
15
+ /**
16
+ * Set of default cacheable status codes per RFC 7231 section 6.1.
17
+ * @type {Set<number>}
18
+ */
19
+ const statusCodeCacheableByDefault = new Set([
20
+ 200,
21
+ 203,
22
+ 204,
23
+ 206,
24
+ 300,
25
+ 301,
26
+ 308,
27
+ 404,
28
+ 405,
29
+ 410,
30
+ 414,
31
+ 501
32
+ ]);
33
+ /**
34
+ * Set of HTTP status codes that the cache implementation understands.
35
+ * Note: This implementation does not understand partial responses (206).
36
+ * @type {Set<number>}
37
+ */
38
+ const understoodStatuses = new Set([
39
+ 200,
40
+ 203,
41
+ 204,
42
+ 300,
43
+ 301,
44
+ 302,
45
+ 303,
46
+ 307,
47
+ 308,
48
+ 404,
49
+ 405,
50
+ 410,
51
+ 414,
52
+ 501
53
+ ]);
54
+ /**
55
+ * Set of HTTP error status codes.
56
+ * @type {Set<number>}
57
+ */
58
+ const errorStatusCodes = new Set([
59
+ 500,
60
+ 502,
61
+ 503,
62
+ 504
63
+ ]);
64
+ /**
65
+ * Object representing hop-by-hop headers that should be removed.
66
+ * @type {Record<string, boolean>}
67
+ */
68
+ const hopByHopHeaders = {
69
+ date: true,
70
+ connection: true,
71
+ "keep-alive": true,
72
+ "proxy-authenticate": true,
73
+ "proxy-authorization": true,
74
+ te: true,
75
+ trailer: true,
76
+ "transfer-encoding": true,
77
+ upgrade: true
78
+ };
79
+ /**
80
+ * Headers that are excluded from revalidation update.
81
+ * @type {Record<string, boolean>}
82
+ */
83
+ const excludedFromRevalidationUpdate = {
84
+ "content-length": true,
85
+ "content-encoding": true,
86
+ "transfer-encoding": true,
87
+ "content-range": true
88
+ };
89
+ /**
90
+ * Converts a string to a number or returns zero if the conversion fails.
91
+ * @param {string} s - The string to convert.
92
+ * @returns {number} The parsed number or 0.
93
+ */
94
+ function toNumberOrZero(s) {
95
+ const n = parseInt(s, 10);
96
+ return isFinite(n) ? n : 0;
97
+ }
98
+ /**
99
+ * Determines if the given response is an error response.
100
+ * Implements RFC 5861 behavior.
101
+ * @param {HttpResponse|undefined} response - The HTTP response object.
102
+ * @returns {boolean} true if the response is an error or undefined, false otherwise.
103
+ */
104
+ function isErrorResponse(response) {
105
+ if (!response) return true;
106
+ return errorStatusCodes.has(response.status);
107
+ }
108
+ /**
109
+ * Parses a Cache-Control header string into an object.
110
+ * @param {string} [header] - The Cache-Control header value.
111
+ * @returns {Record<string, string|boolean>} An object representing Cache-Control directives.
112
+ */
113
+ function parseCacheControl(header) {
114
+ /** @type {Record<string, string|boolean>} */
115
+ const cc = {};
116
+ if (!header) return cc;
117
+ const parts = header.trim().split(/,/);
118
+ for (const part of parts) {
119
+ const [k, v] = part.split(/=/, 2);
120
+ cc[k.trim()] = v === void 0 ? true : v.trim().replace(/^"|"$/g, "");
121
+ }
122
+ return cc;
123
+ }
124
+ /**
125
+ * Formats a Cache-Control directives object into a header string.
126
+ * @param {Record<string, string|boolean>} cc - The Cache-Control directives.
127
+ * @returns {string|undefined} A formatted Cache-Control header string or undefined if empty.
128
+ */
129
+ function formatCacheControl(cc) {
130
+ let parts = [];
131
+ for (const k in cc) {
132
+ const v = cc[k];
133
+ parts.push(v === true ? k : k + "=" + v);
134
+ }
135
+ if (!parts.length) return;
136
+ return parts.join(", ");
137
+ }
138
+ module.exports = class CachePolicy {
139
+ /**
140
+ * Creates a new CachePolicy instance.
141
+ * @param {HttpRequest} req - Incoming client request.
142
+ * @param {HttpResponse} res - Received server response.
143
+ * @param {Object} [options={}] - Configuration options.
144
+ * @param {boolean} [options.shared=true] - Is the cache shared (a public proxy)? `false` for personal browser caches.
145
+ * @param {number} [options.cacheHeuristic=0.1] - Fallback heuristic (age fraction) for cache duration.
146
+ * @param {number} [options.immutableMinTimeToLive=86400000] - Minimum TTL for immutable responses in milliseconds.
147
+ * @param {boolean} [options.ignoreCargoCult=false] - Detect nonsense cache headers, and override them.
148
+ * @param {any} [options._fromObject] - Internal parameter for deserialization. Do not use.
149
+ */
150
+ constructor(req, res, { shared, cacheHeuristic, immutableMinTimeToLive, ignoreCargoCult, _fromObject } = {}) {
151
+ if (_fromObject) {
152
+ this._fromObject(_fromObject);
153
+ return;
154
+ }
155
+ if (!res || !res.headers) throw Error("Response headers missing");
156
+ this._assertRequestHasHeaders(req);
157
+ /** @type {number} Timestamp when the response was received */
158
+ this._responseTime = this.now();
159
+ /** @type {boolean} Indicates if the cache is shared */
160
+ this._isShared = shared !== false;
161
+ /** @type {boolean} Indicates if legacy cargo cult directives should be ignored */
162
+ this._ignoreCargoCult = !!ignoreCargoCult;
163
+ /** @type {number} Heuristic cache fraction */
164
+ this._cacheHeuristic = void 0 !== cacheHeuristic ? cacheHeuristic : .1;
165
+ /** @type {number} Minimum TTL for immutable responses in ms */
166
+ this._immutableMinTtl = void 0 !== immutableMinTimeToLive ? immutableMinTimeToLive : 24 * 3600 * 1e3;
167
+ /** @type {number} HTTP status code */
168
+ this._status = "status" in res ? res.status : 200;
169
+ /** @type {Record<string, string>} Response headers */
170
+ this._resHeaders = res.headers;
171
+ /** @type {Record<string, string|boolean>} Parsed Cache-Control directives from response */
172
+ this._rescc = parseCacheControl(res.headers["cache-control"]);
173
+ /** @type {string} HTTP method (e.g., GET, POST) */
174
+ this._method = "method" in req ? req.method : "GET";
175
+ /** @type {string} Request URL */
176
+ this._url = req.url;
177
+ /** @type {string} Host header from the request */
178
+ this._host = req.headers.host;
179
+ /** @type {boolean} Whether the request does not include an Authorization header */
180
+ this._noAuthorization = !req.headers.authorization;
181
+ /** @type {Record<string, string>|null} Request headers used for Vary matching */
182
+ this._reqHeaders = res.headers.vary ? req.headers : null;
183
+ /** @type {Record<string, string|boolean>} Parsed Cache-Control directives from request */
184
+ this._reqcc = parseCacheControl(req.headers["cache-control"]);
185
+ if (this._ignoreCargoCult && "pre-check" in this._rescc && "post-check" in this._rescc) {
186
+ delete this._rescc["pre-check"];
187
+ delete this._rescc["post-check"];
188
+ delete this._rescc["no-cache"];
189
+ delete this._rescc["no-store"];
190
+ delete this._rescc["must-revalidate"];
191
+ this._resHeaders = Object.assign({}, this._resHeaders, { "cache-control": formatCacheControl(this._rescc) });
192
+ delete this._resHeaders.expires;
193
+ delete this._resHeaders.pragma;
194
+ }
195
+ if (res.headers["cache-control"] == null && /no-cache/.test(res.headers.pragma)) this._rescc["no-cache"] = true;
196
+ }
197
+ /**
198
+ * You can monkey-patch it for testing.
199
+ * @returns {number} Current time in milliseconds.
200
+ */
201
+ now() {
202
+ return Date.now();
203
+ }
204
+ /**
205
+ * Determines if the response is storable in a cache.
206
+ * @returns {boolean} `false` if can never be cached.
207
+ */
208
+ storable() {
209
+ return !!(!this._reqcc["no-store"] && ("GET" === this._method || "HEAD" === this._method || "POST" === this._method && this._hasExplicitExpiration()) && understoodStatuses.has(this._status) && !this._rescc["no-store"] && (!this._isShared || !this._rescc.private) && (!this._isShared || this._noAuthorization || this._allowsStoringAuthenticated()) && (this._resHeaders.expires || this._rescc["max-age"] || this._isShared && this._rescc["s-maxage"] || this._rescc.public || statusCodeCacheableByDefault.has(this._status)));
210
+ }
211
+ /**
212
+ * @returns {boolean} true if expiration is explicitly defined.
213
+ */
214
+ _hasExplicitExpiration() {
215
+ return !!(this._isShared && this._rescc["s-maxage"] || this._rescc["max-age"] || this._resHeaders.expires);
216
+ }
217
+ /**
218
+ * @param {HttpRequest} req - a request
219
+ * @throws {Error} if the headers are missing.
220
+ */
221
+ _assertRequestHasHeaders(req) {
222
+ if (!req || !req.headers) throw Error("Request headers missing");
223
+ }
224
+ /**
225
+ * Checks if the request matches the cache and can be satisfied from the cache immediately,
226
+ * without having to make a request to the server.
227
+ *
228
+ * This doesn't support `stale-while-revalidate`. See `evaluateRequest()` for a more complete solution.
229
+ *
230
+ * @param {HttpRequest} req - The new incoming HTTP request.
231
+ * @returns {boolean} `true`` if the cached response used to construct this cache policy satisfies the request without revalidation.
232
+ */
233
+ satisfiesWithoutRevalidation(req) {
234
+ return !this.evaluateRequest(req).revalidation;
235
+ }
236
+ /**
237
+ * @param {{headers: Record<string, string>, synchronous: boolean}|undefined} revalidation - Revalidation information, if any.
238
+ * @returns {{response: {headers: Record<string, string>}, revalidation: {headers: Record<string, string>, synchronous: boolean}|undefined}} An object with a cached response headers and revalidation info.
239
+ */
240
+ _evaluateRequestHitResult(revalidation) {
241
+ return {
242
+ response: { headers: this.responseHeaders() },
243
+ revalidation
244
+ };
245
+ }
246
+ /**
247
+ * @param {HttpRequest} request - new incoming
248
+ * @param {boolean} synchronous - whether revalidation must be synchronous (not s-w-r).
249
+ * @returns {{headers: Record<string, string>, synchronous: boolean}} An object with revalidation headers and a synchronous flag.
250
+ */
251
+ _evaluateRequestRevalidation(request, synchronous) {
252
+ return {
253
+ synchronous,
254
+ headers: this.revalidationHeaders(request)
255
+ };
256
+ }
257
+ /**
258
+ * @param {HttpRequest} request - new incoming
259
+ * @returns {{response: undefined, revalidation: {headers: Record<string, string>, synchronous: boolean}}} An object indicating no cached response and revalidation details.
260
+ */
261
+ _evaluateRequestMissResult(request) {
262
+ return {
263
+ response: void 0,
264
+ revalidation: this._evaluateRequestRevalidation(request, true)
265
+ };
266
+ }
267
+ /**
268
+ * Checks if the given request matches this cache entry, and how the cache can be used to satisfy it. Returns an object with:
269
+ *
270
+ * ```
271
+ * {
272
+ * // If defined, you must send a request to the server.
273
+ * revalidation: {
274
+ * headers: {}, // HTTP headers to use when sending the revalidation response
275
+ * // If true, you MUST wait for a response from the server before using the cache
276
+ * // If false, this is stale-while-revalidate. The cache is stale, but you can use it while you update it asynchronously.
277
+ * synchronous: bool,
278
+ * },
279
+ * // If defined, you can use this cached response.
280
+ * response: {
281
+ * headers: {}, // Updated cached HTTP headers you must use when responding to the client
282
+ * },
283
+ * }
284
+ * ```
285
+ * @param {HttpRequest} req - new incoming HTTP request
286
+ * @returns {{response: {headers: Record<string, string>}|undefined, revalidation: {headers: Record<string, string>, synchronous: boolean}|undefined}} An object containing keys:
287
+ * - revalidation: { headers: Record<string, string>, synchronous: boolean } Set if you should send this to the origin server
288
+ * - response: { headers: Record<string, string> } Set if you can respond to the client with these cached headers
289
+ */
290
+ evaluateRequest(req) {
291
+ this._assertRequestHasHeaders(req);
292
+ if (this._rescc["must-revalidate"]) return this._evaluateRequestMissResult(req);
293
+ if (!this._requestMatches(req, false)) return this._evaluateRequestMissResult(req);
294
+ const requestCC = parseCacheControl(req.headers["cache-control"]);
295
+ if (requestCC["no-cache"] || /no-cache/.test(req.headers.pragma)) return this._evaluateRequestMissResult(req);
296
+ if (requestCC["max-age"] && this.age() > toNumberOrZero(requestCC["max-age"])) return this._evaluateRequestMissResult(req);
297
+ if (requestCC["min-fresh"] && this.maxAge() - this.age() < toNumberOrZero(requestCC["min-fresh"])) return this._evaluateRequestMissResult(req);
298
+ if (this.stale()) {
299
+ if ("max-stale" in requestCC && (true === requestCC["max-stale"] || requestCC["max-stale"] > this.age() - this.maxAge())) return this._evaluateRequestHitResult(void 0);
300
+ if (this.useStaleWhileRevalidate()) return this._evaluateRequestHitResult(this._evaluateRequestRevalidation(req, false));
301
+ return this._evaluateRequestMissResult(req);
302
+ }
303
+ return this._evaluateRequestHitResult(void 0);
304
+ }
305
+ /**
306
+ * @param {HttpRequest} req - check if this is for the same cache entry
307
+ * @param {boolean} allowHeadMethod - allow a HEAD method to match.
308
+ * @returns {boolean} `true` if the request matches.
309
+ */
310
+ _requestMatches(req, allowHeadMethod) {
311
+ return !!((!this._url || this._url === req.url) && this._host === req.headers.host && (!req.method || this._method === req.method || allowHeadMethod && "HEAD" === req.method) && this._varyMatches(req));
312
+ }
313
+ /**
314
+ * Determines whether storing authenticated responses is allowed.
315
+ * @returns {boolean} `true` if allowed.
316
+ */
317
+ _allowsStoringAuthenticated() {
318
+ return !!(this._rescc["must-revalidate"] || this._rescc.public || this._rescc["s-maxage"]);
319
+ }
320
+ /**
321
+ * Checks whether the Vary header in the response matches the new request.
322
+ * @param {HttpRequest} req - incoming HTTP request
323
+ * @returns {boolean} `true` if the vary headers match.
324
+ */
325
+ _varyMatches(req) {
326
+ if (!this._resHeaders.vary) return true;
327
+ if (this._resHeaders.vary === "*") return false;
328
+ const fields = this._resHeaders.vary.trim().toLowerCase().split(/\s*,\s*/);
329
+ for (const name of fields) if (req.headers[name] !== this._reqHeaders[name]) return false;
330
+ return true;
331
+ }
332
+ /**
333
+ * Creates a copy of the given headers without any hop-by-hop headers.
334
+ * @param {Record<string, string>} inHeaders - old headers from the cached response
335
+ * @returns {Record<string, string>} A new headers object without hop-by-hop headers.
336
+ */
337
+ _copyWithoutHopByHopHeaders(inHeaders) {
338
+ /** @type {Record<string, string>} */
339
+ const headers = {};
340
+ for (const name in inHeaders) {
341
+ if (hopByHopHeaders[name]) continue;
342
+ headers[name] = inHeaders[name];
343
+ }
344
+ if (inHeaders.connection) {
345
+ const tokens = inHeaders.connection.trim().split(/\s*,\s*/);
346
+ for (const name of tokens) delete headers[name];
347
+ }
348
+ if (headers.warning) {
349
+ const warnings = headers.warning.split(/,/).filter((warning) => {
350
+ return !/^\s*1[0-9][0-9]/.test(warning);
351
+ });
352
+ if (!warnings.length) delete headers.warning;
353
+ else headers.warning = warnings.join(",").trim();
354
+ }
355
+ return headers;
356
+ }
357
+ /**
358
+ * Returns the response headers adjusted for serving the cached response.
359
+ * Removes hop-by-hop headers and updates the Age and Date headers.
360
+ * @returns {Record<string, string>} The adjusted response headers.
361
+ */
362
+ responseHeaders() {
363
+ const headers = this._copyWithoutHopByHopHeaders(this._resHeaders);
364
+ const age = this.age();
365
+ if (age > 3600 * 24 && !this._hasExplicitExpiration() && this.maxAge() > 3600 * 24) headers.warning = (headers.warning ? `${headers.warning}, ` : "") + "113 - \"rfc7234 5.5.4\"";
366
+ headers.age = `${Math.round(age)}`;
367
+ headers.date = new Date(this.now()).toUTCString();
368
+ return headers;
369
+ }
370
+ /**
371
+ * Returns the Date header value from the response or the current time if invalid.
372
+ * @returns {number} Timestamp (in milliseconds) representing the Date header or response time.
373
+ */
374
+ date() {
375
+ const serverDate = Date.parse(this._resHeaders.date);
376
+ if (isFinite(serverDate)) return serverDate;
377
+ return this._responseTime;
378
+ }
379
+ /**
380
+ * Value of the Age header, in seconds, updated for the current time.
381
+ * May be fractional.
382
+ * @returns {number} The age in seconds.
383
+ */
384
+ age() {
385
+ return this._ageValue() + (this.now() - this._responseTime) / 1e3;
386
+ }
387
+ /**
388
+ * @returns {number} The Age header value as a number.
389
+ */
390
+ _ageValue() {
391
+ return toNumberOrZero(this._resHeaders.age);
392
+ }
393
+ /**
394
+ * Possibly outdated value of applicable max-age (or heuristic equivalent) in seconds.
395
+ * This counts since response's `Date`.
396
+ *
397
+ * For an up-to-date value, see `timeToLive()`.
398
+ *
399
+ * Returns the maximum age (freshness lifetime) of the response in seconds.
400
+ * @returns {number} The max-age value in seconds.
401
+ */
402
+ maxAge() {
403
+ if (!this.storable() || this._rescc["no-cache"]) return 0;
404
+ if (this._isShared && this._resHeaders["set-cookie"] && !this._rescc.public && !this._rescc.immutable) return 0;
405
+ if (this._resHeaders.vary === "*") return 0;
406
+ if (this._isShared) {
407
+ if (this._rescc["proxy-revalidate"]) return 0;
408
+ if (this._rescc["s-maxage"]) return toNumberOrZero(this._rescc["s-maxage"]);
409
+ }
410
+ if (this._rescc["max-age"]) return toNumberOrZero(this._rescc["max-age"]);
411
+ const defaultMinTtl = this._rescc.immutable ? this._immutableMinTtl : 0;
412
+ const serverDate = this.date();
413
+ if (this._resHeaders.expires) {
414
+ const expires = Date.parse(this._resHeaders.expires);
415
+ if (Number.isNaN(expires) || expires < serverDate) return 0;
416
+ return Math.max(defaultMinTtl, (expires - serverDate) / 1e3);
417
+ }
418
+ if (this._resHeaders["last-modified"]) {
419
+ const lastModified = Date.parse(this._resHeaders["last-modified"]);
420
+ if (isFinite(lastModified) && serverDate > lastModified) return Math.max(defaultMinTtl, (serverDate - lastModified) / 1e3 * this._cacheHeuristic);
421
+ }
422
+ return defaultMinTtl;
423
+ }
424
+ /**
425
+ * Remaining time this cache entry may be useful for, in *milliseconds*.
426
+ * You can use this as an expiration time for your cache storage.
427
+ *
428
+ * Prefer this method over `maxAge()`, because it includes other factors like `age` and `stale-while-revalidate`.
429
+ * @returns {number} Time-to-live in milliseconds.
430
+ */
431
+ timeToLive() {
432
+ const age = this.maxAge() - this.age();
433
+ const staleIfErrorAge = age + toNumberOrZero(this._rescc["stale-if-error"]);
434
+ const staleWhileRevalidateAge = age + toNumberOrZero(this._rescc["stale-while-revalidate"]);
435
+ return Math.round(Math.max(0, age, staleIfErrorAge, staleWhileRevalidateAge) * 1e3);
436
+ }
437
+ /**
438
+ * If true, this cache entry is past its expiration date.
439
+ * Note that stale cache may be useful sometimes, see `evaluateRequest()`.
440
+ * @returns {boolean} `false` doesn't mean it's fresh nor usable
441
+ */
442
+ stale() {
443
+ return this.maxAge() <= this.age();
444
+ }
445
+ /**
446
+ * @returns {boolean} `true` if `stale-if-error` condition allows use of a stale response.
447
+ */
448
+ _useStaleIfError() {
449
+ return this.maxAge() + toNumberOrZero(this._rescc["stale-if-error"]) > this.age();
450
+ }
451
+ /** See `evaluateRequest()` for a more complete solution
452
+ * @returns {boolean} `true` if `stale-while-revalidate` is currently allowed.
453
+ */
454
+ useStaleWhileRevalidate() {
455
+ const swr = toNumberOrZero(this._rescc["stale-while-revalidate"]);
456
+ return swr > 0 && this.maxAge() + swr > this.age();
457
+ }
458
+ /**
459
+ * Creates a `CachePolicy` instance from a serialized object.
460
+ * @param {Object} obj - The serialized object.
461
+ * @returns {CachePolicy} A new CachePolicy instance.
462
+ */
463
+ static fromObject(obj) {
464
+ return new this(void 0, void 0, { _fromObject: obj });
465
+ }
466
+ /**
467
+ * @param {any} obj - The serialized object.
468
+ * @throws {Error} If already initialized or if the object is invalid.
469
+ */
470
+ _fromObject(obj) {
471
+ if (this._responseTime) throw Error("Reinitialized");
472
+ if (!obj || obj.v !== 1) throw Error("Invalid serialization");
473
+ this._responseTime = obj.t;
474
+ this._isShared = obj.sh;
475
+ this._cacheHeuristic = obj.ch;
476
+ this._immutableMinTtl = obj.imm !== void 0 ? obj.imm : 24 * 3600 * 1e3;
477
+ this._ignoreCargoCult = !!obj.icc;
478
+ this._status = obj.st;
479
+ this._resHeaders = obj.resh;
480
+ this._rescc = obj.rescc;
481
+ this._method = obj.m;
482
+ this._url = obj.u;
483
+ this._host = obj.h;
484
+ this._noAuthorization = obj.a;
485
+ this._reqHeaders = obj.reqh;
486
+ this._reqcc = obj.reqcc;
487
+ }
488
+ /**
489
+ * Serializes the `CachePolicy` instance into a JSON-serializable object.
490
+ * @returns {Object} The serialized object.
491
+ */
492
+ toObject() {
493
+ return {
494
+ v: 1,
495
+ t: this._responseTime,
496
+ sh: this._isShared,
497
+ ch: this._cacheHeuristic,
498
+ imm: this._immutableMinTtl,
499
+ icc: this._ignoreCargoCult,
500
+ st: this._status,
501
+ resh: this._resHeaders,
502
+ rescc: this._rescc,
503
+ m: this._method,
504
+ u: this._url,
505
+ h: this._host,
506
+ a: this._noAuthorization,
507
+ reqh: this._reqHeaders,
508
+ reqcc: this._reqcc
509
+ };
510
+ }
511
+ /**
512
+ * Headers for sending to the origin server to revalidate stale response.
513
+ * Allows server to return 304 to allow reuse of the previous response.
514
+ *
515
+ * Hop by hop headers are always stripped.
516
+ * Revalidation headers may be added or removed, depending on request.
517
+ * @param {HttpRequest} incomingReq - The incoming HTTP request.
518
+ * @returns {Record<string, string>} The headers for the revalidation request.
519
+ */
520
+ revalidationHeaders(incomingReq) {
521
+ this._assertRequestHasHeaders(incomingReq);
522
+ const headers = this._copyWithoutHopByHopHeaders(incomingReq.headers);
523
+ delete headers["if-range"];
524
+ if (!this._requestMatches(incomingReq, true) || !this.storable()) {
525
+ delete headers["if-none-match"];
526
+ delete headers["if-modified-since"];
527
+ return headers;
528
+ }
529
+ if (this._resHeaders.etag) headers["if-none-match"] = headers["if-none-match"] ? `${headers["if-none-match"]}, ${this._resHeaders.etag}` : this._resHeaders.etag;
530
+ if (headers["accept-ranges"] || headers["if-match"] || headers["if-unmodified-since"] || this._method && this._method != "GET") {
531
+ delete headers["if-modified-since"];
532
+ if (headers["if-none-match"]) {
533
+ const etags = headers["if-none-match"].split(/,/).filter((etag) => {
534
+ return !/^\s*W\//.test(etag);
535
+ });
536
+ if (!etags.length) delete headers["if-none-match"];
537
+ else headers["if-none-match"] = etags.join(",").trim();
538
+ }
539
+ } else if (this._resHeaders["last-modified"] && !headers["if-modified-since"]) headers["if-modified-since"] = this._resHeaders["last-modified"];
540
+ return headers;
541
+ }
542
+ /**
543
+ * Creates new CachePolicy with information combined from the previews response,
544
+ * and the new revalidation response.
545
+ *
546
+ * Returns {policy, modified} where modified is a boolean indicating
547
+ * whether the response body has been modified, and old cached body can't be used.
548
+ *
549
+ * @param {HttpRequest} request - The latest HTTP request asking for the cached entry.
550
+ * @param {HttpResponse} response - The latest revalidation HTTP response from the origin server.
551
+ * @returns {{policy: CachePolicy, modified: boolean, matches: boolean}} The updated policy and modification status.
552
+ * @throws {Error} If the response headers are missing.
553
+ */
554
+ revalidatedPolicy(request, response) {
555
+ this._assertRequestHasHeaders(request);
556
+ if (this._useStaleIfError() && isErrorResponse(response)) return {
557
+ policy: this,
558
+ modified: false,
559
+ matches: true
560
+ };
561
+ if (!response || !response.headers) throw Error("Response headers missing");
562
+ let matches = false;
563
+ if (response.status !== void 0 && response.status != 304) matches = false;
564
+ else if (response.headers.etag && !/^\s*W\//.test(response.headers.etag)) matches = this._resHeaders.etag && this._resHeaders.etag.replace(/^\s*W\//, "") === response.headers.etag;
565
+ else if (this._resHeaders.etag && response.headers.etag) matches = this._resHeaders.etag.replace(/^\s*W\//, "") === response.headers.etag.replace(/^\s*W\//, "");
566
+ else if (this._resHeaders["last-modified"]) matches = this._resHeaders["last-modified"] === response.headers["last-modified"];
567
+ else if (!this._resHeaders.etag && !this._resHeaders["last-modified"] && !response.headers.etag && !response.headers["last-modified"]) matches = true;
568
+ const optionsCopy = {
569
+ shared: this._isShared,
570
+ cacheHeuristic: this._cacheHeuristic,
571
+ immutableMinTimeToLive: this._immutableMinTtl,
572
+ ignoreCargoCult: this._ignoreCargoCult
573
+ };
574
+ if (!matches) return {
575
+ policy: new this.constructor(request, response, optionsCopy),
576
+ modified: response.status != 304,
577
+ matches: false
578
+ };
579
+ const headers = {};
580
+ for (const k in this._resHeaders) headers[k] = k in response.headers && !excludedFromRevalidationUpdate[k] ? response.headers[k] : this._resHeaders[k];
581
+ const newResponse = Object.assign({}, response, {
582
+ status: this._status,
583
+ method: this._method,
584
+ headers
585
+ });
586
+ return {
587
+ policy: new this.constructor(request, newResponse, optionsCopy),
588
+ modified: false,
589
+ matches: true
590
+ };
591
+ }
592
+ };
593
+ }));
594
+ //#endregion
595
+ export default require_http_cache_semantics();
596
+ export { require_http_cache_semantics };
@@ -6,7 +6,7 @@ import { FC, ReactNode } from "react";
6
6
  //#region src/plugins/blog.d.ts
7
7
  interface BlogPluginOptions<C extends ConfigContext = ConfigContext> {
8
8
  /** default to checking from `page.type` */
9
- isBlog?: (this: AppContext<C>, page: C["loaderConfig"]["page"]) => boolean;
9
+ isBlog?: (this: AppContext<C>, page: C["page"]) => boolean;
10
10
  paths?: {
11
11
  /**
12
12
  * pathname for index page
@@ -32,16 +32,13 @@ interface BlogPluginOptions<C extends ConfigContext = ConfigContext> {
32
32
  interface BlogContext<C extends ConfigContext = ConfigContext> {
33
33
  indexPath: string | false;
34
34
  tagsPath: string | false;
35
- isBlog: (this: AppContext<C>, page: C["loaderConfig"]["page"]) => boolean;
36
- }
37
- declare global {
38
- var blogContextTemp: BlogContext | undefined;
35
+ isBlog: (this: AppContext<C>, page: C["page"]) => boolean;
39
36
  }
40
37
  declare function getBlogContext<C extends ConfigContext = ConfigContext>(): BlogContext<C>;
41
38
  type BlogLayoutPage<C extends ConfigContext = ConfigContext> = FC<{
42
39
  lang?: string;
43
40
  slugs: string[];
44
- page: C["loaderConfig"]["page"];
41
+ page: C["page"];
45
42
  }> & {
46
43
  $ctx?: C;
47
44
  };
@@ -1,5 +1,5 @@
1
1
  import { groupTags, groupTagsI18n } from "../lib/shared/blog.js";
2
- import { joinPathname } from "../lib/join-pathname.js";
2
+ import { joinPathname } from "../lib/pathname.js";
3
3
  import { createBlogLayout, createBlogLayoutPage } from "../layouts/blog.js";
4
4
  import { createBlogTagPage, createBlogTagsPage } from "../layouts/blog.tags.js";
5
5
  import { createBlogIndexPage } from "../layouts/blog.index.js";
@@ -8,9 +8,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
8
8
  //#region src/plugins/blog.tsx
9
9
  const blogContext = new AsyncLocalStorage({ name: "fumapress:blog" });
10
10
  function getBlogContext() {
11
- let store = blogContext.getStore();
12
- if (!store) store = global.blogContextTemp;
13
- else delete global.blogContextTemp;
11
+ const store = blogContext.getStore();
14
12
  if (!store) throw new Error("[Fumapress] Missing blog context for Fumapress, make sure the blog plugin is configured");
15
13
  return store;
16
14
  }
@@ -38,10 +36,12 @@ function blogPlugin({ paths = {}, isBlog = (page) => page.type === "blog", layou
38
36
  createMiddlewares() {
39
37
  return [(_c, next) => blogContext.run(blogCtx, next)];
40
38
  },
39
+ unstable_onSSGRequest(_req, next) {
40
+ return blogContext.run(blogCtx, next);
41
+ },
41
42
  async createPages({ createPage, createLayout }) {
42
43
  const renderMode = this.mode === "default" ? "static" : this.mode;
43
- const blogPages = (await this.getLoader()).getPages().filter((page) => isBlog.call(this, page));
44
- if (import.meta.env.PROD) global.blogContextTemp = blogCtx;
44
+ const blogPages = (await this.getLoader()).getPages().filter(isBlog.bind(this));
45
45
  createLayout({
46
46
  render: renderMode,
47
47
  path: this.i18nConfig ? "/[lang]/(blog)" : "/(blog)",
@@ -5,7 +5,7 @@ import { Index } from "fumadocs-core/search/flexsearch";
5
5
 
6
6
  //#region src/plugins/flexsearch.d.ts
7
7
  interface FlexsearchOptions<C extends ConfigContext = ConfigContext> {
8
- buildIndex?: (this: AppContext<C>, page: C["loaderConfig"]["page"]) => Awaitable<Index>;
8
+ buildIndex?: (this: AppContext<C>, page: C["page"]) => Awaitable<Index>;
9
9
  }
10
10
  declare function flexsearchPlugin<C extends ConfigContext = ConfigContext>({
11
11
  buildIndex