<html>
<head>
<script>
function ts_to_date(ts, is_gmt)
{
    if (ts.length < 14) {
        return ts;
    }

    var datestr = (ts.substring(0, 4) + "-" +
                  ts.substring(4, 6) + "-" +
                  ts.substring(6, 8) + "T" +
                  ts.substring(8, 10) + ":" +
                  ts.substring(10, 12) + ":" +
                  ts.substring(12, 14) + "-00:00");

    var date = new Date(datestr);
    if (is_gmt) {
        return date.toGMTString();
    } else {
        return date.toLocaleString();
    }
}
</script>
</head>
<body>
  <h2>pywb Query Results</h2>
  {% if cdx_lines | length > 0 %}
  <b>{{ cdx_lines | length }}</b> captures of <b>{{ url }}</b>
  <table id="captures" style="border-spacing: 10px;">
    <tr>
      <th>Capture</th>
      <th>Status</th>
      <th>Original Url</th>
      <th>Archive File</th>
    </tr>
    {% for cdx in cdx_lines  %}
    <tr style="{{ 'font-weight: bold' if cdx.mime != 'warc/revisit' else '' }}">
      <td><a href="{{ prefix }}{{ cdx.timestamp }}/{{ cdx.url }}">
      <script>document.write(ts_to_date("{{ cdx['timestamp']}}", true))</script>
      </a></td>
      <td>{{ cdx.status }}</td>
      <td>{{ cdx.url }}</td>
      <td>{{ cdx.filename }}</td>
    </tr>
    {% endfor %}
  </table>
  <p>
  <i><b>* Unique captures are bold.</b> Other captures are duplicates of a previous capture.</i>
  </p>
  {% else %}
  <i>No captures found for <b>{{ url }}</b></i>
  {% endif %}
</body>
</html>
