submitnow-mcp 0.0.0-stage → 2.2.0
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/LICENSE +21 -0
- package/README.md +53 -2
- package/dist/cli/submitnow.js +182 -0
- package/dist/lib/indexnow-endpoints.js +83 -0
- package/dist/lib/indexnow-runtime.js +614 -0
- package/dist/lib/safe-fetch.js +397 -0
- package/dist/lib/seo-tools.js +517 -0
- package/dist/mcp/server.js +312 -0
- package/package.json +46 -4
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
export const MAX_INDEXNOW_BATCH_SIZE = 10_000;
|
|
2
|
+
/**
|
|
3
|
+
* Safe per-batch UTF-8 payload cap (~2 MB) so even long URLs stay well inside
|
|
4
|
+
* Next.js Server Action and IndexNow endpoint payload budgets.
|
|
5
|
+
*/
|
|
6
|
+
export const MAX_INDEXNOW_BATCH_BYTES = 2 * 1024 * 1024;
|
|
7
|
+
function parseHttpUrl(input) {
|
|
8
|
+
try {
|
|
9
|
+
const url = new URL(input);
|
|
10
|
+
return url.protocol === "http:" || url.protocol === "https:" ? url : null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function analyzeUrlList(raw) {
|
|
17
|
+
const inputs = raw
|
|
18
|
+
.split(/[\r\n,\s]+/)
|
|
19
|
+
.map((item) => item.trim())
|
|
20
|
+
.filter(Boolean);
|
|
21
|
+
const validUrls = [];
|
|
22
|
+
const invalidInputs = [];
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const groups = new Map();
|
|
25
|
+
let duplicateCount = 0;
|
|
26
|
+
for (const input of inputs) {
|
|
27
|
+
const parsed = parseHttpUrl(input);
|
|
28
|
+
if (!parsed) {
|
|
29
|
+
invalidInputs.push(input);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const normalizedUrl = parsed.toString();
|
|
33
|
+
if (seen.has(normalizedUrl)) {
|
|
34
|
+
duplicateCount += 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
seen.add(normalizedUrl);
|
|
38
|
+
validUrls.push(normalizedUrl);
|
|
39
|
+
const group = groups.get(parsed.hostname) ?? [];
|
|
40
|
+
group.push(normalizedUrl);
|
|
41
|
+
groups.set(parsed.hostname, group);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
inputCount: inputs.length,
|
|
45
|
+
validUrls,
|
|
46
|
+
invalidInputs,
|
|
47
|
+
duplicateCount,
|
|
48
|
+
hostGroups: Array.from(groups, ([host, urls]) => ({ host, urls })),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function chunkUrls(urls, chunkSize = MAX_INDEXNOW_BATCH_SIZE, maxBytes = MAX_INDEXNOW_BATCH_BYTES) {
|
|
52
|
+
if (urls.length === 0)
|
|
53
|
+
return [];
|
|
54
|
+
const safeSize = Math.max(1, Math.floor(chunkSize));
|
|
55
|
+
const safeBytes = Math.max(1024, Math.floor(maxBytes));
|
|
56
|
+
const encoder = new TextEncoder();
|
|
57
|
+
const chunks = [];
|
|
58
|
+
let current = [];
|
|
59
|
+
let currentBytes = 0;
|
|
60
|
+
for (const url of urls) {
|
|
61
|
+
const urlBytes = encoder.encode(url).byteLength + 1;
|
|
62
|
+
if (current.length > 0 &&
|
|
63
|
+
(current.length >= safeSize || currentBytes + urlBytes > safeBytes)) {
|
|
64
|
+
chunks.push(current);
|
|
65
|
+
current = [];
|
|
66
|
+
currentBytes = 0;
|
|
67
|
+
}
|
|
68
|
+
current.push(url);
|
|
69
|
+
currentBytes += urlBytes;
|
|
70
|
+
}
|
|
71
|
+
if (current.length > 0) {
|
|
72
|
+
chunks.push(current);
|
|
73
|
+
}
|
|
74
|
+
return chunks;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Extracts unique valid http(s) Sitemap URLs declared in a robots.txt body.
|
|
78
|
+
*/
|
|
79
|
+
export function parseRobotsTxtSitemaps(robotsTxt) {
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
const sitemaps = [];
|
|
82
|
+
for (const line of robotsTxt.split(/\r?\n/)) {
|
|
83
|
+
const stripped = line.replace(/#.*$/, "").trim();
|
|
84
|
+
const match = /^sitemap\s*:\s*(.+)$/i.exec(stripped);
|
|
85
|
+
if (!match)
|
|
86
|
+
continue;
|
|
87
|
+
const parsed = parseHttpUrl(match[1].trim());
|
|
88
|
+
if (!parsed)
|
|
89
|
+
continue;
|
|
90
|
+
const normalized = parsed.toString();
|
|
91
|
+
if (!seen.has(normalized)) {
|
|
92
|
+
seen.add(normalized);
|
|
93
|
+
sitemaps.push(normalized);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return sitemaps;
|
|
97
|
+
}
|
|
98
|
+
const TRACKING_PARAMETERS = new Set([
|
|
99
|
+
"fbclid",
|
|
100
|
+
"gclid",
|
|
101
|
+
"dclid",
|
|
102
|
+
"msclkid",
|
|
103
|
+
"mc_cid",
|
|
104
|
+
"mc_eid",
|
|
105
|
+
]);
|
|
106
|
+
function isTrackingParameter(name) {
|
|
107
|
+
return (name.toLowerCase().startsWith("utm_") ||
|
|
108
|
+
TRACKING_PARAMETERS.has(name.toLowerCase()));
|
|
109
|
+
}
|
|
110
|
+
export function normalizeUrlList(raw, options) {
|
|
111
|
+
return raw
|
|
112
|
+
.split(/\r?\n/)
|
|
113
|
+
.map((value) => value.trim())
|
|
114
|
+
.filter(Boolean)
|
|
115
|
+
.map((original) => {
|
|
116
|
+
let url;
|
|
117
|
+
try {
|
|
118
|
+
url = new URL(original);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return { original, changes: [], error: "invalid_url" };
|
|
122
|
+
}
|
|
123
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
124
|
+
return { original, changes: [], error: "unsupported_protocol" };
|
|
125
|
+
}
|
|
126
|
+
const changes = [];
|
|
127
|
+
if (options.removeFragment && url.hash) {
|
|
128
|
+
url.hash = "";
|
|
129
|
+
changes.push("fragment_removed");
|
|
130
|
+
}
|
|
131
|
+
if (options.removeTrackingParameters) {
|
|
132
|
+
const names = Array.from(url.searchParams.keys());
|
|
133
|
+
const removed = names.filter(isTrackingParameter);
|
|
134
|
+
removed.forEach((name) => url.searchParams.delete(name));
|
|
135
|
+
if (removed.length > 0)
|
|
136
|
+
changes.push("tracking_removed");
|
|
137
|
+
}
|
|
138
|
+
if (options.sortQueryParameters && url.search) {
|
|
139
|
+
const before = url.search;
|
|
140
|
+
url.searchParams.sort();
|
|
141
|
+
if (url.search !== before)
|
|
142
|
+
changes.push("query_sorted");
|
|
143
|
+
}
|
|
144
|
+
if (options.removeTrailingSlash &&
|
|
145
|
+
url.pathname.length > 1 &&
|
|
146
|
+
url.pathname.endsWith("/")) {
|
|
147
|
+
url.pathname = url.pathname.replace(/\/+$/, "");
|
|
148
|
+
changes.push("trailing_slash_removed");
|
|
149
|
+
}
|
|
150
|
+
const normalized = url.toString();
|
|
151
|
+
if (normalized !== original && changes.length === 0) {
|
|
152
|
+
changes.push("canonicalized");
|
|
153
|
+
}
|
|
154
|
+
return { original, normalized, changes };
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function getElementsByLocalName(document, localName) {
|
|
158
|
+
const namespaced = Array.from(document.getElementsByTagNameNS("*", localName));
|
|
159
|
+
return namespaced.length > 0
|
|
160
|
+
? namespaced
|
|
161
|
+
: Array.from(document.getElementsByTagName(localName));
|
|
162
|
+
}
|
|
163
|
+
function getChildText(element, localName) {
|
|
164
|
+
const child = Array.from(element.children).find((candidate) => candidate.localName === localName || candidate.nodeName === localName);
|
|
165
|
+
const value = child?.textContent?.trim();
|
|
166
|
+
return value || undefined;
|
|
167
|
+
}
|
|
168
|
+
function normalizeSitemapLocation(location) {
|
|
169
|
+
const parsed = parseHttpUrl(location.trim());
|
|
170
|
+
return parsed?.toString() ?? null;
|
|
171
|
+
}
|
|
172
|
+
function decodeXmlEntities(raw) {
|
|
173
|
+
const unwrapped = raw
|
|
174
|
+
.trim()
|
|
175
|
+
.replace(/^<!\[CDATA\[([\s\S]*?)\]\]>$/, "$1")
|
|
176
|
+
.trim();
|
|
177
|
+
return unwrapped.replace(/&(#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/g, (match, entity) => {
|
|
178
|
+
switch (entity) {
|
|
179
|
+
case "amp":
|
|
180
|
+
return "&";
|
|
181
|
+
case "lt":
|
|
182
|
+
return "<";
|
|
183
|
+
case "gt":
|
|
184
|
+
return ">";
|
|
185
|
+
case "quot":
|
|
186
|
+
return '"';
|
|
187
|
+
case "apos":
|
|
188
|
+
return "'";
|
|
189
|
+
default:
|
|
190
|
+
if (entity.startsWith("#x") || entity.startsWith("#X")) {
|
|
191
|
+
const code = parseInt(entity.slice(2), 16);
|
|
192
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
193
|
+
}
|
|
194
|
+
if (entity.startsWith("#")) {
|
|
195
|
+
const code = parseInt(entity.slice(1), 10);
|
|
196
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
197
|
+
}
|
|
198
|
+
return match;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function extractFirstTagText(block, localName) {
|
|
203
|
+
const regex = new RegExp(`<(?:[\\w-]+:)?${localName}(?:\\s[^>]*)?>([\\s\\S]*?)<\\/(?:[\\w-]+:)?${localName}>`, "i");
|
|
204
|
+
const match = regex.exec(block);
|
|
205
|
+
if (!match)
|
|
206
|
+
return undefined;
|
|
207
|
+
const decoded = decodeXmlEntities(match[1]);
|
|
208
|
+
return decoded || undefined;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Pure-JS XML sitemap parser that runs identically in Node.js (Server Actions,
|
|
212
|
+
* unit tests) and browsers. Supports namespaces, CDATA, XML entities,
|
|
213
|
+
* `<urlset>`, and `<sitemapindex>`.
|
|
214
|
+
*/
|
|
215
|
+
export function parseSitemapXmlString(xml) {
|
|
216
|
+
const cleaned = xml
|
|
217
|
+
.replace(/^\uFEFF/, "")
|
|
218
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
219
|
+
.trim();
|
|
220
|
+
if (!cleaned || !cleaned.startsWith("<")) {
|
|
221
|
+
return {
|
|
222
|
+
type: "unsupported",
|
|
223
|
+
entries: [],
|
|
224
|
+
childSitemaps: [],
|
|
225
|
+
invalidLocations: [],
|
|
226
|
+
duplicateCount: 0,
|
|
227
|
+
error: "invalid_xml",
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
// Strip XML declaration / processing instructions / DOCTYPE to inspect root tag
|
|
231
|
+
const withoutProlog = cleaned
|
|
232
|
+
.replace(/^<\?xml[\s\S]*?\?>\s*/i, "")
|
|
233
|
+
.replace(/^(?:<\?[\s\S]*?\?>\s*|<!DOCTYPE[\s\S]*?>\s*)*/i, "")
|
|
234
|
+
.trim();
|
|
235
|
+
const rootMatch = /^<((?:[\w-]+:)?([a-zA-Z_][\w.-]*))(?:\s[^>]*)?>/.exec(withoutProlog);
|
|
236
|
+
if (!rootMatch) {
|
|
237
|
+
return {
|
|
238
|
+
type: "unsupported",
|
|
239
|
+
entries: [],
|
|
240
|
+
childSitemaps: [],
|
|
241
|
+
invalidLocations: [],
|
|
242
|
+
duplicateCount: 0,
|
|
243
|
+
error: "invalid_xml",
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
const fullRootTag = rootMatch[1];
|
|
247
|
+
const rootLocalName = rootMatch[2].toLowerCase();
|
|
248
|
+
const closingTagRegex = new RegExp(`</${fullRootTag}\\s*>\\s*$`, "i");
|
|
249
|
+
const isSelfClosingRoot = /^<[^>]*\/>\s*$/.test(withoutProlog);
|
|
250
|
+
if (!isSelfClosingRoot && !closingTagRegex.test(withoutProlog)) {
|
|
251
|
+
return {
|
|
252
|
+
type: "unsupported",
|
|
253
|
+
entries: [],
|
|
254
|
+
childSitemaps: [],
|
|
255
|
+
invalidLocations: [],
|
|
256
|
+
duplicateCount: 0,
|
|
257
|
+
error: "invalid_xml",
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
if (rootLocalName === "sitemapindex") {
|
|
261
|
+
const blockRegex = /<(?:[\w-]+:)?sitemap(?:\s[^>]*)?>([\s\S]*?)<\/(?:[\w-]+:)?sitemap>/gi;
|
|
262
|
+
const seen = new Set();
|
|
263
|
+
const childSitemaps = [];
|
|
264
|
+
const invalidLocations = [];
|
|
265
|
+
let duplicateCount = 0;
|
|
266
|
+
let match;
|
|
267
|
+
while ((match = blockRegex.exec(withoutProlog)) !== null) {
|
|
268
|
+
const loc = extractFirstTagText(match[1], "loc");
|
|
269
|
+
if (!loc) {
|
|
270
|
+
invalidLocations.push("");
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const normalized = normalizeSitemapLocation(loc);
|
|
274
|
+
if (!normalized) {
|
|
275
|
+
invalidLocations.push(loc);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (seen.has(normalized)) {
|
|
279
|
+
duplicateCount += 1;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
seen.add(normalized);
|
|
283
|
+
childSitemaps.push(normalized);
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
type: "index",
|
|
287
|
+
entries: [],
|
|
288
|
+
childSitemaps,
|
|
289
|
+
invalidLocations,
|
|
290
|
+
duplicateCount,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (rootLocalName !== "urlset") {
|
|
294
|
+
return {
|
|
295
|
+
type: "unsupported",
|
|
296
|
+
entries: [],
|
|
297
|
+
childSitemaps: [],
|
|
298
|
+
invalidLocations: [],
|
|
299
|
+
duplicateCount: 0,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
const urlBlockRegex = /<(?:[\w-]+:)?url(?:\s[^>]*)?>([\s\S]*?)<\/(?:[\w-]+:)?url>/gi;
|
|
303
|
+
const entries = new Map();
|
|
304
|
+
const invalidLocations = [];
|
|
305
|
+
let duplicateCount = 0;
|
|
306
|
+
let match;
|
|
307
|
+
while ((match = urlBlockRegex.exec(withoutProlog)) !== null) {
|
|
308
|
+
const block = match[1];
|
|
309
|
+
const location = extractFirstTagText(block, "loc");
|
|
310
|
+
if (!location) {
|
|
311
|
+
invalidLocations.push("");
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const normalizedUrl = normalizeSitemapLocation(location);
|
|
315
|
+
if (!normalizedUrl) {
|
|
316
|
+
invalidLocations.push(location);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (entries.has(normalizedUrl)) {
|
|
320
|
+
duplicateCount += 1;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
entries.set(normalizedUrl, {
|
|
324
|
+
url: normalizedUrl,
|
|
325
|
+
lastModified: extractFirstTagText(block, "lastmod"),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
type: "urlset",
|
|
330
|
+
entries: Array.from(entries.values()),
|
|
331
|
+
childSitemaps: [],
|
|
332
|
+
invalidLocations,
|
|
333
|
+
duplicateCount,
|
|
334
|
+
error: entries.size === 0 ? "empty_urlset" : undefined,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
export function parseSitemapXml(xml) {
|
|
338
|
+
if (typeof DOMParser === "undefined") {
|
|
339
|
+
return parseSitemapXmlString(xml);
|
|
340
|
+
}
|
|
341
|
+
const document = new DOMParser().parseFromString(xml, "application/xml");
|
|
342
|
+
if (document.getElementsByTagName("parsererror").length > 0) {
|
|
343
|
+
return {
|
|
344
|
+
type: "unsupported",
|
|
345
|
+
entries: [],
|
|
346
|
+
childSitemaps: [],
|
|
347
|
+
invalidLocations: [],
|
|
348
|
+
duplicateCount: 0,
|
|
349
|
+
error: "invalid_xml",
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
const rootName = document.documentElement?.localName?.toLowerCase();
|
|
353
|
+
if (rootName === "sitemapindex") {
|
|
354
|
+
const seen = new Set();
|
|
355
|
+
const childSitemaps = [];
|
|
356
|
+
const invalidLocations = [];
|
|
357
|
+
let duplicateCount = 0;
|
|
358
|
+
for (const element of getElementsByLocalName(document, "sitemap")) {
|
|
359
|
+
const loc = getChildText(element, "loc");
|
|
360
|
+
if (!loc) {
|
|
361
|
+
invalidLocations.push("");
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const normalized = normalizeSitemapLocation(loc);
|
|
365
|
+
if (!normalized) {
|
|
366
|
+
invalidLocations.push(loc);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (seen.has(normalized)) {
|
|
370
|
+
duplicateCount += 1;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
seen.add(normalized);
|
|
374
|
+
childSitemaps.push(normalized);
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
type: "index",
|
|
378
|
+
entries: [],
|
|
379
|
+
childSitemaps,
|
|
380
|
+
invalidLocations,
|
|
381
|
+
duplicateCount,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
if (rootName !== "urlset") {
|
|
385
|
+
return {
|
|
386
|
+
type: "unsupported",
|
|
387
|
+
entries: [],
|
|
388
|
+
childSitemaps: [],
|
|
389
|
+
invalidLocations: [],
|
|
390
|
+
duplicateCount: 0,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
const entries = new Map();
|
|
394
|
+
const invalidLocations = [];
|
|
395
|
+
let duplicateCount = 0;
|
|
396
|
+
for (const element of getElementsByLocalName(document, "url")) {
|
|
397
|
+
const location = getChildText(element, "loc");
|
|
398
|
+
if (!location) {
|
|
399
|
+
invalidLocations.push("");
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
const normalizedUrl = normalizeSitemapLocation(location);
|
|
403
|
+
if (!normalizedUrl) {
|
|
404
|
+
invalidLocations.push(location);
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
if (entries.has(normalizedUrl)) {
|
|
408
|
+
duplicateCount += 1;
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
entries.set(normalizedUrl, {
|
|
412
|
+
url: normalizedUrl,
|
|
413
|
+
lastModified: getChildText(element, "lastmod"),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
type: "urlset",
|
|
418
|
+
entries: Array.from(entries.values()),
|
|
419
|
+
childSitemaps: [],
|
|
420
|
+
invalidLocations,
|
|
421
|
+
duplicateCount,
|
|
422
|
+
error: entries.size === 0 ? "empty_urlset" : undefined,
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
export function diffSitemapEntries(previousEntries, currentEntries) {
|
|
426
|
+
const previousByUrl = new Map(previousEntries.map((entry) => [entry.url, entry]));
|
|
427
|
+
const currentUrls = new Set();
|
|
428
|
+
const added = [];
|
|
429
|
+
const changed = [];
|
|
430
|
+
const removed = [];
|
|
431
|
+
let unchangedCount = 0;
|
|
432
|
+
for (const entry of currentEntries) {
|
|
433
|
+
currentUrls.add(entry.url);
|
|
434
|
+
const previous = previousByUrl.get(entry.url);
|
|
435
|
+
if (!previous) {
|
|
436
|
+
added.push(entry);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (previous.lastModified !== entry.lastModified) {
|
|
440
|
+
changed.push(entry);
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
unchangedCount += 1;
|
|
444
|
+
}
|
|
445
|
+
for (const entry of previousEntries) {
|
|
446
|
+
if (!currentUrls.has(entry.url)) {
|
|
447
|
+
removed.push(entry);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return { added, changed, removed, unchangedCount };
|
|
451
|
+
}
|
|
452
|
+
export function filterSitemapEntriesByLastMod(entries, maxAgeDays, now = new Date()) {
|
|
453
|
+
if (maxAgeDays === null || maxAgeDays <= 0) {
|
|
454
|
+
return {
|
|
455
|
+
matched: entries,
|
|
456
|
+
withoutLastModCount: 0,
|
|
457
|
+
olderCount: 0,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
const nowMs = now.getTime();
|
|
461
|
+
const cutoffMs = nowMs - maxAgeDays * 24 * 60 * 60 * 1000;
|
|
462
|
+
// Allow up to 24h future clock skew for date-only ISO strings (e.g. 2026-11-25)
|
|
463
|
+
const upperBoundMs = nowMs + 24 * 60 * 60 * 1000;
|
|
464
|
+
const matched = [];
|
|
465
|
+
let withoutLastModCount = 0;
|
|
466
|
+
let olderCount = 0;
|
|
467
|
+
for (const entry of entries) {
|
|
468
|
+
if (!entry.lastModified) {
|
|
469
|
+
withoutLastModCount += 1;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const parsedMs = Date.parse(entry.lastModified);
|
|
473
|
+
if (Number.isNaN(parsedMs)) {
|
|
474
|
+
withoutLastModCount += 1;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
if (parsedMs >= cutoffMs && parsedMs <= upperBoundMs) {
|
|
478
|
+
matched.push(entry);
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
olderCount += 1;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return { matched, withoutLastModCount, olderCount };
|
|
485
|
+
}
|
|
486
|
+
export async function copyText(text) {
|
|
487
|
+
if (!text)
|
|
488
|
+
return false;
|
|
489
|
+
try {
|
|
490
|
+
await navigator.clipboard.writeText(text);
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
const textArea = document.createElement("textarea");
|
|
495
|
+
textArea.value = text;
|
|
496
|
+
textArea.style.position = "fixed";
|
|
497
|
+
textArea.style.opacity = "0";
|
|
498
|
+
document.body.appendChild(textArea);
|
|
499
|
+
textArea.select();
|
|
500
|
+
const didCopy = document.execCommand("copy");
|
|
501
|
+
textArea.remove();
|
|
502
|
+
return didCopy;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
export function downloadTextFile(filename, contents, mimeType = "text/plain;charset=utf-8") {
|
|
506
|
+
const blob = new Blob([contents], { type: mimeType });
|
|
507
|
+
const url = URL.createObjectURL(blob);
|
|
508
|
+
const anchor = document.createElement("a");
|
|
509
|
+
anchor.href = url;
|
|
510
|
+
anchor.download = filename;
|
|
511
|
+
anchor.click();
|
|
512
|
+
URL.revokeObjectURL(url);
|
|
513
|
+
}
|
|
514
|
+
export function generateIndexNowKey() {
|
|
515
|
+
const bytes = crypto.getRandomValues(new Uint8Array(24));
|
|
516
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
517
|
+
}
|