diff --git a/README.md b/README.md index 1a92600..6e39cff 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,8 @@ To start a local DTS web service: ## Must -* add a github action to generate static DTS from thornton corpus -* parametrise the DTS server -* parametrise the SDTS generator * test the static generator with github +* add a github action to generate static DTS from thornton corpus ## Should diff --git a/controllers/controller.js b/controllers/controller.js index ed8fa97..d1db96e 100644 --- a/controllers/controller.js +++ b/controllers/controller.js @@ -4,12 +4,30 @@ // TODO: use SaxonJS instead of DOMParser & XPath const SaxonJS = require("saxon-js"); const fs = require("fs"); +const path = require("path"); const DOMParser = require("@xmldom/xmldom").DOMParser; -const settings = require("../settings.js"); + +// read service settings from settings.js . +// they can be overridden by a json file passed as the last argument +function readSettings() { + let ret = require("../settings.js"); + let path = process.argv[process.argv.length - 1] + if (path.endsWith(".json")) { + let content = fs.readFileSync(path) + ret = { + ...ret, + ...JSON.parse(content) + } + } + return ret +} +const settings = readSettings() + const XPath = require("xpath"); const collectionRoot = settings.source; const Corpus = require("./corpus") const corpus = new Corpus(settings.source) + corpus.buildAndSaveTree() // tei namespace const TEINS = "http://www.tei-c.org/ns/1.0"; @@ -208,28 +226,6 @@ var controllers = { }, }; -// TODO: convert those functions into a class - -// async function getMetadataFromTEIFile(filePath) { -// let content = readFile(filePath); -// // optimisation: we extract the TEI header (so less xml to parse) -// let m = content.match(/^.*<\/teiHeader>/s); -// content = `${m[0]}`; -// let doc = await SaxonJS.getResource({ text: content, type: "xml" }); - -// let ret = { -// title: "//teiHeader/fileDesc/titleStmt/title[1]/text()", -// }; - -// for (const [k, v] of Object.entries(ret)) { -// ret[k] = SaxonJS.XPath.evaluate(v, doc, { -// xpathDefaultNamespace: "http://www.tei-c.org/ns/1.0", -// }).data; -// } - -// return ret; -// } - function getHTMLfromTEI(tei) { let ret = ""; diff --git a/controllers/corpus.js b/controllers/corpus.js index 124613d..8a9a1c0 100644 --- a/controllers/corpus.js +++ b/controllers/corpus.js @@ -1,7 +1,6 @@ const SaxonJS = require("saxon-js"); // const xpath = require('xpath') // const dom = require('xmldom').DOMParser -const path = require("path"); const fs = require("fs"); const CorpusReader = require("./corpusReader") diff --git a/package.json b/package.json index 28dcbb9..fc2c898 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kdl-dts-server", - "version": "0.1.0", + "version": "0.2.0", "description": "Distributed Text Service (DTS) server from TEI files.", "/main": "server.js", "scripts": { diff --git a/settings.js b/settings.js index 36578f2..0e6ce23 100644 --- a/settings.js +++ b/settings.js @@ -1,8 +1,7 @@ module.exports = { - // localPath: "../../texts", - // source: "tests/corpus", + source: "tests/corpus", // source: "https://github.com/kingsdigitallab/alice-thornton/tree/edition/texts", - source: "https://github.com/kingsdigitallab/kdl-dts-server/tree/main/tests/corpus", + // source: "https://github.com/kingsdigitallab/kdl-dts-server/tree/main/tests/corpus", // The stable and base of the URI for most ids (mainly collections & documents). // Only used for identifiction, it may not be accessible on the web. // https://api.github.com/repos/kingsdigitallab/alice-thornton/git/trees/edition?recursive=1 @@ -10,9 +9,13 @@ module.exports = { baseUri: "https://github.com/kingsdigitallab/kdl-dts-server/tests/", // TODO: read this from a collection.json file rootCollection: { - slug: "thornton-books", - title: "Alice Thornton's Books", + slug: "root", + title: "Root Collection", }, + // rootCollection: { + // slug: "thornton-books", + // title: "Alice Thornton's Books", + // }, services: { root: "/", collections: "/collections/", diff --git a/tests/02-services.test.js b/tests/02-services.test.js index bed6405..db7bef5 100644 --- a/tests/02-services.test.js +++ b/tests/02-services.test.js @@ -14,7 +14,6 @@ S test additional fields in the responses */ - describe('Unit testing the / route', function() { let collectionUrl = '' diff --git a/tests/settings-test.json b/tests/settings-test.json new file mode 100644 index 0000000..052b868 --- /dev/null +++ b/tests/settings-test.json @@ -0,0 +1,8 @@ +{ + "source": "https://github.com/kingsdigitallab/kdl-dts-server/tree/main/tests/corpus", + "baseUri": "https://github.com/kingsdigitallab/kdl-dts-server/tests/", + "rootCollection": { + "slug": "test-corpus", + "title": "Test Corpus" + } +}