From 990a0e8469192e96bffe149e7f1d1923f1bb396a Mon Sep 17 00:00:00 2001 From: Daniel Weck Date: Tue, 11 Jul 2023 17:45:40 +0100 Subject: [PATCH] fix(KB): further live-patching of init.js for Ace's offline DAISY Knowledge Base --- src/main/kb.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/kb.js b/src/main/kb.js index 0b4ac72..0513851 100644 --- a/src/main/kb.js +++ b/src/main/kb.js @@ -435,10 +435,19 @@ export function startKnowledgeBaseServer(kbRootPath) { js = js.replace(`href: 'glossary'`, `href: 'glossary/'`); js = js.replace(`href: 'new'`, `href: 'new/'`); js = js.replace(`href: 'contribute'`, `href: 'contribute/'`); + + js = js.replace(`document.getElementById('page-title').insertAdjacentElement('afterBegin', div);`, `if (document.getElementById('page-title')) document.getElementById('page-title').insertAdjacentElement('afterBegin', div);`); + + // js = js.replace(`a.setAttribute('href', topic.href);`, `a.setAttribute('href', topic.href.endsWith('/') ? (topic.href + "index.html") : topic.href);`); + // js = js.replace(`a.setAttribute('href', '/publishing/docs/' + topic.topics[j]['href-override']);`, `a.setAttribute('href', '/publishing/docs/' + (topic.topics[j]['href-override'].endsWith('/') ? (topic.topics[j]['href-override'] + "index.html") : topic.topics[j]['href-override']));`); + // js = js.replace(`a.setAttribute('href', (isRoot ? topic.path + '/' : '') + topic.topics[j].href);`, `a.setAttribute('href', (isRoot ? topic.path + '/' : '') + (topic.topics[j].href.endsWith('/') ? (topic.topics[j].href + "index.html") : topic.topics[j].href));`); js = js.replace(`var search_div =`, `/* var search_div =`); js = js.replace(`appendChild(search_div);`, `appendChild(search_div); */`); + js = js.replace(`// scrub the search box`, `/* // scrub the search box`); + js = js.replace(`document.body.insertAdjacentElement('beforeEnd', script);`, `document.body.insertAdjacentElement('beforeEnd', script); */`); + const buff = Buffer.from(js); headers["Content-Length"] = buff.length.toString(); headers["Content-Type"] = "text/javascript";