feat(print): support CSS for collections too

This commit is contained in:
Elian Doran
2025-11-07 17:48:37 +02:00
parent e4cd946ea8
commit 71d7403690

View File

@@ -92,7 +92,10 @@ function CollectionRenderer({ note, onReady }: RendererProps) {
ntxId="print" ntxId="print"
highlightedTokens={null} highlightedTokens={null}
media="print" media="print"
onReady={onReady} onReady={async () => {
await loadCustomCss(note);
onReady();
}}
/>; />;
} }
@@ -107,6 +110,7 @@ function Error404({ noteId }: { noteId: string }) {
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>[] = [];
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;
@@ -114,8 +118,15 @@ async function loadCustomCss(note: FNote) {
const linkEl = document.createElement("link"); const linkEl = document.createElement("link");
linkEl.href = `/api/notes/${printCssNote.noteId}/download`; linkEl.href = `/api/notes/${printCssNote.noteId}/download`;
linkEl.rel = "stylesheet"; linkEl.rel = "stylesheet";
const promise = $.Deferred();
loadPromises.push(promise.promise());
linkEl.onload = () => promise.resolve();
document.head.appendChild(linkEl); document.head.appendChild(linkEl);
} }
await Promise.allSettled(loadPromises);
} }
main(); main();