aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat_scholar/templates/search_macros.html
blob: 5f1950695cef5683d2adecf1bdd8aed1c24be8d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481

{% macro tag_label(tag) -%}
  {% if tag == "oa" %}
    <span class="ui label basic orange small" title="Open Access">OA</span>
  {% elif tag == "jstor" %}
    <span class="ui label basic purple small" title="Preserved in JSTOR">JSTOR</span>
  {% elif tag == "scielo" %}
    <span class="ui label basic purple small" title="Hosted on SciELO platform">SciELO</span>
  {% elif tag == "ojs" %}
    <span class="ui label basic purple small" title="Hosted with Open Journal Systems">OJS</span>
  {% elif tag == "wordpress" %}
    <span class="ui label basic purple small" title="Hosted with Wordpress">Wordpress</span>
  {% elif tag == "road" %}
    {# skip for now; no curration? #}
    {# <span class="ui label basic orange small" title="ISSN Registry of Open Access Journals">ROAD</span> #}
  {% elif tag == "szczepanski" %}
    <span class="ui label basic orange small" title="Szcezepanski OA Journal List">Szczepanski</span>
  {% elif tag == "doaj" %}
    <span class="ui label basic orange small" title="Directory of Open Access Journals">DOAJ</span>
  {% elif tag.startswith("lang:") %}
    <span class="ui label basic black small" title="ISO Language Code">{{ tag }}</span>
  {% else %}
    {# disabling "other" tags for now #}
    {# <span class="ui label basic grey small">{{ _(tag) }}</span> #}
  {% endif %}
{% endmacro %}

{% macro external_identifiers(biblio) -%}
  {# NOTE: should be able to call with paper.biblio or any paper.release[] #}
  {% if biblio.doi %}
    <a target="_blank" rel="external noopener noreferrer" href="https://doi.org/{{ biblio.doi }}" style="color: green;">doi:{{ biblio.doi }}</a> &nbsp;
  {% endif %}
  {% if biblio.pmid %}
    <a target="_blank" rel="external noopener" href="https://www.ncbi.nlm.nih.gov/pubmed/{{ biblio.pmid }}" style="color: green;">pmid:{{ biblio.pmid }}</a> &nbsp;
  {% endif %}
  {% if biblio.pmcid %}
    <a target="_blank" rel="external noopener" href="https://pubmed.ncbi.nlm.nih.gov/{{ biblio.pmcid }}/" style="color: green;">pmcid:{{ biblio.pmcid }}</a> &nbsp;
  {% endif %}
  {% if biblio.arxiv_id %}
    <a target="_blank" rel="external noopener" href="https://arxiv.org/abs/{{ biblio.arxiv_id }}" style="color: green;">arXiv:{{ biblio.arxiv_id }}</a> &nbsp;
  {% endif %}
  {% if biblio.dblp_id %}
    <a target="_blank" rel="external noopener" href="https://dblp.org/rec/{{ biblio.dblp_id }}.html" style="color: green;">dblp:{{ biblio.dblp_id }}</a> &nbsp;
  {% endif %}
  {% if biblio.doaj_id %}
    <a target="_blank" rel="external noopener" href="https://doaj.org/article/{{ biblio.doaj_id }}" style="color: green;">doaj:{{ biblio.doaj_id }}</a> &nbsp;
  {% endif %}
  {% if biblio.release_ident %}
    <a target="_blank" rel="external noopener" href="https://fatcat.wiki/release/{{ biblio.release_ident}}" style="color: green;">fatcat:{{ biblio.release_ident}}</a> &nbsp;
  {% endif %}
{% endmacro %}

{% macro journal_row(biblio, paper) -%}
  {# NOTE: should be able to call with paper.biblio or any paper.release[] #}
  {% if biblio.release_year %}
    <span title="{{ biblio.release_date or '' }}">{{ biblio.release_year }}</span>
  {% endif %}
  {% if biblio.container_name %}
    <i {% if biblio.publisher %}title="{{ biblio.publisher }}"{% endif %}>
    {% if biblio.container_ident %}
      <a target="_blank" rel="noopener" href="https://fatcat.wiki/container/{{ biblio.container_ident }}" style="color: black;">{{ biblio.container_name }}</a>
    {% elif paper.doc_type == "sim_page" %}
      <a target="_blank" rel="noopener" href="https://archive.org/details/{{ paper.ia_sim.pub_collection }}" style="color: black;">{{ biblio.container_name }}</a>
    {% else %}
      {{ biblio.container_name }}
    {% endif %}
    </i>
    &nbsp;
  {% endif %}

  {% if biblio.release_stage == "submitted" %}
    <span class="release-stage" >pre-print</span>
  {% elif biblio.release_stage and biblio.release_stage != "published" %}
    <span class="release-stage">{{ biblio.release_stage }}</span>
  {% elif not biblio.release_stage %}
    <span class="release-stage">unpublished</span>
  {% endif %}

  {% if biblio.withdrawn_status %}
    <span class="release-stage" style="color: red;">{{ biblio.withdrawn_status }}</span>
  {% endif %}
{% endmacro %}

{% macro fulltext_search_result_row(paper, locale=None, debug_mode=False) -%}
<div class="ui grid">
<div class="thirteen wide column biblio-record">
  {# ### TITLE ROW #}
  <h3 class="biblio-title">

    {% if paper.doc_type == "work" %}
      <a style="color: #2224c7; cursor: pointer;" onclick="document.getElementById('access-modal-{{ paper.key }}').showModal()">
        {% if paper.biblio.title %}
          {{ paper.biblio.title[:512] }}
          {% if paper.biblio.title|length > 512 %}...{% endif %}
        {% else %}
          [blank]
        {% endif %}
      </a>
      {# release type suffix #}
      <span class="release-type" >
      {% if paper.biblio.release_type in ("article-journal", "paper-conference") or paper.doc_type == "sim_page" %}
        {# pass #}
      {% elif paper.biblio.release_type in ("book", "chapter", "dataset") %}
        [{{ _(paper.biblio.release_type) }}]
      {% elif not paper.biblio.release_type %}
        [{{ _("unknown") }}]
      {% else %}
        [{{ _(paper.biblio.release_type) }}]
      {% endif %}
      </span>

      {# show inverse of title/original_title above #}
      {% if paper.biblio.original_title and paper.biblio.title != paper.biblio.original_title %}
        <br>
        <span class="original-title">
          {{ paper.biblio.original_title[:512] }} {% if paper.biblio.original_title|length > 512 %}...{% endif %}
        </span>
      {% endif %}

    {% elif paper.doc_type == "sim_page" %}
      <a target="_blank" rel="noopener" href="https://archive.org/details/{{ paper.ia_sim.issue_item }}/page/{{ paper.ia_sim.first_page }}" title="{{ _('access microfilm on archive.org') }}" {% if settings.ENABLE_GOATCOUNTER %}data-goatcounter-click="serp-title-sim-page"{% endif %}>
        {% trans page_num = paper.ia_sim.first_page, journal_name = paper.biblio.container_name, volume = paper.biblio.volume, issue = paper.biblio.issue %}Page {{ page_num }} of {{ journal_name }} Vol. {{ volume }}, Issue {{ issue }}{% endtrans %}
      </a>
      <span class="release-type">[{{ _("page") }}]</span>
    {% endif %}

  </h3>

  {# ### AUTHOR ROW #}
  {% if paper.biblio.contrib_names %}
    <div class="author-row">
    {{ ", ".join(paper.biblio.contrib_names[:12]) }}
    {% if paper.biblio.contrib_names|length > 12 %}<i>(+{{ paper.biblio.contrib_names|length - 12 }} others)</i>{% endif %}
    </div>
  {% endif %}


  {# ### JOURNAL ROW #}
  {{ journal_row(paper.biblio, paper) }}

  {# ### ABSTRACT / QUERY HIGHLIGHT #}
  {% if paper._highlights %}
    <div style="padding-top: 0.5em; padding-bottom: 0.5em;" class="search_highlights">
    {# this highlight HTML escape hacking should not be necessary in ES 7.x with highlight escaping #}
    {# but for now we manually escape, then de-escape the 'em' highlight tags #}
    {% autoescape false %}
      {% for highlight in paper._highlights[:3] %}
        {{ highlight|e|replace("&lt;em&gt;", "<em>")|replace("&lt;/em&gt;", "</em>") }} &nbsp;...&nbsp;
      {% endfor %}
    {% endautoescape %}
    </div>
  {% elif paper.abstracts %}
    <div style="padding-top: 0.5em; padding-bottom: 0.5em;">
      {% if paper.abstracts[0].body|length > 500 %}
        {{ paper.abstracts[0].body | truncate(500, False, '') }}
        <details style="display:inline;">
          <summary>{% trans %}more &raquo;{% endtrans %}</summary>
          ... {{ paper.abstracts[0].body[480:] }}
        </details>
      {% else %}
        {{ paper.abstracts[0].body }}
      {% endif %}
    </div>
  {% else %}
    <br>
  {% endif %}

  {# ### IDENTIFIERS #}
  {{ external_identifiers(paper.biblio) }}

  <div style="margin-top: 0.2em;">
  {# ### TAGS #}
    {# colors to use: olive, brown, grey, pink, red, etc #}
    {# TODO: remove doc for ES 7.x-style lack of type #}
    {# TODO: only show 'json' link if from cluster? #}
    {% if debug_mode %}
      <a target="_blank" rel="noopener" href="{{ settings.ELASTICSEARCH_FRONTEND }}/{{ settings.ELASTICSEARCH_FULLTEXT_INDEX }}/_doc/{{ paper.key }}">
        <span class="ui label small" title="search document JSON debug link">json</span>
      </a>
    {% endif %}

    {% for tag in paper.tags|sort %}
      {# HACK: don't show "oa" tag if already obvious #}
      {% if tag != "oa" or ("doaj" not in paper.tags and "szczepanski" not in paper.tags) %}
        {{ tag_label(tag) }}
      {% endif %}
    {% endfor %}
    {% if paper.biblio.lang_code and paper.biblio.lang_code != (locale or 'en') %}
      {{ tag_label("lang:" + paper.biblio.lang_code) }}
    {% endif %}

  </div>

</div>

<div class="three wide left aligned column" style="padding-top: 0.5em; padding-right: 0.5em; min-width: 10em;">
  {# ### ACCESS LINKS #}

  {# trusted platform fulltext links #}
  {# TODO: DOAJ, dblp #}
  {% if paper.biblio.arxiv_id %}
    <a target="_blank" rel="noopener" href="https://arxiv.org/abs/{{ paper.biblio.arxiv_id }}" title="arxiv.org access">
      <button class="ui fluid compact blue button serp_button">
        <i class="linkify icon"></i>
        arxiv.org
      </button>
    </a>
  {% elif paper.biblio.pmid %}
    <a target="_blank" rel="noopener" href="https://pubmed.ncbi.nlm.nih.gov/{{paper.biblio.pmid }}" title="pubmed link">
      <button class="ui fluid compact blue button serp_button">
        <i class="linkify icon"></i>
        Pubmed
      </button>
    </a>
  {% endif %}

  {# publisher (DOI) link #}
  {# TODO: detect prefix? JSTOR, biorxiv, medrxiv, zenodo, figshare, dryad, etc #}
  {% if paper.biblio.doi %}
    <a target="_blank" rel="external noopener noreferrer" href="https://doi.org/{{paper.biblio.doi }}" style="color: green;">
      <button class="ui fluid left aligned compact blue button serp_button">
        <i class="linkify icon"></i>
        Publisher
      </button>
    </a>
  {% endif %}

  {# archive links (if available) #}
  {% if paper.fulltext and paper.fulltext.access_url %}
    {% if paper.fulltext.file_mimetype == "application/pdf" %}
      {% set access_alt = _('fulltext PDF download') %}
    {% elif paper.fulltext.access_type == "ia_sim" %}
      {% set access_alt = _('read fulltext microfilm') %}
    {% else %}
      {% set access_alt = _('fulltext access') %}
    {% endif %}
    <a target="_blank" rel="noopener" href="{{ paper.fulltext.access_url}}" title="{{ access_alt }}" {% if settings.ENABLE_GOATCOUNTER %}data-goatcounter-click="serp-fulltext-button"{% endif %}>
      <button class="ui simple dropdown fluid compact black labeled icon button serp-button">
        <i class="icon" style="background: no-repeat center / 50% url('/static/ia-logo.svg');"></i>
        {% if paper.fulltext.access_type == "wayback" %}
          PDF (1.42 MB)
        {% elif paper.fulltext.access_type == "ia_sim" %}
          Microfilm
        {% elif paper.fulltext.access_type == "ia_file" %}
          PDF (2.34 MB)
        {% else %}
          other
        {% endif %}
      {% if paper.fulltext.thumbnail_url %}
        <div class="menu" style="left: 185px; margin-top: -2em;">
          <img src="{{ paper.fulltext.thumbnail_url }}" alt="fulltext thumbnail">
        </div>
      {% endif %}
      </button>
    </a>
  {% endif %}

  {# publisher #}
  {% if paper.biblio.doi %}
    <a target="_blank" rel="external noopener noreferrer" href="https://doi.org/{{paper.biblio.doi }}" style="color: green;">
      <button class="ui fluid left aligned compact blue labeled icon button serp-button">
        {% if "oa" in paper.tags %}
          <i class="unlock alternate icon" style="background-color: orange;"></i>
        {% else %}
          <i class="linkify icon"></i>
        {% endif %}
        {# TODO: detect prefix? JSTOR, biorxiv, medrxiv, zenodo, figshare, dryad, etc #}
        {# helpful: https://gist.github.com/TomDemeranville/8699224 #}
        {% if paper.biblio.doi_prefix == "10.6084" %}
          figshare.com
        {% elif paper.biblio.doi_prefix == "10.5281" %}
          zenodo.org
        {% elif paper.biblio.doi_prefix == "10.1371" %}
          plos.org
        {% elif paper.biblio.doi_prefix == "10.1016" %}
          elsevier.com
        {% elif paper.biblio.doi_prefix in ["10.1186", "10.1007"] %}
          springer.com
        {% elif paper.biblio.doi_prefix in ["10.1042", "10.1111", "10.1177"] %}
          sagepub.com
        {% elif paper.biblio.doi_prefix in ["10.1080"] %}
          tandfonline.com
        {% else %}
          Publisher (DOI)
        {% endif %}
      </button>
    </a>
  {% endif %}

  {# trusted platform fulltext links #}
  {# TODO: DOAJ, dblp #}
  {% if paper.biblio.arxiv_id %}
    <a target="_blank" rel="noopener" href="https://arxiv.org/abs/{{ paper.biblio.arxiv_id }}" title="arxiv.org access">
      <button class="ui fluid compact blue labeled icon button serp-button">
        <i class="file alternate outline icon"></i>
        arxiv.org
      </button>
    </a>
  {% elif paper.biblio.pmcid %}
    <a target="_blank" rel="noopener" href="https://www.ncbi.nlm.nih.gov/pmc/articles/{{paper.biblio.pmcid }}" title="pubmed link">
      <button class="ui fluid compact blue labeled icon button serp-button">
        <i class="file alternate outline icon"></i>
        Pubmed Central
      </button>
    </a>
  {% endif %}

  {# ### VERSIONS #}
  {% if (paper.access and paper.access|length > 1) or (paper.releases and paper.releases|length > 1) %}
    <div class="ui simple dropdown fluid left aligned compact basic blue labeled icon button serp-button">
      <i class="ui icon add"></i>
      {% trans %}Versions{% endtrans %}

      <div class="menu" style="font-weight: normal;">
      </div>
    </div>
  {% endif %}

  {# ### COLLAPSED HITS  #}
  {% if paper._collapsed_count > 0 %}
    <button class="ui fluid left aligned basic blue compact button serp-button" form="search_form" type="submit" name="collapse_key" value="{{ paper.collapse_key }}">
      <i class="ui icon zoom-in"></i>
      {% trans trimmed count=paper._collapsed_count %}
        Issue ({{ count }})
      {% endtrans %}
    </button>
  {% endif %}

  {# ### OTHER ACTIONS #}
  <a onclick="document.getElementById('cite-modal-{{ paper.key }}').showModal()">
    <button class="ui compact icon button serp-button" style="box-shadow: 0;">
      <i class="quote left icon"></i>
    </button>
  </a>
  <a href="https://fatcat.wiki/release/{{ paper.biblio.release_ident }}" target="_blank" rel="noopener" title="{{ _('access fatcat landing page') }}">
    <button class="ui compact icon button serp-button" style="box-shadow: 0;">
      <i class="edit icon"></i>
    </button>
  </a>

  {# ### CITATION MODAL #}
  <dialog id="cite-modal-{{ paper.key }}">
    <h2>Cite Paper</h2>
    Something something bibtex will go here.
  </dialog>

  {# ### VERSIONS MODAL #}
  <dialog id="access-modal-{{ paper.key }}">
    <h2>Paper Versions</h2>
    {% if paper.fulltext.thumbnail_url %}
      <img src="{{ paper.fulltext.thumbnail_url }}" alt="fulltext thumbnail">
      <br>
    {% endif %}
    There are several versions of this paper!

    <table class="ui celled table">
      <thead>
        <tr>
          <th>{{ _("Publication Stage") }}</th>
          <th>{{ _("Date") }}</th>
          <th>{{ _("Fulltext") }}</th>
          <th>{{ _("Metadata") }}</th>
        </tr>
      </thead>
      <tbody>
      {% for release in paper.releases %}
        <tr>
          <td>
            <span style="font-weight: normal; text-transform: uppercase; font-weight: bold; color: brown;">
              {{ release.release_stage or _("unknown") }}
            </span>
          </td>
          <td>
            {% if release.release_date %}
              {{ release.release_date }}
            {% elif release.release_year %}
              {{ release.release_year }}
            {% endif %}
          </td>
          <td>
            {% for access in paper.access %}
              {% if access.release_ident == release.ident %}
                <a href="{{ access.access_url }}">
                  <span class="ui blue label">
                    {% if access.mimetype == "application/pdf" %}
                      <i class="file pdf outline icon"></i>
                    {% endif %}
                    {{ access.access_type }}
                  </span>
                </a>
              {% endif %}
            {% endfor %}
          </td>
          <td>
            <a href="https://fatcat.wiki/release/{{ release.ident }}">
              <span class="ui green label">
                <i class="share square icon"></i>
                fatcat
              </span>
            </a>
          </td>
        </tr>
      {% endfor %}
      {% for access in paper.access %}
        {% if not access.release_ident and access.access_type == "ia_sim" %}
          <tr>
            <td>
              <span style="font-weight: normal; text-transform: uppercase; font-weight: bold; color: brown;">
                {{ _("published") }}
              </span>
            </td>
            <td></td>
            <td>
              <a href="{{ access.access_url }}">
                <span class="ui blue label">
                  <i class="film icon"></i>
                  {{ _("microfilm") }}
                </span>
              </a>
            </td>
            <td></td>
          </tr>
        {% endif %}
      {% endfor %}
      </tbody>
    </table>

  </dialog>

</div>
</div>
{% endmacro %}

{% macro search_pagination(hits, top) %}
{% if hits.offset > 0 %}
  <button class="text-button" form="search_form" type="submit" name="offset" value="{{ hits.offset - hits.limit }}" style="margin-right: 2em;" rel="prev">
    <a>&#xab; {% trans %}Previous{% endtrans %}</a>
  </button>
{% else %}
  <span style="color:rgba(0,0,0,0.55); margin-right: 2em;">&#xab; {% trans %}Previous{% endtrans %}</span>
{% endif %}
<i>
  {% trans trimmed start=(hits.offset + 1), end=(hits.offset + hits.limit), total="{:,}".format(hits.count_found) %}
    Showing results {{ start }} &mdash; {{ end }} out of {{ total }} results
  {% endtrans %}
</i>
{% if hits.offset + hits.limit < hits.count_found %}
<button class="text-button" form="search_form" type="submit" name="offset" value="{{ hits.offset + hits.limit }}" style="margin-left: 2em;" rel="next">
  <a>{% trans %}Next{% endtrans %} &#xbb;</a>
{% else %}
  <span style="color:rgba(0,0,0,0.55); margin-left: 2em;">{% trans %}Next{% endtrans %} &#xbb;</span>
{% endif %}
</button>
{% endmacro %}

{% macro query_option(options, selected) -%}
<div>
  <label for="{{ options.slug }}" style="color: rgba(0,0,0,0.55);">{{ _(options.label) }}</label>
  <div class="ui link list" style="margin-top: 0.3em;">
    {% for opt in options.list %}
      <button class="text-button" form="search_form" type="submit" name="{{ options.slug }}" value="{{ opt.slug }}">
        {% if selected == opt.slug or (not selected and opt.slug == options.default) %}
          <span style="font-weight: bold;">
        {% else %}
          <span>
        {% endif %}
        {{ _(opt.label) }}
        </span>
      </button>
      <br>
    {% endfor %}
  </div>
</div>
<br>
{% endmacro %}

{% macro query_hidden(options, selected) -%}
{% if selected %}
  <input form="search_form" type="hidden" name="{{ options.slug }}" value="{{ selected }}">
{% endif %}
{% endmacro %}