Skip to content

Build your personal knowledge base with Trilium Notes

chore(server): set up template for printing

Elian Doran63bcd80375c0
diff --git a/apps/server/src/assets/views/print.ejs b/apps/server/src/assets/views/print.ejs
new file mode 100644
index 0000000000..2ed13581f9
--- /dev/null
+++ b/apps/server/src/assets/views/print.ejs
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <link rel="shortcut icon" href="favicon.ico">
+ <meta name="mobile-web-app-capable" content="yes">
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover" />
+ <link rel="manifest" crossorigin="use-credentials" href="manifest.webmanifest">
+ <title>Trilium Notes</title>
+ <script src="<%= appPath %>/runtime.js" crossorigin type="module"></script>
+</head>
+<body
+ id="trilium-print"
+ lang="<%= currentLocale.id %>" dir="<%= currentLocale.rtl ? 'rtl' : 'ltr' %>"
+>
+<noscript><%= t("javascript-required") %></noscript>
+
+<script>
+ // hide body to reduce flickering on the startup. This is done through JS and not CSS to not hide <noscript>
+ document.getElementsByTagName("body")[0].style.display = "none";
+</script>
+
+<!-- Required for correct loading of scripts in Electron -->
+<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
+
+<script src="<%= appPath %>/print.js" crossorigin type="module"></script>
+
+</body>
+</html>
diff --git a/apps/server/src/routes/api/print.ts b/apps/server/src/routes/api/print.ts
index fff79a66c5..844769d564 100644
--- a/apps/server/src/routes/api/print.ts
+++ b/apps/server/src/routes/api/print.ts
@@ -1,7 +1,14 @@
-import { Request } from "express";
+import { Request, Response } from "express";
+import assetPath from "../../services/asset_path";
+import app_path from "../../services/app_path";
+import { getCurrentLocale } from "../../services/i18n";
-export function getPrintablePage(req: Request) {
+export function getPrintablePage(req: Request, res: Response) {
const { noteId } = req.params;
- return "Hello world: " + noteId;
+ res.render("print", {
+ assetPath: assetPath,
+ appPath: app_path,
+ currentLocale: getCurrentLocale()
+ });
}
diff --git a/apps/server/src/routes/routes.ts b/apps/server/src/routes/routes.ts
index b4e73cf3ef..a76810feb1 100644
--- a/apps/server/src/routes/routes.ts
+++ b/apps/server/src/routes/routes.ts
@@ -388,7 +388,7 @@ function register(app: express.Application) {
apiDocsRoute(app);
// Printing route
- apiRoute(GET, "/print/:noteId", getPrintablePage);
+ route(GET, "/print/:noteId", [ auth.checkAuth ], getPrintablePage);
app.use("", router);
}