diff --git a/Dockerfile b/Dockerfile index 0802994..f6ff66e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ FROM nginx RUN rm /etc/nginx/conf.d/default.conf COPY nginx.conf /etc/nginx +COPY conf.d/ocfl.conf /etc/nginx/conf.d RUN mkdir -p /etc/nginx/js COPY js/ocfl.js /etc/nginx/js -COPY conf.d/ocfl.conf /etc/nginx/conf.d \ No newline at end of file +RUN mkdir -p /etc/share/nginx/html/assets +COPY assets/* /etc/share/nginx/html/assets \ No newline at end of file diff --git a/assets/ocfl.css b/assets/ocfl.css new file mode 100644 index 0000000..0f1a7d0 --- /dev/null +++ b/assets/ocfl.css @@ -0,0 +1,51 @@ +/* ocfl bridge */ + +body { + background-color: #eee; + padding: 0.5em; +} + +#header { + font-size: 80%; + font-weight: bold; + background-color: #ccc; + padding: 1em; + height: 3em; +} + +#title { + float:left; + margin: 1em; +} + +#nav { + float: right; + margin: 1em; +} + + +#body { + background-color: #fff; + padding: 2em; +} + +div.item { + padding: 0.25em; +} + +div.item > a { + text-decoration: none; +} + +div.item:nth-child(odd) { + background-color: #ddd; +} + + +#footer { + font-size: 80%; + font-weight: bold; + background-color: #ccc; + padding: 1em; +} + diff --git a/conf.d/ocfl.conf b/conf.d/ocfl.conf index 9c3132e..563a780 100644 --- a/conf.d/ocfl.conf +++ b/conf.d/ocfl.conf @@ -6,10 +6,14 @@ server { listen 8080; server_name 0.0.0.0; - set $ocfl_root /etc/share/nginx/html; + set $ocfl_root /etc/share/nginx/html/ocfl; set $ocfl_autoindex ro-crate-preview.html; set $ocfl_repo_index index.json; + location /assets/ { + root /etc/share/nginx/html; + } + location /repo/ { set $ocfl_repo repo_ocfl; set $ocfl_solr /solr/ocflcore; diff --git a/docker-compose.yml b/docker-compose.yml index eed1368..5be33f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: networks: - main volumes: - - "./test_repos/:/etc/share/nginx/html" + - "./test_repos/:/etc/share/nginx/html/ocfl" solr: image: solr diff --git a/js/ocfl.js b/js/ocfl.js index dfb87c8..f3a92c4 100644 --- a/js/ocfl.js +++ b/js/ocfl.js @@ -15,6 +15,7 @@ var fs = require('fs'); // ie the REPO_NAME can't have '/' in it +var PAGE = 20; // parse the URI and either serve the index or an ocfl_object @@ -33,23 +34,37 @@ function ocfl(req) { return; } - req.error("in ocfl: repo = " + repo); - if( oidv ) { ocfl_object(req, repo, oidv, content) } else { - // get pagination from req.variables.args - var query = "fl=name,path,uri_id&q=record_type_s:Dataset" + var start = parse_pagination(req.variables.args); + var query = "q=record_type_s:Dataset&rows=" + String(PAGE) + "&start=" + start + "&fl=name,path,uri_id&" + req.error("solr query " + query); req.subrequest(ocfl_solr + '/select', { args: query }, ( res ) => { var solrJson = JSON.parse(res.responseBody); var docs = solrJson['response']['docs']; var start = solrJson['response']['start']; - send_html(req, render_index(repo, start, docs)); + var numFound = solrJson['response']['numFound']; + send_html(req, render_index(repo, numFound, start, PAGE, docs)); }); } } + +function parse_pagination(args) { + if( ! args ) { + return '0'; + } + var start_re = new RegExp('^start=(\\d+)'); + var match = args.match(start_re); + if( match ) { + return match[1]; + } + return '0'; +} + + // parse a versioned url_id, look it up in solr to find the path // and then return the versioned ocfl content @@ -111,23 +126,59 @@ function ocfl_object(req, repo, oidv, content) { // with the properties url_id and name (name is an array) -function render_index(repo, start, links) { +function render_index(repo, numFound, start, page, links) { - var html = "
ocfl-nginx bridge v1.0.3
\n"; - html += "Start: " + start + "
"; + var html = '\n' + + '\n' + + '