{% set release = entity %}
{% set entity_view = "overview" %}
{% import "entity_macros.html" as entity_macros %}
{% extends "entity_base.html" %}

{% block extra_head %}
  {% if release and release.state == "active" %}
    {# HTML metadata embeddings #}
    <link rel="canonical" href="https://{{ config.FATCAT_DOMAIN }}/release/{{ entity.ident }}">
    <meta name="twitter:card" content="summary">

    <meta name="title" content="{{ release.title }}">
    <meta name="DC.title" content="{{ release.title }}">
    <meta name="citation_title" content="{{ release.title }}">
    <meta name="twitter:title" content="{{ release.title }}">
    <meta name="DC.type" content="{{ release.release_type }}">
    {% if release.abstracts %}
      <meta name="abstract" content="{{ release.abstracts[0].content }}">
      <meta name="DC.description" content="{{ release.abstracts[0].content }}">
      <meta name="twitter:description" content="{{ release.abstracts[0].content }}">
    {% endif %}
    {% for author in release._authors %}
      <meta name="DC.creator" content="{{ author.raw_name }}">
      <meta name="citation_author" content="{{ author.raw_name }}">
    {% endfor %}
    {% if release.release_date or release.release_year %}
      <meta name="DC.issued" content="{{ release.release_date or release.release_year }}">
      <meta name="citation_publication_date" content="{{ release.release_date or release.release_year }}">
    {% endif %}
    {% if release.language %}
      <meta name="DC.language" content="{{ release.language }}">
      <meta name="citation_language" content="{{ release.language }}">
    {% endif %}
    {% if release.container and release.container.issnl %}{# only want actual journals/conferences #}
      <meta name="DC.relation.ispartof" content="{{ release.container.name }}">
      <meta name="citation_journal_title" content="{{ release.container.name }}">
      <meta name="DC.publisher" content="{{ release.container.publisher }}">
      <meta name="citation_publisher" content="{{ release.container.publisher  }}">
      {% if release.container.issnl %}
        <meta name="citation_issn" content="{{ release.container.issnl }}">
      {% endif %}
    {% elif release.publisher %}
      <meta name="DC.publisher" content="{{ release.publisher }}">
      <meta name="citation_publisher" content="{{ release.publisher  }}">
    {% endif %}
    {% if release.volume %}
      <meta name="DC.citation.volume" content="{{ release.volume }}">
      <meta name="citation_volume" content="{{ release.volume }}">
    {% endif %}
    {% if release.issue %}
      <meta name="DC.citation.issue" content="{{ release.issue }}">
      <meta name="citation_issue" content="{{ release.issue }}">
    {% endif %}
    {% if release.pages %}
      <meta name="DC.citation.spage" content="{{ release.pages }}">
      <meta name="citation_first_page" content="{{ release.pages }}">
    {% endif %}
    {% if release.ext_ids.doi %}
      <meta name="DC.identifier" content="doi:{{ release.ext_ids.doi }}">
      <meta name="citation_doi" content="{{ release.ext_ids.doi }}">
    {% endif %}
    {% if release.ext_ids.isbn13 %}
      <meta name="DC.identifier" content="isbn:{{ release.ext_ids.isbn13}}">
      <meta name="citation_isbn" content="{{ release.ext_ids.isbn13}}">
    {% endif %}
    {% for file in (entity.files or [])[:10] %}{% for url in (file.urls or [])[:10] %}
      {% if '//web.archive.org/web/' in url.url %}
        <meta name="DC.identifier" content="{{ url.url }}">
        <meta name="citation_pdf_url" content="{{ url.url }}">
      {% endif %}
    {% endfor %}{% endfor %}
  {% endif %}
{% endblock %}

{% block main_extra_attr %}itemscope itemtype="http://schema.org/ScholarlyArticle" itemid="#release"{% endblock %}

{% block entity_main %}

<div class="ui stackable mobile reversed grid centered">
<div class="column" style="font-size: 16px; flex: 1;">

<div class="title" itemprop="isPartOf" itemscope itemtype="http://schema.org/Periodical" itemid="#container">
  {% if release.release_stage == 'published' %}
    Published
    {% if release.container.ident %}
      in <a href="/container/{{ release.container.ident }}"><span itemprop="name">{{ release.container.name }}</span></a>
    {%- elif release.extra and release.extra.container_name %}
      in <span itemprop="name">{{ release.extra.container_name }}</span>
    {%- endif %}
  {% else %}
    Released
    {% if release.release_type %}
      as a <i>{{ release.release_type }}</i>
    {% endif %}
    {% if release.container %}
      in <a href="/container/{{ release.container.ident }}"><span itemprop="name">{{ release.container.name }}</span></a>
    {% endif %}
  {% endif -%}
  {% if release.publisher %}
    by <span itemprop="publisher">{{ release.publisher }}</span>
  {%- endif %}.

  <p>
  {% set comma = joiner(", ") %}
  {% if release.release_year != None %}
    {{ release.release_year }} &nbsp;
  {% endif %}
  {% if release.volume != None %}
    {{- comma() }}Volume {{ release.volume -}}
  {%- endif %}
  {%- if release.issue != None %}
    {{- comma() }}Issue {{ release.issue -}}
  {%- endif %}
  {%- if release.pages != None %}
    {{- comma() }}
    {% if release.pages[0].isdigit() %}p{% endif -%}
    {{ release.pages }}
  {% endif %}
</div>

{% if release.abstracts != [] %}
  <h3>Abstract</h3>
  <p><span itemprop="description">{{ release.abstracts[0].content }}</span>
  <br><small><i>
    {%- if release.abstracts[0].mimetype != None %}
      In <code>{{ release.abstracts[0].mimetype }}</code> format
    {% else %}
      Unknown format
    {% endif %}
  </i></small>
{% endif %}

{% if entity.state == 'active' %}

{% if entity.files != [] and entity.files != None %}
<h3>Archived Files and Locations</h3>
<table class="ui compact fixed table">
  <tbody>
  {% for file in entity.files %}
  <tr><td>{% if file.mimetype != None %}{{ file.mimetype }}&nbsp;&nbsp;{% endif %}
          {% if file.size != None %}{{ file.size|filesizeformat }}{% endif %}
      <br><small><code><a href="/file/{{ file.ident }}">
            file_{{ file.ident }}
        </a></code></small>
      <td class="single line">
        {% for url in file.urls[:5] %}
          <a href="{{ url.url }}">{{ url.url.split('/')[2] }}</a> ({{ url.rel }})<br>
        {% endfor %}
        {% if file.urls|length > 5 %}
          <a href="/file/{{ file.ident }}">+ {{ file.urls|length - 5 }} more URLs</a>
        {% endif %}
  {% endfor %}
  </tbody>
</table>
{% endif %}

{% if entity.filesets != [] and entity.filesets != None %}
<h3>File Sets</h3>
<table class="ui compact fixed table">
  <tbody>
  {% for fileset in entity.filesets %}
  <tr><td>{{ fileset.manifest|count }} files &nbsp;{{ fileset._total_size|filesizeformat }}
      <br><small><code><a href="/fileset/{{ fileset.ident }}">fileset_{{ fileset.ident }}</a></code></small>
      <td class="single line">
        {% for url in fileset.urls[:5] %}
          {% if url.rel == "dweb" %}
            <a href="{{ url.url }}">{{ url.url }}</a> ({{ url.rel }})<br>
          {% else %}
            <a href="{{ url.url }}">{{ url.url.split('/')[2] }}</a> ({{ url.rel }})<br>
          {% endif %}
        {% endfor %}
        {% if fileset.urls|length > 5 %}
          + {{ file.urls|length - 5 }} more URLs
        {% endif %}
  {% endfor %}
  </tbody>
</table>
{% endif %}

{% if entity.webcaptures != [] and entity.webcaptures != None %}
<h3>Web Captures</h3>
<table class="ui single line compact fixed table">
  <tbody>
  {% for webcapture in entity.webcaptures %}
  <tr><td><b><a href="{{ webcapture.original_url }}" style="color: black;">{{ webcapture.original_url }}</a></b>
      <br>{{ webcapture.timestamp.strftime("%Y-%m-%d %H:%M:%S") }} | {{ webcapture.cdx|count }} resources
      <br><small><code><a href="/webcapture/{{ webcapture.ident }}">webcapture_{{ webcapture.ident }}</a></code></small>
      <td class="single line">
        {% for url in webcapture.archive_urls[:5] %}
          <a href="{{ url.url }}{% if url.rel == "wayback" %}{{ webcapture._wayback_suffix }}{% endif %}">{{ url.url.split('/')[2] }}</a> ({{ url.rel }})<br>
        {% endfor %}
        {% if webcapture.urls|length > 5 %}
          + {{ file.urls|length - 5 }} more URLs
        {% endif %}
  {% endfor %}
  </tbody>
</table>
{% endif %}

{% if not (entity.files or entity.filesets or entity.webcaptures) %}
<h3>Archived Content</h3>
<p>There are no accessible files associated with this release. You could check
<a href="/work/{{ release.work_id }}">other releases for this work</a> for an
accessible version.
{% endif %}

{% endif %}

</div>

<div class="column" style="flex: 0 0 24em;">

{% if entity.state == 'active' and entity._es and entity._es.ia_pdf_url %}
  <a href="{{ entity._es.ia_pdf_url }}" class="ui fluid huge black button" style="text-decoration: underline;">
    <i class="file pdf outline icon"></i>Read Archived PDF
  </a>
{% elif entity.state == 'active' and entity.webcaptures != None and entity.webcaptures != [] and entity.webcaptures[0].archive_urls != [] and entity.webcaptures[0].archive_urls[0].rel == "wayback" %}
  <a href="{{ entity.webcaptures[0].archive_urls[0].url }}{{ entity.webcaptures[0]._wayback_suffix }}" class="ui fluid huge black button" style="text-decoration: underline;">
    <i class="university icon"></i>Visit Web Archive
  </a>
{% endif %}

{% if entity.state == 'active' and entity._es %}
  {% if entity._es.preservation == 'bright' %}
    <div class="ui top attached fluid compact green inverted center aligned segment" style="padding: 0.5em; border-color: #5550; background-color: #2ca048;">
      <b>Preserved and Accessible</b>
    </div>
  {% elif entity._es.preservation == 'dark' %}
    <div class="ui top attached fluid large green inverted center aligned segment" style="padding: 0.5em; border-color: #5550; background-color: #6e7b71;">
      <b>"Dark" Preservation Only</b>
    </div>
  {% else %}
    <div class="ui top attached fluid large red inverted center aligned segment" style="padding: 0.5em; border-color: #5550; background-color: #b71818;">
      <b>Not Preserved</b>
    </div>
  {% endif %}

  {% if entity._es.preservation != 'bright' %}
    <div class="ui segment attached">
      <a href="/release/{{ release.ident }}/save">
        <b><i class="cloud download icon"></i>Save Paper Now!</b>
      </a>
      <p>Know of a fulltext copy of on the public web? Submit a URL and we will archive it
    </div>
  {% endif %}
{% endif %}

{% if release.release_type or release.release_stage or release.release_year %}
  <div class="ui segment attached">
  <b>Type</b> &nbsp;<code>{{ release.release_type or 'unknown' }}</code><br>
  <b>Stage</b> &nbsp; <code>{{ release.release_stage or 'unknown' }}
    {% if release.withdrawn_status %}
      <strong style="color: red;">[{{ release.withdrawn_status }}]</strong>
    {% endif %}
  </code><br>
  {% if release.release_date %}
    <meta itemprop="datePublished" content="{{ release.release_date }}">
    <b>Date</b> &nbsp; {{ release.release_date }}<br>
  {% elif release.release_year %}
    <meta itemprop="datePublished" content="{{ release.release_year }}">
    <b>Year</b> &nbsp; {{ release.release_year }}<br>
  {% endif %}
  {% if release.withdrawn_date %}
    <b>Withdrawn</b> &nbsp; {{ release.withdrawn_date }}<br>
  {% endif %}
  {% if release.version %}
    <b>Version</b> &nbsp; <code>{{ release.version }}</code><br>
  {% endif %}
  {% if release.language != None %}
    <b>Language</b> &nbsp; <code>{{ release.language}}</code>
      <sup><a href="https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1={{ release.language }}">?</a></sup>
  {% endif %}
  </div>
{% endif %}

{% if release.number or release.ext_ids.doi or release.ext_ids.pmid or release.ext_ids.pmcid or release.ext_ids.wikidata_qid or release.ext_ids.isbn13 or release.ext_ids.arxiv or release.ext_ids.jstor or release.ext_ids.ark or release.ext_ids.doaj or release.ext_ids.dblp or release.ext_ids.hdl %}
<div class="ui segment attached" style="word-wrap: break-word;">
{% if release.number %}
  <b>Number</b> &nbsp;<code>{{ release.number }}</code><br>
{% endif %}
{% if release.ext_ids.doi %}
  <b>DOI</b> &nbsp;<code><a href="https://doi.org/{{ release.ext_ids.doi }}" title="{{ release.ext_ids.doi }}" itemprop="sameAs">{{ release.ext_ids.doi }}</a></code><br>
{% endif %}
{% if release.ext_ids.isbn13 != None %}
  <b>ISBN-13</b> &nbsp;<code>{{ release.ext_ids.isbn13 }}</code><br>
{% endif %}
{% if release.ext_ids.pmid != None %}
  <b>PubMed</b> &nbsp;<a href="https://www.ncbi.nlm.nih.gov/pubmed/{{ release.ext_ids.pmid }}"><code>{{ release.ext_ids.pmid }}</code></a><br>
{% endif %}
{% if release.ext_ids.pmcid != None %}
  <b>PMC</b> &nbsp;<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/{{ release.ext_ids.pmcid }}/"><code>{{ release.ext_ids.pmcid }}</code></a><br>
{% endif %}
{% if release.ext_ids.wikidata_qid != None %}
  <b>Wikidata</b> &nbsp;<a href="https://www.wikidata.org/wiki/{{ release.ext_ids.wikidata_qid }}"><code>{{ release.ext_ids.wikidata_qid }}</code></a><br>
{% endif %}
{% if release.ext_ids.arxiv != None %}
  <b>arXiv</b> &nbsp;<a href="https://arxiv.org/abs/{{ release.ext_ids.arxiv }}"><code>{{ release.ext_ids.arxiv }}</code></a><br>
{% endif %}
{% if release.ext_ids.jstor != None %}
  <b>JSTOR</b> &nbsp;<a href="https://jstor.org/stable/{{ release.ext_ids.jstor}}"><code>{{ release.ext_ids.jstor }}</code></a><br>
{% endif %}
{% if release.ext_ids.ark != None %}
  <b>ARK</b> &nbsp;<a href="https://n2t.net/{{ release.ext_ids.ark }}"><code>{{ release.ext_ids.ark }}</code></a><br>
{% endif %}
{% if release.ext_ids.doaj != None %}
  <b>DOAJ</b> &nbsp;<a href="https://doaj.org/article/{{ release.ext_ids.doaj }}" title="{{ release.ext_ids.doaj }}"><code>{{ release.ext_ids.doaj[:20] }}...</code></a><br>
{% endif %}
{% if release.ext_ids.dblp != None %}
  <b>dblp</b> &nbsp;<a href="https://dblp.org/rec/{{ release.ext_ids.dblp }}.html"><code>{{ release.ext_ids.dblp }}</code></a><br>
{% endif %}
{% if release.ext_ids.hdl != None %}
  <b>Handle</b> &nbsp;<a href="https://hdl.handle.net/{{ release.ext_ids.hdl}}"><code>{{ release.ext_ids.hdl }}</code></a><br>
{% endif %}
</div>
{% endif %}

{% if release.extra.is_oa == True %}
<div class="ui segment attached">
<b><i class="ui icon unlock alternate green"></i> Open Access</b>
</div><div class="ui segment attached">
{% elif release.extra.is_oa == False %}
<b><i class="ui icon lock red"></i> Not Open Access</b>
</div>
{% endif %}

{% if release.container != None and release.container._es %}
<div class="ui segment attached">
<b><a href="/container/{{ release.container.ident }}">
{% if release.container.container_type == "journal" %}
  Journal Metadata
{% elif release.container.container_type == "proceedings" %}
  Proceedings Metadata
{% elif release.container.container_type == "book-series" %}
  Book Series Metadata
{% elif release.container.container_type == "blog" %}
  Blog Metadata
{% else %}
  Container Metadata
{% endif %}
</a></b><br>
{% if release.container._es.is_oa == True %}
<i class="icon unlock orange"></i>Open Access Publication<br>
{% endif %}
{% if (release.container._es != None) %}
  {% if release.container._es.in_doaj == True %}
    <i class="icon check green"></i> In <a href="https://doaj.org/toc/{{ release.container.issnl }}">DOAJ</a><br>
  {% elif release.container._es.in_doaj == False %}
    <i class="icon times grey"></i> Not in <a href="https://doaj.org">DOAJ</a><br>
  {% endif %}
  {% if release.container._es.in_road == True %}
    <i class="icon check green"></i> In <a href="http://road.issn.org/issn/{{ release.container.issnl }}">ISSN ROAD</a><br>
  {% elif release.container._es.in_road == False %}
    {# skip 'not in ROAD' display, to reduce UI clutter
    <i class="icon times grey"></i> Not in <a href="https://road.issn.org">ISSN ROAD</a><br>
    #}
  {% endif %}
  {% if release.container._es.any_kbart == True %}
    <i class="icon check green"></i> In <a href="https://keepers.issn.org/?q=api/search&search[]=MUST=allissn={{ release.container.issnl }}&search[]=MUST_EXIST=keepers">Keepers Registry</a><br>
  {% elif release.container._es.any_kbart == False %} <i class="icon times grey"></i> Not in <a href="https://keepers.issn.org/?q=api/search&search[]=MUST=allissn={{ release.container.issnl }}&search[]=MUST_EXIST=keepers">Keepers Registry</a><br>
  {% endif %}
{% endif %}
{% if release.container.issnl != None %}
  <i class="icon linkify"></i>ISSN-L: &nbsp;<code>{{ release.container.issnl }}</code><br>
{% endif %}
</div>
{% endif %}

<div class="ui segment attached">
  <b><a href="/work/{{ release.work_id }}" title="work {{ release.work_id }}">Work Entity</a></b>
  <br>access all versions, variants, and formats of this works (eg, pre-prints)
</div>

{% if release.state == "active" and release._can_citeproc %}
<div class="ui segment attached accordion">
  <div class="title" style="padding: 0px;">
    <i class="dropdown icon"></i><b>Cite This</b>
  </div>
  <div class="content">
    <a href="/release/{{ release.ident }}.bib">BibTeX</a>
    <br><a href="/release/{{ release.ident }}/citeproc?style=csl-json">CSL-JSON</a>
    <br><a href="/release/{{ release.ident }}/citeproc?style=modern-language-association">MLA</a>
    <br><a href="/release/{{ release.ident }}/citeproc?style=elsevier-harvard">Harvard</a>
  </div>
</div>
{% endif %}

<div class="ui segment attached accordion">
  <div class="title" style="padding: 0px;"><i class="dropdown icon"></i><b>Lookup Links</b></div>
  <div class="content">
  {% if release != None and release.ext_ids.doi != None %}
    <a href="https://oadoi.org/{{ release.ext_ids.doi }}">oaDOI/unpaywall</a> (OA fulltext)<br/>
  {% endif %}
  {% if release.ext_ids.doi %}
    {% if release.extra.datacite %}
      <a href="https://api.datacite.org/dois/{{ release.ext_ids.doi }}">Datacite Metadata</a> (via API)<br>
    {% else %}
      <a href="https://api.crossref.org/v1/works/http://dx.doi.org/{{ release.ext_ids.doi }}">Crossref Metadata</a> (via API)<br>
    {% endif %}
  {% endif %}
  {% if release.ext_ids.isbn13 != None %}
    <a href="https://openlibrary.org/search?isbn={{ release.ext_ids.isbn13 }}">Open Library</a><br>
    <a href="http://www.worldcat.org/search?q=bn%3A{{ release.ext_ids.isbn13 }}">Worldcat</a><br>
  {% else %}
    <a href="http://www.worldcat.org/search?qt=worldcat_org_art&q={{ release.title|urlencode }}">Worldcat</a><br>
  {% endif %}
  {% if release.container != None and release.container.issnl != None %}
    <a href="http://www.sherpa.ac.uk/romeo/issn/{{ release.container.issnl }}/">SHERPA/RoMEO</a> (journal policies)<br/>
  {% endif %}
  <a href="https://www.wikidata.org/w/index.php?search={{ release.title|urlencode  }}">wikidata.org</a><br>
  <a href="https://core.ac.uk/search?q={{ release.title|urlencode  }}">CORE.ac.uk</a><br>
  <a href="https://www.semanticscholar.org/search?q={{ release.title|urlencode  }}">Semantic Scholar</a><br>
  <a href="https://scholar.google.com/scholar?q={{ release.title|urlencode  }}">Google Scholar</a><br>
</div>
</div>

{{ entity_macros.fatcat_bits(entity, "release", "container,creators,files,filesets,webcaptures", editgroup) }}

</div>
</div>

{% endblock %}

{% block postscript %}
<script>
  $('.ui.accordion').accordion();
</script>
{% endblock %}