Skip to content

Commit 945f29c

Browse files
committed
feat(share): render webviews using iframe
1 parent 98f4288 commit 945f29c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

apps/server/src/share/content_renderer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { highlightAuto } from "@triliumnext/highlightjs";
1818
import becca from "../becca/becca.js";
1919
import { BAttachment } from "../services/backend_script_entrypoint.js";
2020
import SAttachment from "./shaca/entities/sattachment.js";
21+
import { sanitizeUrl } from "@braintree/sanitize-url";
2122

2223
const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`;
2324
const templateCache: Map<string, string> = new Map();
@@ -250,6 +251,8 @@ export function getContent(note: SNote | BNote) {
250251
renderFile(note, result);
251252
} else if (note.type === "book") {
252253
result.isEmpty = true;
254+
} else if (note.type === "webView") {
255+
renderWebView(note, result);
253256
} else {
254257
result.content = `<p>${t("content_renderer.note-cannot-be-displayed")}</p>`;
255258
}
@@ -414,6 +417,13 @@ function renderFile(note: SNote | BNote, result: Result) {
414417
}
415418
}
416419

420+
function renderWebView(note: SNote | BNote, result: Result) {
421+
const url = note.getLabelValue("webViewSrc");
422+
if (!url) return;
423+
424+
result.content = `<iframe class="webview" src="${sanitizeUrl(url)}"></iframe>`;
425+
}
426+
417427
export default {
418428
getContent
419429
};

packages/share-theme/src/styles/content.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,19 @@
5252

5353
body:not(.math-loaded) .math-tex {
5454
visibility: hidden;
55+
}
56+
57+
body.type-webView #main {
58+
max-width: unset;
59+
}
60+
61+
body.type-webView #content {
62+
display: flex;
63+
flex-direction: column;
64+
height: 100%;
65+
}
66+
67+
iframe.webview {
68+
width: 100%;
69+
flex-grow: 1;
5570
}

0 commit comments

Comments
 (0)