Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ccheraa
Copy link
Contributor

@ccheraa ccheraa commented May 31, 2022

currently, the navigation root is determined as the parent of the first document found, this may omit some documents from the navigation pane if their first common ancestor is not their parent
so by providing a path to the correct navigation root, we can make sure that all documents appear in the navigation pane, and that's by using the nav-root query parameter, for example, as follows:

/exist/apps/tei-publisher/api/document/document.xml/epub?nav-root=1/1/3

1/1/3 means that the navigation root node should be $doc/node()[1]/node()[1]/node()[3]

This open source contribution to the tei-publisher-app project was commissioned by the Office of the Historian, U.S. Department of State, https://history.state.gov.

"in": "query",
"schema": {
"type": "string",
"example": "/1/4"
Copy link
Member

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?

Copy link
Contributor Author

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

@joewiz
Copy link
Member

joewiz commented Aug 27, 2022

@ccheraa By "navigation pane", do you mean the TEI Publisher app's own table of contents pane, or are you referring to an ebook reader/client app's table of contents?

@@ -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)] })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TEI Publisher application makes extensive use of the functions util:node-id() and util:node-by-id(). I suspect they may exhibit better performance. Were you aware of these functions? If so, did you have a reason for opting not to use them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 text or body, which don't always have an ID

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The util:node-id() and util:node-by-id() functions do use the node's numeric position in the node hierarchy. For their function documentation, see https://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/util#node-by-id.2.

For example, given the sample TEI file from your test saved to /db/test/test.xml, the query util:node-id(doc("/db/test/test.xml")/tei:TEI/tei:text) returns 1.4, and correspondingly, the query util:node-by-id(doc("/db/test/test.xml"), "1.4") returns the <text> element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@ccheraa
Copy link
Contributor Author

ccheraa commented Aug 30, 2022

@ccheraa By "navigation pane", do you mean the TEI Publisher app's own table of contents pane, or are you referring to an ebook reader/client app's table of contents?

I mean the navigation pane of the ebook reader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants