aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat_scholar
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-04-27 20:53:24 -0700
committerBryan Newbold <bnewbold@archive.org>2021-04-27 20:53:26 -0700
commit9907d45e4f54fe70e8e062f47f75197a3ae1b58e (patch)
treed5654721d401a9b96e7ce803b0039e0d140b1cb4 /fatcat_scholar
parente35e99bceff3277afaac8f2d5519aa4f07aabe49 (diff)
downloadfatcat-scholar-9907d45e4f54fe70e8e062f47f75197a3ae1b58e.tar.gz
fatcat-scholar-9907d45e4f54fe70e8e062f47f75197a3ae1b58e.zip
iterate on access redirects and landing page implementation
Small code refactors and minimal test coverage
Diffstat (limited to 'fatcat_scholar')
-rw-r--r--fatcat_scholar/search.py11
-rw-r--r--fatcat_scholar/templates/work.html38
-rw-r--r--fatcat_scholar/web.py1
3 files changed, 27 insertions, 23 deletions
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py
index c5fca35..a0cad2c 100644
--- a/fatcat_scholar/search.py
+++ b/fatcat_scholar/search.py
@@ -469,14 +469,17 @@ def lookup_fulltext_pdf(sha1: str) -> Optional[dict]:
sha1 = sha1.lower()
assert len(sha1) == 40 and sha1.isalnum()
hits = do_lookup_query(
- f'fulltext.file_sha1:{sha1} fulltext.file_mimetype:"application/pdf"'
+ f'fulltext.file_sha1:{sha1} fulltext.file_mimetype:"application/pdf" fulltext.access_url:*'
)
if not hits.results:
return None
fulltext = ScholarFulltext.parse_obj(hits.results[0]["fulltext"])
if not fulltext.access_type in ("ia_file", "wayback"):
return None
- assert fulltext.file_sha1 == sha1
- assert fulltext.file_mimetype == "application/pdf"
- assert fulltext.access_url
+ if fulltext.file_sha1 != sha1:
+ return None
+ if fulltext.file_mimetype != "application/pdf":
+ return None
+ if not fulltext.access_url:
+ return None
return fulltext
diff --git a/fatcat_scholar/templates/work.html b/fatcat_scholar/templates/work.html
index 92e334e..067d23c 100644
--- a/fatcat_scholar/templates/work.html
+++ b/fatcat_scholar/templates/work.html
@@ -2,39 +2,39 @@
{% extends "base.html" %}
{% block title %}
-{{ doc.title }}
+{{ work.title }}
{% endblock %}
{% block extra_head %}
- <link rel="canonical" href="/work/{{ doc.work_ident }}">
+ <link rel="canonical" href="/work/{{ work.work_ident }}">
- <meta name="citation_title" content="{{ doc.biblio.title }}">
-{% for contrib in doc.biblio.contrib_names %}
+ <meta name="citation_title" content="{{ work.biblio.title }}">
+{% for contrib in work.biblio.contrib_names %}
<meta name="citation_author" content="{{ contrib }}">
{% endfor %}
-{% if doc.biblio.release_date or doc.biblio.release_year %}
- <meta name="citation_publication_date" content="{{ doc.biblio.release_date or doc.biblio.release_year }}">
+{% if work.biblio.release_date or work.biblio.release_year %}
+ <meta name="citation_publication_date" content="{{ work.biblio.release_date or work.biblio.release_year }}">
{% endif %}
-{% if doc.biblio.container_name %}
- <meta name="citation_journal_title" content="{{ doc.biblio.container_name }}">
+{% if work.biblio.container_name %}
+ <meta name="citation_journal_title" content="{{ work.biblio.container_name }}">
{% endif %}
-{% if doc.biblio.volume %}
- <meta name="citation_volume" content="{{ doc.biblio.volume }}">
+{% if work.biblio.volume %}
+ <meta name="citation_volume" content="{{ work.biblio.volume }}">
{% endif %}
-{% if doc.biblio.issue %}
- <meta name="citation_issue" content="{{ doc.biblio.issue }}">
+{% if work.biblio.issue %}
+ <meta name="citation_issue" content="{{ work.biblio.issue }}">
{% endif %}
-{% if doc.biblio.pages %}
- <meta name="citation_first_page" content="{{ doc.biblio.pages }}">
+{% if work.biblio.pages %}
+ <meta name="citation_first_page" content="{{ work.biblio.pages }}">
{% endif %}
-{% if doc.biblio.doi %}
- <meta name="citation_doi" content="{{ doc.biblio.doi }}">
+{% if work.biblio.doi %}
+ <meta name="citation_doi" content="{{ work.biblio.doi }}">
{% endif %}
-{% if doc.fulltext.access_url and doc.biblio.release_ident == doc.fulltext.release_ident and doc.fulltext.access_type in ['wayback', 'ia_file'] and doc.fulltext.file_mimetype == "application/pdf" and doc.fulltext.file_sha1 %}
+{% if work.fulltext.access_url and work.biblio.release_ident == work.fulltext.release_ident and work.fulltext.access_type in ['wayback', 'ia_file'] and work.fulltext.file_mimetype == "application/pdf" and work.fulltext.file_sha1 %}
<!-- PDF access redirect URL, as requested by, eg, scholar.google.com -->
-<meta name="citation_pdf_url" content="/access-redirect/{{ doc.fulltext.file_sha1 }}.pdf">
-<!-- <meta name="citation_pdf_url" content="{{ doc.fulltext.access_url }}"> -->
+<meta name="citation_pdf_url" content="/access-redirect/{{ work.fulltext.file_sha1 }}.pdf">
+<!-- <meta name="citation_pdf_url" content="{{ work.fulltext.access_url }}"> -->
{% endif %}
{% endblock %}
diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py
index 56f2561..adddcbd 100644
--- a/fatcat_scholar/web.py
+++ b/fatcat_scholar/web.py
@@ -380,6 +380,7 @@ def web_work(
"locale": lang.code,
"lang_prefix": lang.prefix,
"doc": doc,
+ "work": doc["_obj"],
},
)