Skip to content

Commit

Permalink
JSON index is working with the rich-index format with names and descr…
Browse files Browse the repository at this point in the history
…iptions
  • Loading branch information
spikelynch committed Jul 29, 2019
1 parent 4377788 commit 84feaa6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 26 additions & 4 deletions js/ocfl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var fs = require('fs');

var MAX_INDEX_LENGTH = 80;

// ocfl(request)
//
// entry-point from nginx
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -78,8 +87,10 @@ function repository_index(req, url_path) {

var html = "<html><body>";

Object.keys(index).sort().forEach((k) => {
html += '<p><a href="/' + url_path + '/' + k + '/">' + k + '</a></p>'
index.forEach((e) => {
var entry = index_map(e);
var url = '/' + url_path + '/' + entry[0] + '/';
html += '<p><a href="' + url + '/">' + entry[1] + '</a></p>'
});

html += '</body>';
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 84feaa6

Please sign in to comment.