@stati/core 1.6.3 → 1.6.4
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/README.md +1 -1
- package/dist/core/build.js +3 -2
- package/dist/core/invalidate.d.ts.map +1 -1
- package/dist/core/invalidate.js +11 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -159,7 +159,7 @@ await invalidate('path:/posts');
|
|
|
159
159
|
// Invalidate by glob pattern
|
|
160
160
|
await invalidate('glob:/blog/**');
|
|
161
161
|
|
|
162
|
-
// Invalidate content younger than 3 months
|
|
162
|
+
// Invalidate content younger than 3 months (exact calendar arithmetic)
|
|
163
163
|
await invalidate('age:3months');
|
|
164
164
|
|
|
165
165
|
// Multiple criteria (OR logic)
|
package/dist/core/build.js
CHANGED
|
@@ -346,10 +346,11 @@ async function buildInternal(options = {}) {
|
|
|
346
346
|
// Initialize cache stats
|
|
347
347
|
let cacheHits = 0;
|
|
348
348
|
let cacheMisses = 0;
|
|
349
|
-
// Clean output directory if requested
|
|
349
|
+
// Clean output directory and cache if requested
|
|
350
350
|
if (options.clean) {
|
|
351
|
-
logger.info('Cleaning output directory...');
|
|
351
|
+
logger.info('Cleaning output directory and ISG cache...');
|
|
352
352
|
await remove(outDir);
|
|
353
|
+
await remove(cacheDir);
|
|
353
354
|
}
|
|
354
355
|
await ensureDir(outDir);
|
|
355
356
|
// Load content and build navigation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalidate.d.ts","sourceRoot":"","sources":["../../src/core/invalidate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,gBAAgB,EAAE,MAAM,CAAC;IACzB,iCAAiC;IACjC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,2CAA2C;IAC3C,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAkC9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAkC9F;
|
|
1
|
+
{"version":3,"file":"invalidate.d.ts","sourceRoot":"","sources":["../../src/core/invalidate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,gBAAgB,EAAE,MAAM,CAAC;IACzB,iCAAiC;IACjC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,2CAA2C;IAC3C,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAkC9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAkC9F;AAuLD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAoD5E"}
|
package/dist/core/invalidate.js
CHANGED
|
@@ -203,14 +203,18 @@ function globToRegex(pattern) {
|
|
|
203
203
|
* Checks if a cache entry matches an age-based invalidation term.
|
|
204
204
|
* Supports various time units: days, weeks, months, years.
|
|
205
205
|
*
|
|
206
|
+
* Uses proper date arithmetic for months and years to handle varying month lengths
|
|
207
|
+
* and leap years accurately. Days and weeks use simple day arithmetic for consistency.
|
|
208
|
+
*
|
|
206
209
|
* @param entry - Cache entry to check
|
|
207
210
|
* @param ageValue - Age specification (e.g., "3months", "1week", "30days")
|
|
208
211
|
* @returns True if the entry is younger than the specified age
|
|
209
212
|
*
|
|
210
213
|
* @example
|
|
211
214
|
* ```typescript
|
|
212
|
-
* matchesAge(entry, "3months") // true if rendered within the last 3 months
|
|
213
|
-
* matchesAge(entry, "1week") // true if rendered within the last 1 week
|
|
215
|
+
* matchesAge(entry, "3months") // true if rendered within the last 3 months (using exact month arithmetic)
|
|
216
|
+
* matchesAge(entry, "1week") // true if rendered within the last 1 week (7 days)
|
|
217
|
+
* matchesAge(entry, "1year") // true if rendered within the last 1 year (using exact year arithmetic)
|
|
214
218
|
* ```
|
|
215
219
|
*/
|
|
216
220
|
function matchesAge(entry, ageValue) {
|
|
@@ -229,7 +233,7 @@ function matchesAge(entry, ageValue) {
|
|
|
229
233
|
console.warn(`Invalid age number: ${numStr}`);
|
|
230
234
|
return false;
|
|
231
235
|
}
|
|
232
|
-
// Calculate cutoff date
|
|
236
|
+
// Calculate cutoff date using appropriate date arithmetic
|
|
233
237
|
const cutoffDate = new Date(now);
|
|
234
238
|
switch (unit.toLowerCase()) {
|
|
235
239
|
case 'day':
|
|
@@ -242,18 +246,20 @@ function matchesAge(entry, ageValue) {
|
|
|
242
246
|
break;
|
|
243
247
|
case 'month':
|
|
244
248
|
case 'months':
|
|
249
|
+
// Use proper month arithmetic to handle varying month lengths
|
|
245
250
|
cutoffDate.setMonth(cutoffDate.getMonth() - num);
|
|
246
251
|
break;
|
|
247
252
|
case 'year':
|
|
248
253
|
case 'years':
|
|
254
|
+
// Use proper year arithmetic to handle leap years
|
|
249
255
|
cutoffDate.setFullYear(cutoffDate.getFullYear() - num);
|
|
250
256
|
break;
|
|
251
257
|
default:
|
|
252
258
|
console.warn(`Unknown time unit: ${unit}`);
|
|
253
259
|
return false;
|
|
254
260
|
}
|
|
255
|
-
// Entry matches if it was rendered after the cutoff date (i.e., younger than specified age)
|
|
256
|
-
return renderedAt
|
|
261
|
+
// Entry matches if it was rendered after or on the cutoff date (i.e., younger than or equal to specified age)
|
|
262
|
+
return renderedAt >= cutoffDate;
|
|
257
263
|
}
|
|
258
264
|
/**
|
|
259
265
|
* Invalidates cache entries based on a query string.
|