mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 20:19:05 +01:00
fix(export/share): tree not expanding properly
This commit is contained in:
parent
413137ac64
commit
a2110ca631
@ -1,6 +1,6 @@
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import NoteMeta, { NoteMetaFile } from "../../meta/note_meta";
|
import NoteMeta, { NoteMetaFile } from "../../meta/note_meta";
|
||||||
import { ZipExportProvider } from "./abstract_provider";
|
import { ZipExportProvider } from "./abstract_provider.js";
|
||||||
import { RESOURCE_DIR } from "../../resource_dir";
|
import { RESOURCE_DIR } from "../../resource_dir";
|
||||||
import { getResourceDir, isDev } from "../../utils";
|
import { getResourceDir, isDev } from "../../utils";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
@ -50,7 +50,7 @@ export default class ShareThemeExportProvider extends ZipExportProvider {
|
|||||||
const basePath = "../".repeat(noteMeta.notePath.length - 1);
|
const basePath = "../".repeat(noteMeta.notePath.length - 1);
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
content = renderNoteForExport(note, branch, basePath);
|
content = renderNoteForExport(note, branch, basePath, noteMeta.notePath.slice(0, -1));
|
||||||
content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, "href=\"#root/$1\"");
|
content = content.replace(/href="[^"]*\.\/([a-zA-Z0-9_\/]{12})[^"]*"/g, "href=\"#root/$1\"");
|
||||||
content = this.rewriteFn(content, noteMeta);
|
content = this.rewriteFn(content, noteMeta);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,7 @@ function getSharedSubTreeRoot(note: SNote | BNote | undefined): Subroot {
|
|||||||
return getSharedSubTreeRoot(parentBranch.getParentNote());
|
return getSharedSubTreeRoot(parentBranch.getParentNote());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath: string) {
|
export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath: string, ancestors: string[]) {
|
||||||
const subRoot: Subroot = {
|
const subRoot: Subroot = {
|
||||||
branch: parentBranch,
|
branch: parentBranch,
|
||||||
note: parentBranch.getNote()
|
note: parentBranch.getNote()
|
||||||
@ -69,7 +69,7 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
|
|||||||
|
|
||||||
return renderNoteContentInternal(note, {
|
return renderNoteContentInternal(note, {
|
||||||
subRoot,
|
subRoot,
|
||||||
rootNoteId: note.getParentNotes()[0].noteId,
|
rootNoteId: parentBranch.noteId,
|
||||||
cssToLoad: [
|
cssToLoad: [
|
||||||
`${basePath}style.css`,
|
`${basePath}style.css`,
|
||||||
`${basePath}boxicons.css`
|
`${basePath}boxicons.css`
|
||||||
@ -77,13 +77,22 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
|
|||||||
jsToLoad: [
|
jsToLoad: [
|
||||||
`${basePath}script.js`
|
`${basePath}script.js`
|
||||||
],
|
],
|
||||||
logoUrl: `${basePath}icon-color.svg`
|
logoUrl: `${basePath}icon-color.svg`,
|
||||||
|
ancestors
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderNoteContent(note: SNote) {
|
export function renderNoteContent(note: SNote) {
|
||||||
const subRoot = getSharedSubTreeRoot(note);
|
const subRoot = getSharedSubTreeRoot(note);
|
||||||
|
|
||||||
|
const ancestors: string[] = [];
|
||||||
|
let notePointer = note;
|
||||||
|
while (notePointer.parents[0].noteId !== subRoot.note?.noteId) {
|
||||||
|
const pointerParent = notePointer.parents[0];
|
||||||
|
ancestors.push(pointerParent.noteId);
|
||||||
|
notePointer = pointerParent;
|
||||||
|
}
|
||||||
|
|
||||||
// Determine CSS to load.
|
// Determine CSS to load.
|
||||||
const cssToLoad: string[] = [];
|
const cssToLoad: string[] = [];
|
||||||
if (!isDev && !note.isLabelTruthy("shareOmitDefaultCss")) {
|
if (!isDev && !note.isLabelTruthy("shareOmitDefaultCss")) {
|
||||||
@ -110,7 +119,8 @@ export function renderNoteContent(note: SNote) {
|
|||||||
rootNoteId: "_share",
|
rootNoteId: "_share",
|
||||||
cssToLoad,
|
cssToLoad,
|
||||||
jsToLoad,
|
jsToLoad,
|
||||||
logoUrl
|
logoUrl,
|
||||||
|
ancestors
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +130,7 @@ interface RenderArgs {
|
|||||||
cssToLoad: string[];
|
cssToLoad: string[];
|
||||||
jsToLoad: string[];
|
jsToLoad: string[];
|
||||||
logoUrl: string;
|
logoUrl: string;
|
||||||
|
ancestors: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs) {
|
function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs) {
|
||||||
|
|||||||
@ -137,6 +137,7 @@ function register(router: Router) {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send(renderNoteContent(note));
|
res.send(renderNoteContent(note));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -97,16 +97,7 @@ content = content.replaceAll(headingRe, (...match) => {
|
|||||||
</div>
|
</div>
|
||||||
<% if (hasTree) { %>
|
<% if (hasTree) { %>
|
||||||
<nav id="menu">
|
<nav id="menu">
|
||||||
<%
|
<%- include("tree_item", {note: subRoot.note, activeNote: note, subRoot: subRoot, ancestors}) %>
|
||||||
const ancestors = [];
|
|
||||||
let notePointer = note;
|
|
||||||
while (notePointer.parents[0].noteId !== rootNoteId) {
|
|
||||||
const pointerParent = notePointer.parents[0];
|
|
||||||
ancestors.push(pointerParent.noteId);
|
|
||||||
notePointer = pointerParent;
|
|
||||||
}
|
|
||||||
%>
|
|
||||||
<%- include("tree_item", {note: subRoot.note, activeNote: note, subRoot: subRoot, ancestors: ancestors}) %>
|
|
||||||
</nav>
|
</nav>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user