mirror of
https://github.com/zadam/trilium.git
synced 2026-01-06 14:44:25 +01:00
fix(print): skip printing protected notes if session not available
This commit is contained in:
parent
502c896616
commit
66cdee82a4
@ -1,10 +1,11 @@
|
|||||||
import FNote from "./entities/fnote";
|
|
||||||
import { render } from "preact";
|
import { render } from "preact";
|
||||||
import { CustomNoteList, useNoteViewType } from "./widgets/collections/NoteList";
|
|
||||||
import { useCallback, useLayoutEffect, useRef } from "preact/hooks";
|
import { useCallback, useLayoutEffect, useRef } from "preact/hooks";
|
||||||
|
|
||||||
|
import FNote from "./entities/fnote";
|
||||||
import content_renderer from "./services/content_renderer";
|
import content_renderer from "./services/content_renderer";
|
||||||
import { dynamicRequire, isElectron } from "./services/utils";
|
|
||||||
import { applyInlineMermaid } from "./services/content_renderer_text";
|
import { applyInlineMermaid } from "./services/content_renderer_text";
|
||||||
|
import { dynamicRequire, isElectron } from "./services/utils";
|
||||||
|
import { CustomNoteList, useNoteViewType } from "./widgets/collections/NoteList";
|
||||||
|
|
||||||
interface RendererProps {
|
interface RendererProps {
|
||||||
note: FNote;
|
note: FNote;
|
||||||
@ -42,7 +43,7 @@ function App({ note, noteId }: { note: FNote | null | undefined, noteId: string
|
|||||||
}, []);
|
}, []);
|
||||||
const props: RendererProps | undefined | null = note && { note, onReady, onProgressChanged };
|
const props: RendererProps | undefined | null = note && { note, onReady, onProgressChanged };
|
||||||
|
|
||||||
if (!note || !props) return <Error404 noteId={noteId} />
|
if (!note || !props) return <Error404 noteId={noteId} />;
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
document.body.dataset.noteType = note.type;
|
document.body.dataset.noteType = note.type;
|
||||||
@ -51,8 +52,8 @@ function App({ note, noteId }: { note: FNote | null | undefined, noteId: string
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{note.type === "book"
|
{note.type === "book"
|
||||||
? <CollectionRenderer {...props} />
|
? <CollectionRenderer {...props} />
|
||||||
: <SingleNoteRenderer {...props} />
|
: <SingleNoteRenderer {...props} />
|
||||||
}
|
}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@ -91,7 +92,7 @@ function SingleNoteRenderer({ note, onReady }: RendererProps) {
|
|||||||
await loadCustomCss(note);
|
await loadCustomCss(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
load().then(() => requestAnimationFrame(onReady))
|
load().then(() => requestAnimationFrame(onReady));
|
||||||
}, [ note ]);
|
}, [ note ]);
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
@ -124,12 +125,12 @@ function Error404({ noteId }: { noteId: string }) {
|
|||||||
<p>The note you are trying to print could not be found.</p>
|
<p>The note you are trying to print could not be found.</p>
|
||||||
<small>{noteId}</small>
|
<small>{noteId}</small>
|
||||||
</main>
|
</main>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCustomCss(note: FNote) {
|
async function loadCustomCss(note: FNote) {
|
||||||
const printCssNotes = await note.getRelationTargets("printCss");
|
const printCssNotes = await note.getRelationTargets("printCss");
|
||||||
let loadPromises: JQueryPromise<void>[] = [];
|
const loadPromises: JQueryPromise<void>[] = [];
|
||||||
|
|
||||||
for (const printCssNote of printCssNotes) {
|
for (const printCssNote of printCssNotes) {
|
||||||
if (!printCssNote || (printCssNote.type !== "code" && printCssNote.mime !== "text/css")) continue;
|
if (!printCssNote || (printCssNote.type !== "code" && printCssNote.mime !== "text/css")) continue;
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
|
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
|
||||||
import froca from "../../../services/froca";
|
|
||||||
import type FNote from "../../../entities/fnote";
|
import type FNote from "../../../entities/fnote";
|
||||||
import content_renderer from "../../../services/content_renderer";
|
import content_renderer from "../../../services/content_renderer";
|
||||||
|
import froca from "../../../services/froca";
|
||||||
import type { ViewModeProps } from "../interface";
|
import type { ViewModeProps } from "../interface";
|
||||||
import { filterChildNotes, useFilteredNoteIds } from "./utils";
|
import { filterChildNotes, useFilteredNoteIds } from "./utils";
|
||||||
|
|
||||||
@ -22,6 +23,8 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady, onPro
|
|||||||
const notesWithContent: NotesWithContent[] = [];
|
const notesWithContent: NotesWithContent[] = [];
|
||||||
|
|
||||||
async function processNote(note: FNote, depth: number) {
|
async function processNote(note: FNote, depth: number) {
|
||||||
|
if (!isNotePrintable(note)) return;
|
||||||
|
|
||||||
const content = await content_renderer.getRenderedContent(note, {
|
const content = await content_renderer.getRenderedContent(note, {
|
||||||
trim: false,
|
trim: false,
|
||||||
noChildrenList: true
|
noChildrenList: true
|
||||||
@ -78,6 +81,14 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady, onPro
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isNotePrintable(note: FNote) {
|
||||||
|
if (!note.isContentAvailable()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function insertPageTitle(contentEl: HTMLElement, title: string) {
|
function insertPageTitle(contentEl: HTMLElement, title: string) {
|
||||||
const pageTitleEl = document.createElement("h1");
|
const pageTitleEl = document.createElement("h1");
|
||||||
pageTitleEl.textContent = title;
|
pageTitleEl.textContent = title;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user