From e9fb46fc5d9c6d364c1491653d1ce02006dc8f2c Mon Sep 17 00:00:00 2001 From: Cesar Uribe Date: Thu, 22 Jul 2021 17:33:51 -0500 Subject: [PATCH] extract js code from 404_doi.html the js code is now implemented as a macro --- scholia/app/static/scholia.js | 24 ++++++++++++++++++++++++ scholia/app/templates/404_doi.html | 29 +++-------------------------- scholia/app/templates/base.html | 7 ++++++- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/scholia/app/static/scholia.js b/scholia/app/static/scholia.js index 26220bd32..a066d2f41 100644 --- a/scholia/app/static/scholia.js +++ b/scholia/app/static/scholia.js @@ -672,4 +672,28 @@ function searchTerm(placeholder) { }); +} + +function quickStatement404DOI(doi, element) { + const c = require('citation-js') + + try { + let example = new c.Cite([doi]) + let output = example.format('quickstatements') + $( element ).append( output ); + output = encodeURI( + output.replaceAll('\t', '|') + .replaceAll('\n', '||')) + .replaceAll('/','%2F') + htmlOutput = "\n" + + " \n" + + "\n" + $( element ).after( htmlOutput ); + } catch (error) { + if (error.message.includes("status code 404")) { + $( element ).append( "DOI does not exist" ) + } else { + console.log(error) + } + } } \ No newline at end of file diff --git a/scholia/app/templates/404_doi.html b/scholia/app/templates/404_doi.html index 9981eadfb..f77bc9e49 100644 --- a/scholia/app/templates/404_doi.html +++ b/scholia/app/templates/404_doi.html @@ -1,31 +1,8 @@ {% extends "base.html" %} -{% block scripts %} -{{super()}} - - - +{% block in_ready %} + +{{ quick_statement( doi ,'qs') }} {% endblock %} diff --git a/scholia/app/templates/base.html b/scholia/app/templates/base.html index 1c837498d..0f05108b0 100644 --- a/scholia/app/templates/base.html +++ b/scholia/app/templates/base.html @@ -25,6 +25,11 @@ "#{{ panel }}-iframe", "{{ aspect }}_{{ panel }}.sparql"); {%- endmacro %} +{% macro quick_statement(doi, element) -%} +quickStatement404DOI( "{{ doi }}" ,"#{{ element }}") +{%- endmacro %} + + {% block head %} {{super()}} @@ -49,7 +54,7 @@ - +