{% set entity = release %}
{% import "entity_macros.html" as entity_macros %}
{% extends "base.html" %}

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

    <meta name="description" content="Editable catalog of bibliographic and fulltext file metadata">
    <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 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="isbn:{{ 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.doi %}
      <meta name="DC.identifier" content="doi:{{ release.doi }}">
      <meta name="citation_doi" content="{{ release.doi }}">
    {% endif %}
    {% if release.isbn13 %}
      <meta name="DC.identifier" content="isbn:{{ release.isbn13}}">
      <meta name="citation_isbn" content="{{ release.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 %}
  {% endblock %}
{% endif %}

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

{% block fullbody %}

<div class="ui stackable mobile reversed grid centered">
<div class="one wide column"></div>
<div class="fifteen wide column">
  <h1 class="ui header"><span itemprop="headline"><span itemprop="name">{{ release.title }}</span></span>
  <span class="sub header"><code>release {{ release.ident }}</code></span></h1>
  <p style="font-size: larger;">
  {% if authors != [] %} by {% endif %}
  {% for contrib in authors[:12] %}
    {% if contrib.creator_id %}
      <b><a href="/creator/{{contrib.creator_id}}">{{ contrib.raw_name }}</a></b>{% if not loop.last %}, {% endif %}
    {% else %}
      {% if contrib.raw_name != None %}{{ contrib.raw_name }}{% else %}<i>Unknown</i>{% endif %}{% if not loop.last %}, {% endif %}
    {% endif %}
  {% endfor %}
  {% if authors|count > 12 %} <b>(+{{ authors|length - 12 }} others)</b>
  {% endif %}
</div>
</div>

<div class="ui stackable mobile reversed grid centered">
<div class="one wide column"></div>
<div class="ten wide column" style="font-size: 16px;">

<div class="ui accordion">
<div class="title" itemprop="isPartOf" itemscope itemtype="http://schema.org/Periodical" itemid="#container">
  {% if release.release_status == 'published' %}
    <i class="dropdown icon"></i>Published in <a href="/container/{{ container.ident }}"><span itemprop="name">{{ container.name }}</span></a>
  {% else %}
    <i class="dropdown icon"></i>Released as a <i>{{ release.release_type }}</i>
    {% if container %} in <a href="/container/{{ container.ident }}"><span itemprop="name">{{ container.name }}</span></a> {% endif %}
  {% endif %}
  {% if release.publisher %}
    by <span itemprop="publisher">{{ release.publisher }}</span>
  {% endif %}
</div><div class="content" itemscope itemtype="http://schema.org/Periodical" itemid="#container">
  <table class="ui definition single line fixed compact small collapsing unstackable table">
  <tbody>
    {% if container != None and container.issnl != None %}
      <tr><td class="right aligned">ISSN-L</td>
          <td class="" itemprop="issn">{{ container.issnl }}
    {% endif %}
    {% if release.volume != None %}
      <tr itemprop="isPartOf" itemscope itemtype="http://schema.org/PublicationVolume">
          <td class="right aligned">Volume</td>
          <td class="" itemprop="volumeNumber">{{ release.volume }}
    {% endif %}
    {% if release.issue != None %}
      <tr itemprop="isPartOf" itemscope itemtype="http://schema.org/PublicationIssue">
          <td class="right aligned">Issue</td>
          <td class="" itemprop="issueNumber">{{ release.issue }}
    {% endif %}
    {% if release.pages != None %}
      <tr itemprop="isPartOf" itemscope itemtype="http://schema.org/PublicationIssue">
          <td class="right aligned">Page(s)</td>
          <td class="" itemprop="pagination">{{ release.pages }}
    {% endif %}
    {% if release.release_date != None %}
      <tr><td class="right aligned">Release Date</td>
          <td class="">{{ release.release_date }}
    {% elif release.release_year != None %}
      <tr><td class="right aligned">Release Year</td>
          <td class="">{{ release.release_year }}
    {% endif %}
    {% if container != None and container.container_type != None %}
      <tr><td class="right aligned">Container Type</td>
          <td class="">{{ container.container_type }}
    {% endif %}
    {% if release.publisher != None %}
      <tr><td class="right aligned">Publisher</td>
          <td class="">{{ release.publisher }}
    {% endif %}
    {% if release.language != None %}
      <tr><td class="right aligned">Primary Language</td>
          <td class=""><code>{{ release.language }}</code>
          (<a href="https://www.loc.gov/standards/iso639-2/php/langcodes_name.php?iso_639_1={{ release.language }}">lookup</a>)
    {% endif %}

  </tbody>
  </table>
</div>
</div>

{% if release.contribs|length > 0 %}
<div class="ui accordion">
<div class="title">
  <i class="dropdown icon"></i>All Contributors ({{ release.contribs|length }})
</div><div class="content">
<table class="ui basic compact table">
<tbody>
{% for contrib in release.contribs %}
  <tr><td class="collapsing">{% if contrib.index or contrib.index == 0 %} {{ contrib.index + 1 }}{% endif %}
      <td><span itemprop="author">
      {% if contrib.creator_id %}
        <a href="/creator/{{contrib.creator_id}}">{{ contrib.raw_name or 'unknown' }}</a> 
      {% else %}
        {{ contrib.raw_name or '' }}
      {% endif %}
      </span><br><i>{{ contrib.role or 'unknown' }}</i>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% else %}
<p>No known contributors (authors, translators, etc).
{% endif %}

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


{% if entity.extra %}
  <h3>Extra Metadata (raw JSON)</h3>
  {{ entity_macros.extra_metadata(entity.extra) }}
{% endif %}


<h3>Known Files and URLs</h3>
{% if entity.files != [] %}
<table class="ui compact fixed table">
<!--
  <thead>
    <tr><th>SHA-1
        <th>Size (bytes)
        <th>File Type
        <th>Links
  </thead>
-->
  <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 }}">
            {% if file.sha1 != None %}sha1:{{ file.sha1[:20] + "..." }}
            {% elif file.sha256!= None %}sha256:{{ file.md5[:20] + "..." }}
            {% elif file.md5 != None %}md5:{{ file.md5[:20] + "..." }}
            {% endif %}
        </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>
{% else %}
<p>There are no known files associated with this release (you could try
<a href="/work/{{ release.work_id }}">other releases for this work?</a>).
{% endif %}


{% if entity.filesets != [] %}
<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 != [] %}
<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 }}">{{ 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 release.refs != None and release.refs.size != 0 %}
<h3>References</h3>
<i>This release citing other releases</i>
{# see https://github.com/Semantic-Org/Semantic-UI/issues/2639 #}
<ol>
  {% for ref in release.refs %}
    <li>
    {% if ref.title %}
      {{ ref.title }}
      {% if ref.container_name %}{{ ref.container_name }}.{% endif %}
      {% if ref.year %}{{ ref.year }}{% endif %}
      {% if ref.locator %}{{ ref.locator }}{% endif %}
    {% elif ref.extra != None %}
      {% if ref.extra.get('author') %}{{ ref.extra['author'] }}.{% endif %}
      {% if ref.extra.get('article-title') %}{{ ref.extra['article-title'] }}.{% endif %}
      {% if ref.container_name %}{{ ref.container_name }}.{% endif %}
      {% if ref.year %}{{ ref.year }}.{% endif %}
      {% if ref.extra.unstructured %}{{ ref.extra.unstructured }}{% endif %}
    {% else %}
      <i>unknown</i>
    {% endif %}
    {% if ref.target_release_id != None %}
      (<a href="/release/{{ ref.target_release_id }}">fatcat entry</a>)
    {% endif %}
    {% if ref.extra != None and ref.extra.doi %}
      (DOI: <a href="/release/lookup?doi={{ ref.extra.doi }}">{{ ref.extra.doi }}</a>)
    {% endif %}
    </li>
  {% endfor %}
</ol>
{% else %}
<p>No reference list available.
{% endif %}

</div>
<div class="five wide column">

{% if entity.files != [] and entity.files[0].urls != [] %}
<a href="{{ entity.files[0].urls[0].url }}" class="ui top attached fluid huge green button"><i class="file pdf outline icon"></i>Download Full Text</a>
{% elif 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 top attached fluid huge green button"><i class="file archive outline icon"></i>View Web Archive</a>
{% else %}
<span class="ui top attached fluid huge grey button"><i class="file cross icon"></i>No Full Text Available</span>
{% endif %}

{% if release.release_type or release.release_status or release.release_year %}
  <div class="ui segment attached">
  {% if release.release_type %}
    <b>Type</b> &nbsp;<code>{{ release.release_type }}</code><br>
  {% endif %}
  {% if release.release_status %}
    <b>Status</b> &nbsp; <code>{{ release.release_status or 'unknown' }}</code><br>
  {% endif %}
  {% 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 %}
  </div>
{% endif %}

{% if release.doi or release.pmid or release.pmcid or release.wikidata_qid %}
<div class="ui segment attached" style="word-wrap: break-word;">
{% if release.doi %}
  <b>DOI </b> &nbsp;<a href="https://doi.org/{{ release.doi }}" title="{{ release.doi }}" itemprop="sameAs">{{ release.doi }}</a><br>
{% endif %}
{% if release.pmid != None %}
  <b>PubMed</b> <a href="https://www.ncbi.nlm.nih.gov/pubmed/{{ release.pmid }}">&nbsp;<code>{{ release.pmid }}</code></a><br>
{% endif %}
{% if release.pmcid != None %}
  <b>PMC</b> <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/{{ release.pmcid }}">&nbsp;<code>{{ release.pmcid }}</code></a><br>
{% endif %}
{% if release.wikidata_qid != None %}
  <b>Wikidata</b> <a href="https://www.wikidata.org/wiki/{{ release.wikidata_qid }}">&nbsp;<code>{{ release.wikidata_qid }}</code></a><br>
{% endif %}
{% if release.isbn13 != None %}
  <b>ISBN-13 </b> &nbsp;<code>{{ release.isbn13 }}</code>
{% 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 container != None and container.es %}
<div class="ui segment attached">
<b>Container Metadata</b><br>
{% if container.es.is_oa == True %}
<i class="icon unlock orange"></i>Open Access Publication<br>
{% elif container.es.is_oa == False  %}
<i class="icon lock black"></i>Not Open Access<br>
{% else %}
<i class="icon question grey"></i>Unknown OA Status<br>
{% endif %}
{% if (container.es != None) %}
  {% if container.es.in_doaj == True %}
    <i class="icon check green"></i> In <a href="https://doaj.org/toc/{{ container.issnl }}">DOAJ</a><br>
  {% elif container.es.in_doaj == False %}
    <i class="icon times grey"></i> Not in <a href="https://doaj.org">DOAJ</a><br>
  {% endif %}
  {% if container.es.in_road == True %}
    <i class="icon check green"></i> In <a href="http://road.issn.org/issn/{{ container.issnl }}">ISSN ROAD</a><br>
  {% elif container.es.in_road == False %}
    <i class="icon times grey"></i> Not in <a href="https://road.issn.org">ISSN ROAD</a><br>
  {% endif %}
  {% if container.es.in_kbart == True %}
    <i class="icon check green"></i> In <a href="https://thekeepers.org/purl/issn/{{ container.issnl }}">Keepers Registery</a><br>
  {% elif container.es.in_kbart == False %} <i class="icon times grey"></i> Not in <a href="https://thekeepers.org/journals?query={{ container.issnl }}">Keepers Registry</a><br>
  {% endif %}
{% endif %}
{% if container.issnl != None %}
  <i class="icon linkify"></i>ISSN-L: &nbsp;<code>{{ container.issnl }}</code><br>
{% endif %}
  <a href="/container/{{ container.ident }}" title="container {{ container.ident }}"><i class="icon share"></i>Fatcat Entry</a>
</div>
{% endif %}

<div class="ui segment attached accordion">
  <b><a href="/work/{{ release.work_id }}" title="work {{ release.work_id }}">Work Entity</a></b>
  <br>grouping other versions (eg, pre-print) and variants of this release
</div>

{# this restriction, for CSL-JSON generation, rules out almost everything #}
{% if release.contribs and release.contribs[0].creator_id %}
<div class="ui segment attached accordion">
  <div class="title" style="padding: 0px;">
    <i class="dropdown icon"></i><b>Cite This Release</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 container != None and container.issnl != None %}
    <a href="http://www.sherpa.ac.uk/romeo/issn/{{ container.issnl }}/">SHERPA/RoMEO</a> (journal policies)<br/>
  {% endif %}
  {% if container != None and container.doi != None %}
    <a href="https://oadoi.org/{{ release.doi }}">oaDOI/unpaywall</a><br/>
  {% endif %}
  {% if release.isbn13 != None %}
    <a href="https://openlibrary.org/search?isbn={{ release.isbn13 }}">Open Library</a><br>
    <a href="http://www.worldcat.org/search?q=bn%3A{{ release.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.doi %}
  <a href="https://api.crossref.org/v1/works/http://dx.doi.org/{{ release.doi }}">Crossref Metadata</a> (via API)<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> (CS, neuro)<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,files,filesets,webcaptures") }}

</div>
</div>
{% endblock %}

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