From 465468a5a3ffb497482975bbe49e2f60ef13a056 Mon Sep 17 00:00:00 2001 From: Zerebos Date: Thu, 6 Jun 2024 12:20:36 -0400 Subject: [PATCH] Add more customization in template --- package.json | 2 +- src/templates/page.ejs | 77 ++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 11e67e8db..960cb2cfe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "trilium.rocks", - "version": "1.0.1", + "version": "1.0.2", "description": "", "main": "index.js", "scripts": { diff --git a/src/templates/page.ejs b/src/templates/page.ejs index 30ecaf442..2acf5cb9f 100644 --- a/src/templates/page.ejs +++ b/src/templates/page.ejs @@ -2,22 +2,14 @@ - <% if (note.hasLabel("shareDescription")) { %> - "> - <% } %> - - <% if (note.hasRelation("shareFavicon")) { %> - /download"> - <% } else { %> - - <% } %> + + api/notes/<%= note.getRelation("shareFavicon").value %>/download<% } else { %>../favicon.ico<% } %>"> - <% if (!note.hasLabel("shareOmitDefaultCss")) { %> - - - <% } %> + + <% if (note.hasLabel("shareSwagger")) { %> + <% } %> - <% if (note.type === 'text' || note.type === 'book') { %> + + <% if (note.type === "text" || note.type === "book") { %> <% } %> <% for (const cssRelation of note.getRelations("shareCss")) { %> @@ -60,31 +53,44 @@ const customServerYml = `- url: "{protocol}://{domain}:{port}/etapi" <% for (const jsRelation of note.getRelations("shareJs")) { %> <% } %> - <% if (note.hasLabel('shareDisallowRobotIndexing')) { %> + <% if (note.hasLabel("shareDisallowRobotIndexing")) { %> <% } %> - <%- header %> - <%= note.title %><% if (note.noteId !== subRoot.note.noteId) { %> - <%= subRoot.note.title %><% } %> + + <% + const pageTitle = `${note.title}${note.noteId !== subRoot.note.noteId ? ` - ${subRoot.note.title}` : ""}`; + // Setup some key OpenGraph variables + const openGraphColor = subRoot.note.getLabelValue("shareOpenGraphColor"); + const openGraphURL = subRoot.note.getLabelValue("shareOpenGraphURL"); + const openGraphDomain = subRoot.note.getLabelValue("shareOpenGraphDomain"); + let openGraphImage = subRoot.note.getLabelValue("shareOpenGraphImage"); + // Relation takes priority and requires some altering + if (subRoot.note.hasRelation("shareOpenGraphImage")) { + openGraphImage = `api/images/${subRoot.note.getRelation("shareOpenGraphImage").value}/download`; + } + %> + <%= pageTitle %> - + "> - + - + "> - + - - - + + + "> - + - + <% +const shareRootLink = subRoot.note.hasLabel("shareRootLink") ? subRoot.note.getLabelValue("shareRootLink") : `./${subRoot.note.noteId}`; const currentTheme = note.getLabel("shareTheme") === "light" ? "light" : "dark"; const themeClass = currentTheme === "light" ? " theme-light" : " theme-dark"; const headingRe = /()(.+?)(<\/h[1-6]>)/g; @@ -97,10 +103,9 @@ content = content.replaceAll(headingRe, (...match) => { %>
- - + <% if (subRoot.note.hasRelation("shareLogo")) { %> - /logo.svg" alt="Logo" /> + /download" alt="Logo" /> <% } %> <%= subRoot.note.title %> @@ -110,9 +115,9 @@ content = content.replaceAll(headingRe, (...match) => {
@@ -140,7 +145,7 @@ content = content.replaceAll(headingRe, (...match) => {
-
+
ck-content<% } %><% if (isEmpty) { %> no-content<% } %>">

<%= note.title %>

<% if (isEmpty && (!note.hasVisibleChildren() && note.type !== "book")) { %>

This note has no content.

@@ -159,8 +164,8 @@ content = content.replaceAll(headingRe, (...match) => { <% const action = note.type === "book" ? "getChildNotes" : "getVisibleChildNotes"; for (const childNote of note[action]()) { - const isExternalLink = childNote.hasLabel("shareExternal"); - const linkHref = isExternalLink ? childNote.getLabelValue("shareExternal") : `./${childNote.shareId}`; + const isExternalLink = childNote.hasLabel("shareExternal") || childNote.hasLabel("shareExternalLink"); + const linkHref = isExternalLink ? childNote.getLabelValue("shareExternal") ?? childNote.getLabelValue("shareExternalLink") : `./${childNote.shareId}`; const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : ""; %>
  • @@ -200,7 +205,7 @@ content = content.replaceAll(headingRe, (...match) => {

    On This Page

      <% for (const entry of toc) { %> - <%- include('toc_item', {entry}) %> + <%- include("toc_item", {entry}) %> <% } %>