/** * Patch @rmdes/indiekit-endpoint-webmention-sender template to: * * Show a "No external links found" message when a post was processed * but all sent/failed/skipped arrays are empty (i.e. no external links * were discovered in the post content at processing time). * * Without this patch the expanded detail row is completely blank, which * is confusing because the user can't tell whether something went wrong * or the post simply had no outbound links. */ import { access, readFile, writeFile } from "node:fs/promises"; const filePath = "node_modules/@rmdes/indiekit-endpoint-webmention-sender/views/webmention-sender.njk"; const patchMarker = "[patched:empty-details]"; const originalBlock = ` {% if result.details.skipped and result.details.skipped.length > 0 %}
| {{ __("webmention-sender.results.target") }} | {{ __("webmention-sender.results.reason") }} |
|---|---|
| {{ item.target | truncate(50) }} | {{ item.reason }} |
{{ __("webmention-sender.results.noDetails") }}
{% endif %}`; const newBlock = ` {% if result.details.skipped and result.details.skipped.length > 0 %}| {{ __("webmention-sender.results.target") }} | {{ __("webmention-sender.results.reason") }} |
|---|---|
| {{ item.target | truncate(50) }} | {{ item.reason }} |
No external links discovered in this post.
{% endif %} {% else %}{{ __("webmention-sender.results.noDetails") }}
{% endif %}`; async function exists(p) { try { await access(p); return true; } catch { return false; } } if (!(await exists(filePath))) { console.log("[patch-webmention-sender-empty-details] File not found, skipping"); process.exit(0); } const source = await readFile(filePath, "utf8"); if (source.includes(patchMarker)) { console.log("[patch-webmention-sender-empty-details] Already patched"); process.exit(0); } if (!source.includes(originalBlock)) { console.warn( "[patch-webmention-sender-empty-details] Target block not found — upstream format may have changed, skipping" ); process.exit(0); } const patched = source.replace(originalBlock, newBlock); if (!patched.includes(patchMarker)) { console.warn("[patch-webmention-sender-empty-details] Patch validation failed, skipping"); process.exit(0); } await writeFile(filePath, patched, "utf8"); console.log("[patch-webmention-sender-empty-details] Patched successfully");