Commit fff03cb5 authored by Jérôme Chauveau's avatar Jérôme Chauveau
Browse files

no query params in side_toc route + hidden side_toc link + side_toc href rewrite

parent d37037f5
Loading
Loading
Loading
Loading
+8 −2
Changes for plugins/side_toc/side_toc.js: 8 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -10,11 +10,17 @@ class SideTocPlugin extends Plugin{

  run(){
    console.log("plugin side toc running");
    const urlPrefix = baseURI.replace(projectId +'/', '')
    fetch(`${baseURI}side_toc.html?urlPrefix=${urlPrefix}`).then((res) => res.text().then((toc) => {
    //const urlPrefix = baseURI.replace(projectId +'/', '')
      fetch(`${baseURI}side_toc/${route}/toc.html`).then((res) => res.text().then((toc) => {
          document.querySelector('.plugins-wrapper').innerHTML+=toc;
          document.querySelector('.side-toc').querySelectorAll('a').forEach((link) => {
              let href = link.getAttribute('href')
              //href = baseURI + href.split(projectId)[1]
              link.setAttribute('href', baseURI + href.split(projectId +'/')[1])
          })
      }))


    // if(document.getElementById('text') && document.getElementById(fragmentId)){
    if(document.getElementById('text') && fragmentId){
        this.highlightTreeNode('details_'+fragmentId)
+7 −6
Changes for plugins/side_toc/side_toc.xqm: 7 added lines, 6 removed lines.
Original line number Diff line number Diff line
module namespace max.plugin.side_toc = 'pddn/max/plugin/side_toc';
import module namespace max.toc = 'pddn/max/toc' at '../../rxq/toc.xqm';

declare
%rest:GET
%output:method("html")
%rest:query-param("urlPrefix", "{$urlPrefix}")
%rest:path("/{$project}/side_toc.html")
function max.plugin.side_toc:toc($project, $urlPrefix){
    let $toc := max.toc:getProjectTOC($project, $urlPrefix)
(:    let $input := <input type="hidden" name="currentTocItem" value="{$project}/{$doc}/{$id}"></input>:)
    return <div class='side-toc'>{$toc}</div>
%rest:path("/{$project}/side_toc/{$routeDoc=.*\.xml}/toc.html")
function max.plugin.side_toc:toc2($project, $routeDoc){
    let $toc := max.toc:getDocumentTOC($project, $routeDoc)
    let $currentUrl := request:uri()
    (:hidden link for "statification":)
    return <div class='side-toc'><a href="{$currentUrl}" style="display:none">{$currentUrl}</a>{$toc}</div>
};
 No newline at end of file
+1 −5
Changes for rxq/toc.xqm: 1 added line, 5 removed lines.
Original line number Diff line number Diff line
@@ -8,10 +8,6 @@ import module namespace max.i18n = 'pddn/max/i18n' at 'i18n.xqm';

(:get project table of contents:)
declare function max.toc:getProjectTOC($project){
    max.toc:getProjectTOC($project, max.util:getRelativeRootPath(()))
};

declare function max.toc:getProjectTOC($project, $urlPrefix){

    let $tocFile := max.util:getResourceFilePath($project, "editions/"||$project ||'/'||$max.cons:TOC_QUERY_FILEPATH)
    let $xml :=
@@ -20,7 +16,7 @@ declare function max.toc:getProjectTOC($project, $urlPrefix){
            xquery:eval(xs:anyURI($tocFile),map
            {
            'project':$project,
            'baseURI': $urlPrefix,
            'baseURI': max.util:getRelativeRootPath(()),
            'dbPath':max.config:getProjectDBPath($project),
            'locale': max.i18n:getLang($project)
            })