diff --git a/packages/ace-core/src/core/ace.js b/packages/ace-core/src/core/ace.js index 32661692..16d2846f 100644 --- a/packages/ace-core/src/core/ace.js +++ b/packages/ace-core/src/core/ace.js @@ -53,7 +53,7 @@ module.exports = function ace(epubPath, options) { epub.extract() .then(() => epub.parse()) // initialize the report - .then(() => new Report(epub)) + .then(() => new Report(epub, options.outdir)) // Check each Content Doc .then(report => checker.check(epub, report)) // Process the Results diff --git a/packages/ace-report/src/defaults.json b/packages/ace-report/src/defaults.json new file mode 100644 index 00000000..c5d98bc2 --- /dev/null +++ b/packages/ace-report/src/defaults.json @@ -0,0 +1,5 @@ +{ + "report": { + "use-relative-paths": true + } +} diff --git a/packages/ace-report/src/report-builders.js b/packages/ace-report/src/report-builders.js index 38d0b21f..cffb24bc 100644 --- a/packages/ace-report/src/report-builders.js +++ b/packages/ace-report/src/report-builders.js @@ -5,6 +5,11 @@ const pkg = require('../package'); +const { config, paths } = require('@daisy/ace-config'); +const defaults = require('./defaults'); +const reportConfig = config.get('report', defaults.report); +const path = require('path'); + // static const ACE_DESCRIPTION = { '@type': 'earl:software', @@ -105,6 +110,10 @@ class ReportBuilder { build() { return this._json; } + setOutdir(outdir) { + this.outdir = outdir; + return this; + } withA11yMeta(metadata) { if (!metadata) return this; this._json['a11y-metadata'] = metadata; @@ -151,7 +160,11 @@ class ReportBuilder { return this; } withTestSubject(url, title, identifier, metadata, links) { - withTestSubject(this._json, url, title, identifier, metadata, links); + var url_ = url; + if (this.outdir != "" && reportConfig["use-relative-paths"]) { + url_ = path.relative(this.outdir, url); + } + withTestSubject(this._json, url_, title, identifier, metadata, links); return this; } } diff --git a/packages/ace-report/src/report.js b/packages/ace-report/src/report.js index a7f17245..d9c27940 100644 --- a/packages/ace-report/src/report.js +++ b/packages/ace-report/src/report.js @@ -39,8 +39,9 @@ function aggregateHTMLOutlines(outlines) { } module.exports = class Report { - constructor(epub) { + constructor(epub, outdir) { this._builder = new builders.ReportBuilder() + .setOutdir(outdir) .withTestSubject(epub.path, '', '', epub.metadata, epub.links) .withA11yMeta(a11yMetaChecker.analyze(epub.metadata)) }