Skip to content

Commit 3e1cdfb

Browse files
committed
feat(rootDir): Add root dir as hidden node dataset, Render process may need it when website url is redirected.
1 parent 8ac16f3 commit 3e1cdfb

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

assets/webpage.txt.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,15 @@ async function loadLeftSidebar(document) {
475475

476476
try
477477
{
478-
const hostPath = getURLPath();
479-
const baseDir = hostPath.split('/')[0];
478+
const dataNode = document.getElementById('invio-hidden-data-node');
479+
let baseDir = '';
480+
if (dataNode?.dataset.root) {
481+
baseDir = dataNode?.dataset.root;
482+
} else {
483+
const hostPath = getURLPath();
484+
baseDir = hostPath.split('/')[0];
485+
}
486+
480487
const sidebarUrl = `${baseDir}/_common-left-tree.html`
481488
console.log("Loading left sidebar: ", sidebarUrl);
482489
response = await fetch(sidebarUrl);

src/html-generation/html-generator.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export class HTMLGenerator {
9494

9595
let fileTree: HTMLDivElement = this.generateHTMLTree(tree, usingDocument, pageTitle, "file-tree", true, 1, 1, false);
9696
// leftSidebar.appendChild(fileTree);
97+
const dataNode = this.generateRootDirNode(file, usingDocument);
98+
leftSidebar.appendChild(dataNode);
99+
const rootDir = file.exportPath.directory.asString?.split('/')[0];
100+
97101
file.downloads.push(new Downloadable('_common-left-tree.html', fileTree.outerHTML, new Path(file.exportPath.asString.split('/')[0])));
98102
}
99103

@@ -695,6 +699,15 @@ export class HTMLGenerator {
695699
return container;
696700
}
697701

702+
private static generateRootDirNode(file: ExportFile, usingDocument: Document) {
703+
const rootDir = file.exportPath.directory.asString?.split('/')[0];
704+
const container = document.createElement('div');
705+
container.id = 'invio-hidden-data-node'
706+
container.style.display = 'none';
707+
container.setAttribute('data-root', rootDir);
708+
return container;
709+
}
710+
698711
private static generateHTMLTree(tree: LinkTree, usingDocument: Document, treeTitle: string, className: string, showNestingIndicator = true, minDepth: number = 1, minCollapsableDepth = 1, closeAllItems: boolean = false): HTMLDivElement {
699712
/*
700713
- div.tree-container

0 commit comments

Comments
 (0)