Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(export/zip): get tree to render
Elian Doranf189deb415e4
diff --git a/apps/server/src/services/export/zip.ts b/apps/server/src/services/export/zip.tsindex f544f2a73d..a175241d85 100644--- a/apps/server/src/services/export/zip.ts+++ b/apps/server/src/services/export/zip.ts@@ -23,7 +23,7 @@ import type BNote from "../../becca/entities/bnote.js";import type { Response } from "express";import type { NoteMetaFile } from "../meta/note_meta.js";import cssContent from "@triliumnext/ckeditor5/content.css";-import { renderNoteContent } from "../../share/content_renderer.js";+import { renderNoteForExport } from "../../share/content_renderer.js";type RewriteLinksFn = (content: string, noteMeta: NoteMeta) => string;@@ -332,7 +332,7 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "hconst htmlTitle = escapeHtml(title);if (note) {- content = renderNoteContent(note);+ content = renderNoteForExport(note, branch);} else {// <base> element will make sure external links are openable - https://github.com/zadam/trilium/issues/1289#issuecomment-704066809content = `<html>diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.tsindex aad3ab9d2d..465c605cac 100644--- a/apps/server/src/share/content_renderer.ts+++ b/apps/server/src/share/content_renderer.ts@@ -26,7 +26,12 @@ export interface Result {isEmpty?: boolean;}-function getSharedSubTreeRoot(note: SNote | BNote | undefined): { note?: SNote | BNote; branch?: SBranch | BBranch } {+interface Subroot {+ note?: SNote | BNote;+ branch?: SBranch | BBranch+}++function getSharedSubTreeRoot(note: SNote | BNote | undefined): Subroot {if (!note || note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {// share root itself is not sharedreturn {};@@ -53,9 +58,21 @@ function getSharedSubTreeRoot(note: SNote | BNote | undefined): { note?: SNote |return getSharedSubTreeRoot(parentBranch.getParentNote());}-export function renderNoteContent(note: SNote | BNote) {- const { header, content, isEmpty } = getContent(note);+export function renderNoteForExport(note: BNote, parentBranch: BBranch) {+ const subRoot: Subroot = {+ branch: parentBranch,+ note: parentBranch.getNote()+ };+ return renderNoteContentInternal(note, subRoot, note.getParentNotes()[0].noteId);+}++export function renderNoteContent(note: SNote) {const subRoot = getSharedSubTreeRoot(note);+ return renderNoteContentInternal(note, subRoot, "_share");+}++function renderNoteContentInternal(note: SNote | BNote, subRoot: Subroot, rootNoteId: string) {+ const { header, content, isEmpty } = getContent(note);const showLoginInShareTheme = options.getOption("showLoginInShareTheme");const opts = {note,@@ -68,7 +85,8 @@ export function renderNoteContent(note: SNote | BNote) {appPath: isDev ? app_path : `../${app_path}`,showLoginInShareTheme,t,- isDev+ isDev,+ rootNoteId};// Check if the user has their own template.diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejsindex 5c39051ebf..ba3d45b440 100644--- a/packages/share-theme/src/templates/page.ejs+++ b/packages/share-theme/src/templates/page.ejs@@ -108,7 +108,7 @@ content = content.replaceAll(headingRe, (...match) => {<%const ancestors = [];let notePointer = note;- while (notePointer.parents[0].noteId !== "_share") {+ while (notePointer.parents[0].noteId !== rootNoteId) {const pointerParent = notePointer.parents[0];ancestors.push(pointerParent.noteId);notePointer = pointerParent;