chore(share): integrate root template

This commit is contained in:
Elian Doran 2025-06-08 22:57:24 +03:00
parent 8e27d877a1
commit 881a015f68
No known key found for this signature in database
6 changed files with 42 additions and 6 deletions

View File

@ -236,7 +236,8 @@
], ],
"esbuildOptions": { "esbuildOptions": {
"loader": { "loader": {
".css": "text" ".css": "text",
".ejs": "text"
} }
}, },
"declarationRootDir": "apps/server/src" "declarationRootDir": "apps/server/src"
@ -285,7 +286,8 @@
"esbuildOptions": { "esbuildOptions": {
"splitting": false, "splitting": false,
"loader": { "loader": {
".css": "text" ".css": "text",
".ejs": "text"
} }
}, },
"additionalEntryPoints": [ "additionalEntryPoints": [

View File

@ -17,6 +17,8 @@ import type SAttachment from "./shaca/entities/sattachment.js";
import utils, { isDev, safeExtractMessageAndStackFromError } from "../services/utils.js"; import utils, { isDev, safeExtractMessageAndStackFromError } from "../services/utils.js";
import options from "../services/options.js"; import options from "../services/options.js";
import { t } from "i18next"; import { t } from "i18next";
import shareThemeRoot from "@triliumnext/share-theme/templates/page.ejs";
import ejs from "ejs";
function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } { function getSharedSubTreeRoot(note: SNote): { note?: SNote; branch?: SBranch } {
if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) { if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
@ -136,7 +138,7 @@ function renderImageAttachment(image: SNote, res: Response, attachmentName: stri
} }
function register(router: Router) { function register(router: Router) {
async function renderNote(note: SNote, req: Request, res: Response) { function renderNote(note: SNote, req: Request, res: Response) {
if (!note) { if (!note) {
console.log("Unable to find note ", note); console.log("Unable to find note ", note);
res.status(404).render("share/404"); res.status(404).render("share/404");
@ -197,7 +199,6 @@ function register(router: Router) {
try { try {
const content = templateNote.getContent(); const content = templateNote.getContent();
if (typeof content === "string") { if (typeof content === "string") {
const ejs = await import("ejs");
const ejsResult = ejs.render(content, opts, { includer }); const ejsResult = ejs.render(content, opts, { includer });
res.send(ejsResult); res.send(ejsResult);
useDefaultView = false; // Rendering went okay, don't use default view useDefaultView = false; // Rendering went okay, don't use default view
@ -210,7 +211,14 @@ function register(router: Router) {
} }
if (useDefaultView) { if (useDefaultView) {
res.render("share/page", opts); console.log("Got share theme path", shareThemeRoot);
const ejsResult = ejs.render(shareThemeRoot, opts, {
includer(originalPath, parsedPath: string) {
console.log("Path ", originalPath, parsedPath);
throw new Error("Hi");
}
})
res.send(ejsResult);
} }
} }

View File

@ -27,3 +27,9 @@ declare module "@triliumnext/ckeditor5/content.css" {
const content: string; const content: string;
export default content; export default content;
} }
declare module "@triliumnext/share-theme/*.ejs" {
const content: string;
export default content;
}

View File

@ -37,6 +37,9 @@
{ {
"path": "../../packages/ckeditor5/tsconfig.lib.json" "path": "../../packages/ckeditor5/tsconfig.lib.json"
}, },
{
"path": "../../packages/share-theme"
},
{ {
"path": "../../packages/turndown-plugin-gfm/tsconfig.lib.json" "path": "../../packages/turndown-plugin-gfm/tsconfig.lib.json"
}, },

View File

@ -1,5 +1,5 @@
{ {
"name": "trilium.rocks", "name": "@triliumnext/share-theme",
"version": "1.0.3", "version": "1.0.3",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
@ -12,6 +12,9 @@
"dist": "esrun scripts/build.ts -- --minify", "dist": "esrun scripts/build.ts -- --minify",
"test": "esrun src/scripts/test.ts" "test": "esrun src/scripts/test.ts"
}, },
"exports": {
"./*": "./src/*"
},
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {

14
pnpm-lock.yaml generated
View File

@ -473,6 +473,9 @@ importers:
'@braintree/sanitize-url': '@braintree/sanitize-url':
specifier: 7.1.1 specifier: 7.1.1
version: 7.1.1 version: 7.1.1
'@digitalmaas/esbuild-plugin-ejs':
specifier: 1.0.0
version: 1.0.0(esbuild@0.25.5)
'@electron/remote': '@electron/remote':
specifier: 2.1.2 specifier: 2.1.2
version: 2.1.2(electron@36.4.0) version: 2.1.2(electron@36.4.0)
@ -2326,6 +2329,12 @@ packages:
'@digitak/grubber@3.1.4': '@digitak/grubber@3.1.4':
resolution: {integrity: sha512-pqsnp2BUYlDoTXWG34HWgEJse/Eo1okRgNex8IG84wHrJp8h3SakeR5WhB4VxSA2+/D+frNYJ0ch3yXzsfNDoA==} resolution: {integrity: sha512-pqsnp2BUYlDoTXWG34HWgEJse/Eo1okRgNex8IG84wHrJp8h3SakeR5WhB4VxSA2+/D+frNYJ0ch3yXzsfNDoA==}
'@digitalmaas/esbuild-plugin-ejs@1.0.0':
resolution: {integrity: sha512-R6FHotduWyXExphqMJuv0CK42ZCt5Z+gZATFOXvL/lVHLyRVRdTlZqvKyP6DRCQVGz9ecYpk++AWhRzkNODKwQ==}
engines: {node: '>=14'}
peerDependencies:
esbuild: '>=0.25.0'
'@dual-bundle/import-meta-resolve@4.1.0': '@dual-bundle/import-meta-resolve@4.1.0':
resolution: {integrity: sha512-+nxncfwHM5SgAtrVzgpzJOI1ol0PkumhVo469KCf9lUi21IGcY90G98VuHm9VRrUypmAzawAHO9bs6hqeADaVg==} resolution: {integrity: sha512-+nxncfwHM5SgAtrVzgpzJOI1ol0PkumhVo469KCf9lUi21IGcY90G98VuHm9VRrUypmAzawAHO9bs6hqeADaVg==}
@ -14973,6 +14982,11 @@ snapshots:
'@digitak/grubber@3.1.4': {} '@digitak/grubber@3.1.4': {}
'@digitalmaas/esbuild-plugin-ejs@1.0.0(esbuild@0.25.5)':
dependencies:
ejs: 3.1.10
esbuild: 0.25.5
'@dual-bundle/import-meta-resolve@4.1.0': {} '@dual-bundle/import-meta-resolve@4.1.0': {}
'@electron-forge/cli@7.8.1(encoding@0.1.13)': '@electron-forge/cli@7.8.1(encoding@0.1.13)':