Skip to content

Build your personal knowledge base with Trilium Notes

add shareHTML relation

Kevin Leutzingerd483b6e8401c
diff --git a/apps/server/src/services/builtin_attributes.ts b/apps/server/src/services/builtin_attributes.ts
index 2d35992aaa..ca48f3df1b 100644
--- a/apps/server/src/services/builtin_attributes.ts
+++ b/apps/server/src/services/builtin_attributes.ts
@@ -66,6 +66,7 @@ export default [
{ type: "label", name: "shareDisallowRobotIndexing" },
{ type: "label", name: "shareCredentials" },
{ type: "label", name: "shareIndex" },
+ { type: "label", name: "shareHTMLLocation" },
{ type: "label", name: "displayRelations" },
{ type: "label", name: "hideRelations" },
{ type: "label", name: "titleTemplate", isDangerous: true },
@@ -105,6 +106,7 @@ export default [
{ type: "relation", name: "renderNote", isDangerous: true },
{ type: "relation", name: "shareCss" },
{ type: "relation", name: "shareJs" },
+ { type: "relation", name: "shareHTML" },
{ type: "relation", name: "shareTemplate" },
{ type: "relation", name: "shareFavicon" }
];
diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejs
index e4ac1f6030..eaa7dbe3bc 100644
--- a/packages/share-theme/src/templates/page.ejs
+++ b/packages/share-theme/src/templates/page.ejs
@@ -1,7 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
- <% const hasTree = subRoot.note.hasVisibleChildren(); %>
+ <%
+ const hasTree = subRoot.note.hasVisibleChildren();
+
+ // Collect HTML snippets by location
+ const htmlSnippetsByLocation = {};
+ for (const htmlRelation of note.getRelations("shareHTML")) {
+ const htmlNote = htmlRelation.targetNote;
+ if (htmlNote) {
+ let location = htmlNote.getLabelValue("shareHTMLLocation") || "content:end";
+ // Default to :end if no position specified
+ if (!location.includes(":")) {
+ location = location + ":end";
+ }
+ if (!htmlSnippetsByLocation[location]) {
+ htmlSnippetsByLocation[location] = [];
+ }
+ htmlSnippetsByLocation[location].push(htmlNote.getContent());
+ }
+ }
+ const renderSnippets = (location) => {
+ const snippets = htmlSnippetsByLocation[location];
+ return snippets ? snippets.join("\n") : "";
+ };
+ %>
+ <%- renderSnippets("head:start") %>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -53,6 +77,7 @@
<meta name="twitter:image" content="<%= openGraphImage %>">
<!-- Meta Tags Generated via https://opengraph.dev -->
<meta name="theme-color" content="<%= openGraphColor %>">
+ <%- renderSnippets("head:end") %>
</head>
<%
const customLogoId = subRoot.note.getRelation("shareLogo")?.value;
@@ -72,6 +97,7 @@ content = content.replaceAll(headingRe, (...match) => {
});
%>
<body data-note-id="<%= note.noteId %>" class="type-<%= note.type %><%= themeClass %>" data-ancestor-note-id="<%= subRoot.note.noteId %>">
+<%- renderSnippets("body:start") %>
<div id="mobile-header">
<a href="<%= shareRootLink %>">
<img src="<%= logoUrl %>" width="32" height="<%= mobileLogoHeight %>" alt="Logo" />
@@ -121,8 +147,8 @@ content = content.replaceAll(headingRe, (...match) => {
</div>
<div id="right-pane">
<div id="main">
-
<div id="content" class="type-<%= note.type %><% if (note.type === "text") { %> ck-content<% } %><% if (isEmpty) { %> no-content<% } %>">
+ <%- renderSnippets("content:start") %>
<h1 id="title"><%= note.title %></h1>
<% if (isEmpty && (!note.hasVisibleChildren() && note.type !== "book")) { %>
<p>This note has no content.</p>
@@ -132,6 +158,7 @@ content = content.replaceAll(headingRe, (...match) => {
%>
<%- content %>
<% } %>
+ <%- renderSnippets("content:end") %>
</div>
<% if (note.hasVisibleChildren() || note.type === "book") { %>
@@ -164,7 +191,7 @@ content = content.replaceAll(headingRe, (...match) => {
</div>
<% } %>
- <% if (hasTree) { %>
+ <% if (hasTree) { %>
<%- include("prev_next", { note: note, subRoot: subRoot }) %>
<% } %>
</footer>
@@ -205,5 +232,6 @@ content = content.replaceAll(headingRe, (...match) => {
<% } %>
</div>
</div>
+<%- renderSnippets("body:end") %>
</body>
</html>