Skip to content

Commit

Permalink
Merge PR #49
Browse files Browse the repository at this point in the history
  • Loading branch information
pietercolpaert committed Oct 3, 2022
2 parents 89b4723 + d14d336 commit 38b9dff
Show file tree
Hide file tree
Showing 3 changed files with 430 additions and 2,202 deletions.
15 changes: 12 additions & 3 deletions bin/ldfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var ldfetch = require('../lib/ldfetch.js');
var fetch = new ldfetch();
var n3 = require('n3');
var program = require('commander');
var path = require('path');
var fs = require('fs');

var url = "";
console.error('LDFetch. Use --help to discover more instructions');
Expand All @@ -13,7 +15,7 @@ var list = function (val) {

program
.option('-p, --predicates <predicates ...>', 'Some predicates can be followed [predicates]', list)
.option('--frame <jsonldframe>', 'Add a JSON-LD frame')
.option('--frame <jsonldframe|file>', 'Add a JSON-LD frame')
.arguments('<url>')
.action(function (argUrl) {
//TODO: check whether starts with http(s)?
Expand Down Expand Up @@ -48,8 +50,15 @@ var processPage = async function (pageUrl) {
history.push(pageUrl);
history.push(response.url);
if (response.triples) {
if (options.frame) {
let frame = JSON.parse(options.frame);
if (program.frame) {
let frame;

if (fs.existsSync(program.frame)) {
frame = JSON.parse(fs.readFileSync(program.frame));
}
else {
frame = JSON.parse(program.frame);
}
let object = await fetch.frame(response.triples, frame);
console.log(JSON.stringify(object));
} else {
Expand Down
Loading

0 comments on commit 38b9dff

Please sign in to comment.