mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 04:59:04 +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 { Response } from "express";
|
||||||
import type { NoteMetaFile } from "../meta/note_meta.js";
|
import type { NoteMetaFile } from "../meta/note_meta.js";
|
||||||
import cssContent from "@triliumnext/ckeditor5/content.css";
|
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;
|
type RewriteLinksFn = (content: string, noteMeta: NoteMeta) => string;
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
|
|||||||
const htmlTitle = escapeHtml(title);
|
const htmlTitle = escapeHtml(title);
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
content = renderNoteContent(note);
|
content = renderNoteForExport(note, branch);
|
||||||
} else {
|
} else {
|
||||||
// <base> element will make sure external links are openable - https://github.com/zadam/trilium/issues/1289#issuecomment-704066809
|
// <base> element will make sure external links are openable - https://github.com/zadam/trilium/issues/1289#issuecomment-704066809
|
||||||
content = `<html>
|
content = `<html>
|
||||||
|
|||||||
@ -26,7 +26,12 @@ export interface Result {
|
|||||||
isEmpty?: boolean;
|
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) {
|
if (!note || note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
|
||||||
// share root itself is not shared
|
// share root itself is not shared
|
||||||
return {};
|
return {};
|
||||||
@ -53,9 +58,21 @@ function getSharedSubTreeRoot(note: SNote | BNote | undefined): { note?: SNote |
|
|||||||
return getSharedSubTreeRoot(parentBranch.getParentNote());
|
return getSharedSubTreeRoot(parentBranch.getParentNote());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function renderNoteContent(note: SNote | BNote) {
|
export function renderNoteForExport(note: BNote, parentBranch: BBranch) {
|
||||||
const { header, content, isEmpty } = getContent(note);
|
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);
|
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 showLoginInShareTheme = options.getOption("showLoginInShareTheme");
|
||||||
const opts = {
|
const opts = {
|
||||||
note,
|
note,
|
||||||
@ -68,7 +85,8 @@ export function renderNoteContent(note: SNote | BNote) {
|
|||||||
appPath: isDev ? app_path : `../${app_path}`,
|
appPath: isDev ? app_path : `../${app_path}`,
|
||||||
showLoginInShareTheme,
|
showLoginInShareTheme,
|
||||||
t,
|
t,
|
||||||
isDev
|
isDev,
|
||||||
|
rootNoteId
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if the user has their own template.
|
// Check if the user has their own template.
|
||||||
|
|||||||
@ -108,7 +108,7 @@ content = content.replaceAll(headingRe, (...match) => {
|
|||||||
<%
|
<%
|
||||||
const ancestors = [];
|
const ancestors = [];
|
||||||
let notePointer = note;
|
let notePointer = note;
|
||||||
while (notePointer.parents[0].noteId !== "_share") {
|
while (notePointer.parents[0].noteId !== rootNoteId) {
|
||||||
const pointerParent = notePointer.parents[0];
|
const pointerParent = notePointer.parents[0];
|
||||||
ancestors.push(pointerParent.noteId);
|
ancestors.push(pointerParent.noteId);
|
||||||
notePointer = pointerParent;
|
notePointer = pointerParent;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user