mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 12:09:02 +01:00
feat(export/zip): get tree to render
This commit is contained in:
parent
9c460dbc87
commit
f189deb415
@ -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: "h
|
||||
const 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-704066809
|
||||
content = `<html>
|
||||
|
||||
@ -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 shared
|
||||
return {};
|
||||
@ -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.
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user