Skip to content

Commit

Permalink
Document URL routing: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangmm committed Aug 20, 2023
1 parent 0c4652c commit 0828e2c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions data/doc/documentation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3694,7 +3694,7 @@ declare function pmf:code($config as map(*), $node as element(), $class as xs:st
<section xml:id="client-side-urls">
<title>Adjusting the client-side URL handling</title>
<para>With the two routes we set up for the documentation in the previous section, we cover the cases in which the entire page is loaded or reloaded by the browser, either by following a link, selecting a bookmark or pasting an URL into the location bar. However, TEI Publisher is a highly dynamic application and users can interact with the page without reloading it, e.g. by navigating to the next page of the document, selecting a toggle, clickling a link in the table of contents etc. Client-side interactions like this also need to be recorded and should be reflected in the URL, so users can copy or bookmark it. And the bookmarked link should later reconstitute the page in the state it was in when the bookmark was created.</para>
<para>All client-side web components in TEI Publisher therefore use a central state registry to track their state and reflect it in the URL. You can see this in action when you open any of the larger sample documents and navigate between its pages using the navigation buttons: the URL shown in the browser's location bar will change. For simple documents like <link xlink:href="../test/kant_rvernunft_1781.TEI-P5.xml" xlink:show="new">Kant's Kritik</link>, the current page displayed will be encoded in the <parameter>root</parameter>. If the divisions or pages to navigate by have an <option>xml:id</option>, this will be used instead and placed into the <parameter>id</parameter> parameter. The path to the TEI document is also tracked (it's the <code>test/kant_rvernunft_1781.TEI-P5.xml</code> part of the URL), though you won't see it change while navigating.</para>
<para>All client-side web components in TEI Publisher therefore use a central state registry to track their state and reflect it in the URL. You can see this in action when you open any of the larger sample documents and navigate between its pages using the navigation buttons: the URL shown in the browser's location bar will change. For simple documents like <link xlink:href="../test/kant_rvernunft_1781.TEI-P5.xml" xlink:show="new">Kant's Kritik</link>, the current page displayed will be encoded in the <parameter>root</parameter> parameter. If the divisions or pages to navigate by have an <code>xml:id</code>, this will be used instead and placed into the <parameter>id</parameter> parameter. The path to the TEI document is also tracked (it's the <code>test/kant_rvernunft_1781.TEI-P5.xml</code> part of the URL), though you won't see it change while navigating.</para>
<para>For the documentation we deviate from this default pattern with the relative URL becoming <code>documentation/{id}</code>. We thus need to inform the client-side components about the change, so they know how to store their state into the URL. The central <tag>pb-page</tag> component provides two attributes for this:</para>
<variablelist>
<varlistentry>
Expand All @@ -3710,8 +3710,8 @@ declare function pmf:code($config as map(*), $node as element(), $class as xs:st
</listitem>
</varlistentry>
</variablelist>
<para>The expression passed to url-template may reference any of the default parameters known to TEI Publisher components, in particular <option>path</option>, <option>odd</option>, <option>view</option> or <option>id</option>. Additionally, any parameter supplied to a <tag>pb-view</tag> via the <tag>pb-param</tag> element can be referenced. Just have a look at the constructed URLs in the browser to see which parameters are being tracked for a specific page. Within TEI Publisher, URL templates will usually be rather simple. For the full syntax supported check the underlying <link xlink:href="https://www.npmjs.com/package/path-to-regexp" xlink:show="new">javascript library</link>.</para>
<para>To handle the URL for the documentation example, we set the URL template to <code>documentation/:id?</code>. This injects the <option>id</option> parameter as part of the path, e.g. <code>/documentation/api</code>. The ? after the parameter indicates that it is optional. We also do not want the <option>path</option> to the document to appear anywhere (it is always the same in the case), so we add it to <option>url-ignore</option>. The resulting <tag>pb-page</tag> would thus look as follows:</para>
<para>The expression passed to url-template may reference any of the default parameters known to TEI Publisher components, in particular <parameter>path</parameter>, <parameter>odd</parameter>, <parameter>view</parameter> or <parameter>id</parameter>. Additionally, any parameter supplied to a <tag>pb-view</tag> via the <tag>pb-param</tag> element can be referenced. Just have a look at the constructed URLs in the browser to see which parameters are being tracked for a specific page. Within TEI Publisher, URL templates will usually be rather simple. For the full syntax supported check the underlying <link xlink:href="https://www.npmjs.com/package/path-to-regexp" xlink:show="new">javascript library</link>.</para>
<para>To handle the URL for the documentation example, we set the URL template to <code>documentation/:id?</code>. This injects the <option>id</option> parameter as part of the path, e.g. <code>/documentation/api</code>. The ? after the parameter indicates that it is optional. We also do not want the <code>path</code> to the document to appear anywhere (it is always the same in the case), so we add it to <code>url-ignore</code>. The resulting <tag>pb-page</tag> would thus look as follows:</para>
<synopsis language="html"><![CDATA[<pb-page url-template="documentation/:id?" url-ignore="odd,view,path" data-template="pages:pb-page" unresolved="unresolved" >]]></synopsis>
</section>
</section>
Expand Down

0 comments on commit 0828e2c

Please sign in to comment.