Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): title an app view with a row like the app's

Elian Doran035a114e55f3
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.html
index add4219449..4922238959 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.html
@@ -136,8 +136,15 @@
<tr>
<td><code>showTitle</code>
</td>
- <td>Whether the default template shows the note's title above the content: <code>false</code> for
- a calendar or a geo map, which take the whole page.</td>
+ <td>Whether the default template shows the note's title above the content.
+ Always <code>true</code>.</td>
+ </tr>
+ <tr>
+ <td><code>titleIcon</code>
+ </td>
+ <td>The icon classes of the note, which the default template shows beside
+ the title in a row of its own for a note that takes the whole page, such
+ as a calendar, a geo map or an image; <code>null</code> for any other note.</td>
</tr>
<tr>
<td><code>snippets</code>
diff --git a/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.md b/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.md
index 0ccd25ecda..4b33604802 100644
--- a/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.md
+++ b/docs/User Guide/User Guide/Advanced Usage/Sharing/Custom share template.md
@@ -39,7 +39,8 @@ Your template is rendered with a context object exposing the note and its render
| `prevNext` | The pages before and after the note in the navigation tree, as `previous` and `next`, each with `title` and `href`, or `null`. Both `null` for a calendar or a geo map. |
| `language` | The languages of the page: `page` with the `lang` and `dir` of the application's language, and `content` with those of the note's content language, or `null` when they are the same. |
| `lastUpdated` | When the note was last changed, as `iso` for a `<time>` element and as `text` in the application's language, or `null`, which it also is for a calendar or a geo map. |
-| `showTitle` | Whether the default template shows the note's title above the content: `false` for a calendar or a geo map, which take the whole page. |
+| `showTitle` | Whether the default template shows the note's title above the content. Always `true`. |
+| `titleIcon` | The icon classes of the note, which the default template shows beside the title in a row of its own for a note that takes the whole page, such as a calendar, a geo map or an image; `null` for any other note. |
| `snippets` | The HTML of the `~shareHtml` snippets for each location, such as `snippets["head:end"]`. Every location is present, empty when no snippet goes there. |
| `subRoot` | The root of the shared subtree as `{ note, branch }` — handy for a site-wide title or logo. |
| `cssToLoad` / `jsToLoad` | Arrays of stylesheet / script URLs the default theme would inject (includes anything added via `~shareCss` / `~shareJs`). |
diff --git a/packages/share-theme/src/base.css b/packages/share-theme/src/base.css
index b48e9ab02f..8616ca91a2 100644
--- a/packages/share-theme/src/base.css
+++ b/packages/share-theme/src/base.css
@@ -59,6 +59,8 @@ html.theme-light {
--muted-text-color: #666;
--card-background-color: #0000000d;
--card-background-hover-color: #0000001c;
+ --note-icon-background-color: #4f4f4f;
+ --note-icon-color: white;
/* The content colors of `theme-next-light.css`. */
--accented-background-color: #f5f5f5;
--selection-background-color: #3399FF70;
@@ -122,6 +124,8 @@ html.theme-dark {
--muted-text-color: #bbb;
--card-background-color: #ffffff12;
--card-background-hover-color: #ffffff20;
+ --note-icon-background-color: #444444;
+ --note-icon-color: #d4d4d4;
/* The content colors of `theme-next-dark.css`. */
--accented-background-color: #555;
--selection-background-color: #3399FF70;
diff --git a/packages/share-theme/src/content/app_view.css b/packages/share-theme/src/content/app_view.css
index 4ec411cd5d..ff903a4064 100644
--- a/packages/share-theme/src/content/app_view.css
+++ b/packages/share-theme/src/content/app_view.css
@@ -24,8 +24,9 @@ body:has(#content.app-view) {
#title-row {
display: flex;
flex: none;
+ gap: 12px;
align-items: center;
- height: 50px;
+ padding: 12px 20px;
border-bottom: 1px solid var(--main-border-color);
> .tn-icon {
@@ -33,17 +34,20 @@ body:has(#content.app-view) {
flex-shrink: 0;
align-items: center;
justify-content: center;
- width: 50px;
- height: 50px;
- font-size: 30px;
- color: var(--muted-text-color);
+ width: 40px;
+ height: 40px;
+ border-radius: 50%;
+ background: var(--note-icon-background-color);
+ color: var(--note-icon-color);
+ font-size: 22px;
}
> #title {
min-width: 0;
margin: 0;
- padding-inline: 12px;
border-bottom: 0;
+ font-size: 1.5rem;
+ font-weight: 400;
line-height: 1;
overflow: hidden;
white-space: nowrap;
diff --git a/packages/share-theme/src/templates/page.ejs b/packages/share-theme/src/templates/page.ejs
index abfcfc67f1..472b49d1fd 100644
--- a/packages/share-theme/src/templates/page.ejs
+++ b/packages/share-theme/src/templates/page.ejs
@@ -73,7 +73,12 @@
<div id="main">
<div id="content" class="<%= contentClasses %>"<% if (language.content) { %> lang="<%= language.content.lang %>" dir="<%= language.content.dir %>"<% } %> data-tab-title-placeholder="<%= t("share_theme.tab-title") %>">
<%- snippets["content:start"] %>
- <% if (showTitle) { %>
+ <% if (showTitle && titleIcon) { %>
+ <div id="title-row">
+ <span class="tn-icon <%= titleIcon %>" aria-hidden="true"></span>
+ <h1 id="title"><%= note.title %></h1>
+ </div>
+ <% } else if (showTitle) { %>
<h1 id="title"><%= note.title %></h1>
<% } %>
<% if (isEmpty && !childLinks.length && note.type !== "book") { %>
diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.ts
index d6af1218cd..b411a55883 100644
--- a/packages/trilium-core/src/share/content_renderer.spec.ts
+++ b/packages/trilium-core/src/share/content_renderer.spec.ts
@@ -1513,6 +1513,7 @@ describe("content_renderer", () => {
language: { page: { lang: "en", dir: "ltr" }, content: null },
lastUpdated: null,
showTitle: true,
+ titleIcon: null,
headings: [],
toc: [],
isPageInNavigation: false
@@ -1717,6 +1718,19 @@ describe("content_renderer pages", () => {
.toBe(`<p>${t("content_renderer.note-cannot-be-displayed")}</p>`);
});
+ it("titles an app view with its icon in a row of its own, and other pages with a heading", () => {
+ const appPage = parse(String(renderNoteContent(buildSitePage({
+ type: "image", title: "A <picture>", content: "", "#iconClass": "bx bx-rocket"
+ }))));
+ expect(appPage.querySelector("#content > #title-row > .tn-icon")?.classList.contains("bx-rocket"))
+ .toBe(true);
+ expect(appPage.querySelector("#title-row > h1#title")?.textContent).toBe("A <picture>");
+
+ const textPage = parse(String(renderNoteContent(buildSitePage({ content: "<p>a</p>" }))));
+ expect(textPage.querySelector("#title-row") === null).toBe(true);
+ expect(textPage.querySelector("#content > h1#title") === null).toBe(false);
+ });
+
it("leaves content that is not text as it is, and empty text as empty", () => {
const binary = Buffer.from("<p>x</p>");
for (const type of [ "text", "mermaid", "code" ]) {
diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.ts
index b5a4f623dd..c96ea2325c 100644
--- a/packages/trilium-core/src/share/content_renderer.ts
+++ b/packages/trilium-core/src/share/content_renderer.ts
@@ -61,8 +61,8 @@ export interface Result {
isEmpty?: boolean;
/**
* Set to `true` if the content is shown with the app's own view, such as a map or the viewer of
- * an image, which takes the page without the title, the subpages, the date and the links to the
- * neighboring pages.
+ * an image, which takes the page below a title row like the app's, without the subpages, the
+ * date and the links to the neighboring pages.
*/
isAppView?: boolean;
}
@@ -266,6 +266,7 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
// `canAccessEmbed` is only given with a shaca note, whose children are shaca notes too.
canAccess: (child) => renderArgs.canAccessEmbed?.(child as SNote) !== false
});
+ const titleIcon = isAppView ? note.getIcon(renderArgs.iconPackSupportedPrefixes) : null;
const opts = {
note,
header,
@@ -291,9 +292,11 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
defaultContentLanguage: options.getOptionOrNull("defaultContentLanguage")
}),
lastUpdated: isAppView ? null : getLastUpdated(note, displayLanguage),
- showTitle: !isAppView,
+ showTitle: true,
+ titleIcon,
fontPreloads: getFontPreloads(renderArgs.iconPackFonts, [
logo.icon,
+ ...(titleIcon ? [ titleIcon ] : []),
...getNavigationIcons(navigation),
...childLinks.flatMap((child) => [ child.icon, ...child.children.map((grandchild) => grandchild.icon) ])
]),