-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added option to choose navigation root #107
base: master
Are you sure you want to change the base?
Changes from 1 commit
0b81ad8
e2bcb10
84f1f57
23618f4
c4ceff5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,7 +326,8 @@ declare function dapi:epub($request as map(*)) { | |
}; | ||
|
||
declare %private function dapi:work2epub($request as map(*), $id as xs:string, $work as document-node(), $lang as xs:string?) { | ||
let $config := $config:epub-config($work, $lang) | ||
let $navRoot := fn:fold-left(tokenize($request?parameters?nav-root, '/'), (), function($a, $b) { (if (not(empty($a))) then $a else $work)/node()[position()=xs:integer($b)] }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TEI Publisher application makes extensive use of the functions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose to use the position of the node instead because the node to be the root for navigation will most likely be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The For example, given the sample TEI file from your test saved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't thought of using that, I will test it and let you know. |
||
let $config := map:merge(($config:epub-config($work, $lang), map { 'navRoot': $navRoot })) | ||
let $odd := head(($request?parameters?odd, $config:default-odd)) | ||
let $oddName := replace($odd, "^([^/\.]+).*$", "$1") | ||
let $cssDefault := util:binary-to-string(util:binary-doc($config:output-root || "/" || $oddName || ".css")) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const util = require('./util.js'); | ||
const path = require('path'); | ||
const FormData = require('form-data'); | ||
const chai = require('chai'); | ||
const chaiXML = require('chai-xml'); | ||
const expect = chai.expect; | ||
const chaiResponseValidator = require('chai-openapi-response-validator'); | ||
const jsdom = require("jsdom"); | ||
const zip = require('adm-zip'); | ||
const { JSDOM } = jsdom; | ||
|
||
const spec = path.resolve("./modules/lib/api.json"); | ||
chai.use(chaiResponseValidator(spec)); | ||
chai.use(chaiXML); | ||
|
||
const testXml = `<TEI xmlns="http://www.tei-c.org/ns/1.0"> | ||
<teiHeader> | ||
<fileDesc> | ||
<titleStmt> | ||
<title>EPUB Navigation Test</title> | ||
</titleStmt> | ||
<publicationStmt> | ||
<p /> | ||
</publicationStmt> | ||
<sourceDesc> | ||
<p /> | ||
</sourceDesc> | ||
</fileDesc> | ||
</teiHeader> | ||
<text> | ||
<front> | ||
<div type="document" n="1" xml:id="d1" subtype="pre-document"> | ||
<head>Pre-Document 1</head> | ||
<p>Pre-Document 1 body</p> | ||
</div> | ||
<div type="document" n="2" xml:id="d2" subtype="pre-document"> | ||
<head>Pre-Document 2</head> | ||
<p>Pre-Document 2 body</p> | ||
</div> | ||
<div type="document" n="3" xml:id="d3" subtype="pre-document"> | ||
<head>Pre-Document 3</head> | ||
<p>Pre-Document 3 body</p> | ||
</div> | ||
</front> | ||
<body> | ||
<div type="document" n="4" xml:id="d4" subtype="document"> | ||
<head>Document 4</head> | ||
<p>Document 4 body</p> | ||
</div> | ||
<div type="document" n="5" xml:id="d5" subtype="document"> | ||
<head>Document 5</head> | ||
<p>Document 5 body</p> | ||
</div> | ||
<div type="document" n="6" xml:id="d6" subtype="document"> | ||
<head>Document 6</head> | ||
<p>Document 6 body</p> | ||
</div> | ||
</body> | ||
</text> | ||
</TEI>`; | ||
|
||
function getNav(data) { | ||
return new zip(Buffer.from(data)).getEntries().find(({ entryName }) => entryName === 'OEBPS/nav.xhtml')?.getData().toString('utf-8'); | ||
} | ||
|
||
describe('/api/document/{document}}/epub?nav-root=', function() { | ||
before(async () => { | ||
await util.login(); | ||
const formData = new FormData() | ||
formData.append('files[]', testXml, "nav.xml"); | ||
const res = await util.axios.post('upload/playground', formData, { | ||
headers: formData.getHeaders() | ||
}); | ||
expect(res.data).to.have.length(1); | ||
expect(res.data[0].name).to.equal('/db/apps/tei-publisher/data/playground/nav.xml'); | ||
expect(res).to.satisfyApiSpec; | ||
}); | ||
|
||
it('let tei-publisher determine the navigation root', async () => { | ||
const res = await util.axios.get('document/playground%2Fnav.xml/epub', { responseType: 'arraybuffer' }); | ||
expect(res.status).to.equal(200); | ||
const document = new JSDOM(getNav(res.data), { contentType: "application/xml" }).window.document; | ||
expect(document.querySelectorAll('li').length).to.equal(3); | ||
}); | ||
|
||
it('define navigation root', async () => { | ||
const res = await util.axios.get('document/playground%2Fnav.xml/epub?nav-root=1/4', { responseType: 'arraybuffer' }); | ||
expect(res.status).to.equal(200); | ||
const document = new JSDOM(getNav(res.data), { contentType: "application/xml" }).window.document; | ||
expect(document.querySelectorAll('li').length).to.equal(6); | ||
}); | ||
|
||
after(util.logout); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test below uses a value of
1/4
, but this example has a leading slash -/1/4
. Is the leading slash optional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, it should be
/1/4
won't work, I will update it