summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/fatcat_tools/transforms/csl.py2
-rw-r--r--python/fatcat_web/routes.py35
-rw-r--r--python/fatcat_web/templates/stats.html2
3 files changed, 34 insertions, 5 deletions
diff --git a/python/fatcat_tools/transforms/csl.py b/python/fatcat_tools/transforms/csl.py
index 3509f350..7bc026ed 100644
--- a/python/fatcat_tools/transforms/csl.py
+++ b/python/fatcat_tools/transforms/csl.py
@@ -208,7 +208,7 @@ def citeproc_csl(csl_json, style, html=False):
bib.register(Citation([CitationItem(csl_json['id'])]))
lines = bib.bibliography()[0]
if style == "bibtex":
- out = "\n"
+ out = ""
for l in lines:
if l.startswith(" @"):
out += "@"
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index d660da86..e2c5fc3a 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -2,7 +2,7 @@
import os
import json
from flask import Flask, render_template, send_from_directory, request, \
- url_for, abort, g, redirect, jsonify, session, flash
+ url_for, abort, g, redirect, jsonify, session, flash, Response
from flask_login import login_required
from fatcat_client.rest import ApiException
@@ -507,7 +507,7 @@ def stats_page():
### Pseudo-APIs #############################################################
-@app.route('/unstable/stats.json', methods=['GET', 'OPTIONS'])
+@app.route('/stats.json', methods=['GET', 'OPTIONS'])
@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type'])
def stats_json():
try:
@@ -518,7 +518,6 @@ def stats_json():
abort(503)
return jsonify(stats)
-@app.route('/unstable/container/issnl/<issnl>/stats.json', methods=['GET', 'OPTIONS'])
@app.route('/container/issnl/<issnl>/stats.json', methods=['GET', 'OPTIONS'])
@crossdomain(origin='*',headers=['access-control-allow-origin','Content-Type'])
def container_issnl_stats(issnl):
@@ -529,6 +528,36 @@ def container_issnl_stats(issnl):
abort(503)
return jsonify(stats)
+@app.route('/release/<ident>.bib', methods=['GET'])
+def release_bibtex(ident):
+ try:
+ entity = api.get_release(ident)
+ except ApiException as ae:
+ abort(ae.status)
+ csl = release_to_csl(entity)
+ bibtex = citeproc_csl(csl, 'bibtex')
+ return Response(bibtex, mimetype="text/plain")
+
+@app.route('/release/<ident>/citeproc', methods=['GET'])
+def release_citeproc(ident):
+ style = request.args.get('style', 'harvard1')
+ is_html = request.args.get('html', False)
+ if is_html and is_html.lower() in ('yes', '1', 'true', 'y', 't'):
+ is_html = True
+ else:
+ is_html = False
+
+ try:
+ entity = api.get_release(ident)
+ except ApiException as ae:
+ abort(ae.status)
+ csl = release_to_csl(entity)
+ cite = citeproc_csl(csl, style, is_html)
+ if is_html:
+ return Response(cite)
+ else:
+ return Response(cite, mimetype="text/plain")
+
### Auth ####################################################################
diff --git a/python/fatcat_web/templates/stats.html b/python/fatcat_web/templates/stats.html
index 7f56248f..f11ca820 100644
--- a/python/fatcat_web/templates/stats.html
+++ b/python/fatcat_web/templates/stats.html
@@ -3,7 +3,7 @@
<h1>Stats</h1>
-You can also fetch these numbers <a href="./unstable/stats.json">as JSON</a>.
+You can also fetch these numbers <a href="./stats.json">as JSON</a>.
<h3>Changelog</h3>