{% extends "all_content/base.html" %}
{% load markup typogrify_tags cache social_tags site_tags %}

{% block title %}{{ object.title }}: {% endblock %}
{% block extra_title %}{{ destination }}{% endblock %}

{% block description %}{{ object.title }}: {{ object.summary }} | {{ site.name }} {{ destination }}{% endblock description %}

{% block extra_meta %}
  <meta property="og:title" content="{% if object.kicker %}{{ object.kicker }}: {% endif %}{{ object.headline }}">
  <meta property="og:url" content="http://{{ site.domain }}{{ object.get_absolute_url }}">
  {% if object.has_image %}<meta property="og:image" content="http://{{ site.domain }}{{ MEDIA_URL }}{{ object.get_image.image }}">{% endif %}
  <meta property="og:description" content="{{ object.summary }}">
  <meta property="og:type" content="article">
  <meta property="article:section" content="{{ object.get_section }}">
  <meta property="article:published_time"  content="{{ object.created|date:"c" }}Z">
  <meta name="DC.date.issued" content="{{ object.created|date:"c" }}Z">
{% endblock %}

{% block bodyid %}article-detail{% endblock %}
{% block bodyclass %}article-detail{% endblock %}

{% block content %}
  <article class="hentry">
    {% cache 86400 'article' object.id object.last_modified 13 %}
      <header>
        {% with object.show_label as cat %}
          {% if cat %}
            <h2 class="kicker">
              <a href="{{ cat.get_absolute_url }}">{{ cat.category }}</a>
            </h2>
          {% endif %}
        {% endwith %}
        {% if object.kicker %}
          <h2 class="overline">{{ object.kicker|typogrify }}</h2>
        {% endif %}
        <h1 class="entry-title">{{ object.title|typogrify }}</h1>
        
        {% if object.subhead %}
          <h2 class="subhead">{{ object.subhead|typogrify }}</h2>
        {% endif %}
        
        <p class="author vcard{% if destination.is_blog %} hide{% endif %}">
          <span class="email fn">
            {% firstof object.author.display_name object.guest_author %}
          </span>
        </p>
        
        {% if object.source %}
          <p class="source-org vcard">
            <span class="org fn">{{ object.source }}</span>
          </p>
        {% endif %}
      </header>

      <section class="content-body">
        {% format_time object.created %}

        {% block top_assets %}
          {% with object.get_top_assets as top_assets %}
            {% if top_assets or object.pullquote %}
              {% include "includes/top_assets.html" %}
            {% endif %}
          {% endwith %}
        {% endblock %}

        {% if object.dateline %}
          <span class="dateline">{{ object.dateline }}</span>
        {% endif %}

        {% block article_body %}
          {% firstof object.autotag_body|markdown|urlize|typogrify object.body|markdown|typogrify %}
        {% endblock %}

        {% block endnote %}
          {% if object.endnote %}
            <p class="shirttail">{{ object.endnote|urlize }}</p>
          {% endif %}
        {% endblock %}

        {% block socialize %}
          <div id="social_bottom">
            {% social_links object user %}
          </div>
        {% endblock %}
      </section><!-- /entry-content -->

      <section id="article-extra-assets">
        <! -- insert polls here -->

        {% for sidebar in object.related_sidebars.all|dictsort:'id' %}
          <aside class="sidebar">
            {% if sidebar.image %}
              <img src="{{ sidebar.image.thumbnail }}">
            {% endif %}
            {% if sidebar.headline %}
              <h3>{{sidebar.headline }}</h3>
            {% endif %}
            {{ sidebar.body|safe|urlize|markdown|typogrify }}
          </aside>
        {% endfor %}

        {% if object.attachment_set.count %}
          <aside id="article-attachments">
            <h3>Attachments</h3>
            <ul>
              {% for attached in object.attachment_set.all %}
                <li>
                    <a href="{{ MEDIA_URL }}/{{ attached.file.name }}">
                      {% firstof attached.filename 'Attachment' %}
                    </a>
                    <span class="meta">
                      {{ attached.file.size|filesizeformat }} 
                      {{ attached.filetype }}
                    </span>
                  </li>
                {% endfor %}
            </ul>
          </aside>
        {% endif %}

        {% for gallery in object.attach_galleries.all %}
          <aside class="related-story">
            <h3 class="has-photos">
              <a href="{{ gallery.get_absolute_url }}">{{ gallery.title }}</a>
            </h3>
            <p><img src="{{ photo.image.extra_thumbnails.t_180 }}"></p>
          </aside>
        {% endfor %}

        {% block related_articles %}
          {% with object.get_related_articles as related %}
            {# first show directly related #}
            {% for a in related.related|slice:"3" %}
              <aside class="related_story">
                {% if a.has_image %}
                  <img src="{{ a.get_image.extra_thumbnails.t_180 }}">
                {% endif %}
                <h3>
                  <a href="{{ a.get_absolute_url }}">{{ a.title }}</a>
                </h3>
                <p>{{ a.summary }}</p>
              </aside>
            {% endfor %}
            
            {# then more general related (from the same section) #}
            {% if related.from_section %}
              <h3>More {{ object.get_section }}</h3>
              <ul>
                {% for a in related.from_section|slice:"5" %}
                  <li>
                    <a href="{{ a.get_absolute_url }}">{{ a.title }}</a>
                  </li>
                {% endfor %}
              </ul>
            {% endif %}
          {% endwith %}
        {% endblock %}
      </section><!-- /article-extra-assets -->
    {% endcache %}

    <footer class="clear">
      {% block comments %}
        {% include 'includes/comments/comments.html' %}
      {% endblock %}
    </footer>
  </article>
{% endblock %}

{% block aside %}
  {% if destination.is_blog %}
    {% include "blogs/includes/blog_extras.html" %}
  {% endif %}

  {{ block.super }}
{% endblock %}
