From 84feaa69fde8307db205d1f8cefd1bab439bbabf Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Mon, 29 Jul 2019 10:52:17 +1000 Subject: [PATCH] JSON index is working with the rich-index format with names and descriptions --- js/ocfl.js | 30 ++++++++++++++++++++++++++---- nginx.conf | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/js/ocfl.js b/js/ocfl.js index 0e385cb..55ef418 100644 --- a/js/ocfl.js +++ b/js/ocfl.js @@ -2,6 +2,8 @@ var fs = require('fs'); +var MAX_INDEX_LENGTH = 80; + // ocfl(request) // // entry-point from nginx @@ -39,14 +41,21 @@ function ocfl(req) { req.return(440, "Resource not found"); return } - var oid = match[0]; - var v = match[1]; + var oid = match[1]; + var v = match[2]; var object = pairtree(oid); var opath = [ ocfl_repo ].concat(object).join('/'); if( v ) { v = v.substr(1); } + + if( !content ) { + content = index_file; + } + + req.error("oid: " + oid + "; v: " + v + "; object: " + opath); + var vpath = version(req, ocfl_root + '/' + opath, content, v); if( vpath ) { var newroute = '/' + opath + '/' + vpath; @@ -78,8 +87,10 @@ function repository_index(req, url_path) { var html = ""; - Object.keys(index).sort().forEach((k) => { - html += '

' + k + '

' + index.forEach((e) => { + var entry = index_map(e); + var url = '/' + url_path + '/' + entry[0] + '/'; + html += '

' + entry[1] + '

' }); html += ''; @@ -92,6 +103,17 @@ function repository_index(req, url_path) { } +// indexmap takes an index entry and returns an id and a chunk of HTML +// to be rendered as the index + +function index_map(entry) { + var html = entry['name'] + ': ' + entry['description']; + if( html.length > MAX_INDEX_LENGTH ) { + html = html.slice(0, MAX_INDEX_LENGTH) + '...'; + } + return [ entry['@id'], html ]; +} + function send_html(req, html) { req.status = 200; req.headersOut['Content-Type'] = "text/html; charset=utf-8"; diff --git a/nginx.conf b/nginx.conf index 8b73341..48fdf8c 100644 --- a/nginx.conf +++ b/nginx.conf @@ -2,7 +2,7 @@ user nginx; worker_processes 1; -error_log /var/log/nginx/error.log warn; +error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; load_module modules/ngx_http_js_module.so;