---
layout: layouts/base.njk
title: Webmention Debug
permalink: /debug/webmentions/
eleventyExcludeFromCollections: true
pagefindIgnore: true
---
<div class="page-header mb-6 sm:mb-8">
  <h1 class="text-2xl sm:text-3xl font-bold text-surface-900 dark:text-surface-100 mb-2">Webmention Debug</h1>
  <p class="text-surface-600 dark:text-surface-400">
    Debug page for webmention recovery from legacy URLs.
    This page is excluded from collections and won't appear in feeds.
  </p>
</div>

<div class="space-y-8">
  {# Summary #}
  <section class="p-4 bg-surface-100 dark:bg-surface-800 rounded-lg">
    <h2 class="text-xl font-bold mb-4">Summary</h2>
    <dl class="grid grid-cols-2 gap-4 text-sm">
      <div>
        <dt class="font-semibold text-surface-600 dark:text-surface-400">Total URL Mappings</dt>
        <dd class="text-2xl font-bold">{{ urlAliases.aliases | length }}</dd>
      </div>
      <div>
        <dt class="font-semibold text-surface-600 dark:text-surface-400">Total Webmentions</dt>
        <dd class="text-2xl font-bold">{{ webmentions | length }}</dd>
      </div>
    </dl>
  </section>

  {# Recent Posts with Webmentions #}
  <section>
    <h2 class="text-xl font-bold mb-4">Posts with Webmentions</h2>
    <div class="overflow-x-auto">
      <table class="w-full text-sm">
        <thead class="bg-surface-100 dark:bg-surface-800">
          <tr>
            <th class="p-2 text-left">Current URL</th>
            <th class="p-2 text-left">Legacy URLs</th>
            <th class="p-2 text-right">Webmentions</th>
          </tr>
        </thead>
        <tbody class="divide-y divide-surface-200 dark:divide-surface-700">
          {% for post in collections.posts | head(50) %}
            {% set allMentions = webmentions | webmentionsForUrl(post.url, urlAliases, conversationMentions) %}
            {% set legacyUrls = urlAliases.getOldUrls(post.url) %}
            {% if allMentions.length > 0 or legacyUrls.length > 0 %}
            <tr class="hover:bg-surface-50 dark:hover:bg-surface-800/50">
              <td class="p-2">
                <a href="{{ post.url }}" class="text-accent-600 dark:text-accent-400 hover:underline">
                  {{ post.url }}
                </a>
              </td>
              <td class="p-2 text-xs text-surface-600 dark:text-surface-400 font-mono">
                {% if legacyUrls.length %}
                  {% for legacyUrl in legacyUrls %}
                    <div>{{ legacyUrl }}</div>
                  {% endfor %}
                {% else %}
                  <span class="text-surface-600 dark:text-surface-400">-</span>
                {% endif %}
              </td>
              <td class="p-2 text-right">
                {% if allMentions.length %}
                  <span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-100">
                    {{ allMentions.length }}
                  </span>
                {% else %}
                  <span class="text-surface-600 dark:text-surface-400">0</span>
                {% endif %}
              </td>
            </tr>
            {% endif %}
          {% endfor %}
        </tbody>
      </table>
    </div>
  </section>

  {# URL Alias Sample #}
  <section>
    <h2 class="text-xl font-bold mb-4">URL Alias Sample (first 20)</h2>
    <div class="overflow-x-auto">
      <table class="w-full text-sm font-mono">
        <thead class="bg-surface-100 dark:bg-surface-800">
          <tr>
            <th class="p-2 text-left">New URL</th>
            <th class="p-2 text-left">Old URL(s)</th>
          </tr>
        </thead>
        <tbody class="divide-y divide-surface-200 dark:divide-surface-700">
          {% set aliasEntries = urlAliases.aliases | dictsort %}
          {% for newUrl, oldUrls in aliasEntries | head(20) %}
          <tr>
            <td class="p-2 text-xs break-all">{{ newUrl }}</td>
            <td class="p-2 text-xs break-all text-surface-600 dark:text-surface-400">
              {% for oldUrl in oldUrls %}
                <div>{{ oldUrl }}</div>
              {% endfor %}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </section>

  {# Raw Webmention Targets (for debugging) #}
  <section>
    <h2 class="text-xl font-bold mb-4">Recent Webmention Targets</h2>
    <p class="text-sm text-surface-600 dark:text-surface-400 mb-4">
      Shows which URLs webmentions were sent to (useful for verifying legacy URL matches).
    </p>
    <ul class="space-y-1 font-mono text-xs">
      {% for wm in webmentions | head(30) %}
      <li class="p-2 bg-surface-50 dark:bg-surface-800/50 rounded">
        <span class="text-surface-600 dark:text-surface-400">{{ wm["wm-property"] }}:</span>
        <span class="break-all">{{ wm["wm-target"] }}</span>
      </li>
      {% endfor %}
    </ul>
  </section>
</div>
