Skip to content

Build your personal knowledge base with Trilium Notes

feat(share): give full-height notes the app view's title row and page

Elian Doran4f84d6578b8a
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 4922238959..8b492e7956 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
@@ -92,8 +92,9 @@
<td><code>contentClasses</code>
</td>
<td>The classes of the content element: <code>type-&lt;note type&gt;</code>, <code>ck-content</code> for
- text and Markdown notes, and <code>no-content</code> when the note has no
- content of its own.</td>
+ text and Markdown notes, <code>full-height</code> for a note that takes the
+ whole page (such as a PDF, a web view, a calendar, a geo map or an image),
+ and <code>no-content</code> when the note has no content of its own.</td>
</tr>
<tr>
<td><code>childLinks</code>
@@ -104,7 +105,7 @@
and <code>children</code> (when it has no excerpt, its first ten visible
children, each with <code>title</code>, <code>href</code>, <code>isExternal</code> and <code>icon</code>).
Empty for a note that is not a collection, a text note or a code note,
- for a calendar or a geo map, and with <code>#hideChildrenOverview</code>.</td>
+ for a note that takes the whole page, and with <code>#hideChildrenOverview</code>.</td>
</tr>
<tr>
<td><code>childLinksLayout</code>
@@ -117,7 +118,7 @@
</td>
<td>The pages before and after the note in the navigation tree, as <code>previous</code> and <code>next</code>,
each with <code>title</code> and <code>href</code>, or <code>null</code>. Both <code>null</code> for
- a calendar or a geo map.</td>
+ a note that takes the whole page.</td>
</tr>
<tr>
<td><code>language</code>
@@ -131,7 +132,7 @@
</td>
<td>When the note was last changed, as <code>iso</code> for a <code>&lt;time&gt;</code> element
and as <code>text</code> in the application's language, or <code>null</code>,
- which it also is for a calendar or a geo map.</td>
+ which it also is for a note that takes the whole page.</td>
</tr>
<tr>
<td><code>showTitle</code>
@@ -143,8 +144,8 @@
<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>
+ the title in a row of its own for a note that takes the whole page; <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 4b33604802..6efabf7a5d 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
@@ -33,14 +33,14 @@ Your template is rendered with a context object exposing the note and its render
| `head` | The values of the page's `<head>`: `title` (the note's title, followed by the site's), `description` (`#shareDescription`), `noIndex` (`#shareDisallowRobotIndexing`) and `openGraph` with `url`, `domain`, `image`, `color` and `card` (`summary_large_image` with an image, `summary` without). A value whose label is not set is `null`. `metaTags` lists the description, OpenGraph and Twitter `<meta>` tags of the values that are set, each with `attribute` (`name` or `property`), `key` and `content`. |
| `logo` | The site logo above the navigation tree and, on a narrow screen, in the header: `href` (`#shareRootLink`, otherwise the site's root page), `image` (the `~shareLogo` image, or `null`), `icon` (the icon classes of the site's root note, shown when there is no `image`), and `width` and `height` for the image. |
| `navigation` | The navigation tree of the site: its visible pages, each with `title`, `href`, `isExternal`, `type`, `icon`, `isActive` (the page being shown), `isExpanded` (that page or one of its ancestors) and `children`. |
-| `contentClasses` | The classes of the content element: `type-<note type>`, `ck-content` for text and Markdown notes, and `no-content` when the note has no content of its own. |
-| `childLinks` | The links to the note's visible children, each with `title`, `href`, `isExternal`, `type`, `icon` (its icon classes), `excerpt` (its `#shareDescription` or the start of its text, with a line break between paragraphs, or `null`) and `children` (when it has no excerpt, its first ten visible children, each with `title`, `href`, `isExternal` and `icon`). Empty for a note that is not a collection, a text note or a code note, for a calendar or a geo map, and with `#hideChildrenOverview`. |
+| `contentClasses` | The classes of the content element: `type-<note type>`, `ck-content` for text and Markdown notes, `full-height` for a note that takes the whole page (such as a PDF, a web view, a calendar, a geo map or an image), and `no-content` when the note has no content of its own. |
+| `childLinks` | The links to the note's visible children, each with `title`, `href`, `isExternal`, `type`, `icon` (its icon classes), `excerpt` (its `#shareDescription` or the start of its text, with a line break between paragraphs, or `null`) and `children` (when it has no excerpt, its first ten visible children, each with `title`, `href`, `isExternal` and `icon`). Empty for a note that is not a collection, a text note or a code note, for a note that takes the whole page, and with `#hideChildrenOverview`. |
| `childLinksLayout` | How the default template lays `childLinks` out: `list` for a collection whose view type is list, `grid` otherwise. |
-| `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. |
+| `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 note that takes the whole page. |
| `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. |
+| `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 note that takes 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. |
+| `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; `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/content/app_view.css b/packages/share-theme/src/content/app_view.css
index ff903a4064..4d2a00fe9e 100644
--- a/packages/share-theme/src/content/app_view.css
+++ b/packages/share-theme/src/content/app_view.css
@@ -1,85 +1,20 @@
-body:has(#content.app-view) {
- #right-pane {
- height: 100vh;
- }
-
- #main {
- display: flex;
- flex-direction: column;
- height: 100%;
- padding: 0;
- }
-
- #content {
- display: flex;
- flex-direction: column;
+#content.app-view > :is(.share-collection, .share-note-view) {
+ position: relative;
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-height: 0;
+ justify-content: center;
+
+ > * {
flex: 1;
min-height: 0;
}
- #content-footer {
- margin-top: 0;
- }
-
- #title-row {
- display: flex;
- flex: none;
- gap: 12px;
- align-items: center;
- padding: 12px 20px;
- border-bottom: 1px solid var(--main-border-color);
-
- > .tn-icon {
- display: flex;
- flex-shrink: 0;
- align-items: center;
- justify-content: center;
- 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;
- border-bottom: 0;
- font-size: 1.5rem;
- font-weight: 400;
- line-height: 1;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- }
-
- #content > :is(.share-collection, .share-note-view) {
- position: relative;
- display: flex;
- flex-direction: column;
- flex: 1;
- min-height: 0;
-
- justify-content: center;
-
- > * {
- flex: 1;
- min-height: 0;
- }
-
- > img {
- flex: 0 1 auto;
- align-self: center;
- object-fit: contain;
- }
- }
-
- @media (max-width: 48em) {
- #right-pane {
- height: calc(100dvh - var(--header-height));
- }
+ > img {
+ flex: 0 1 auto;
+ align-self: center;
+ object-fit: contain;
}
}
diff --git a/packages/share-theme/src/content/content.css b/packages/share-theme/src/content/content.css
index 33f46ac522..30e1841842 100644
--- a/packages/share-theme/src/content/content.css
+++ b/packages/share-theme/src/content/content.css
@@ -227,39 +227,6 @@ body:not(.math-loaded) .math-tex {
visibility: hidden;
}
-body.type-webView {
- #right-pane {
- height: 100vh;
- }
-
- #main {
- padding: 0;
- height: 100%;
- }
-
- #content {
- display: flex;
- flex-direction: column;
- height: 100%;
-
- h1 {
- display: none;
- }
-
- iframe.webview {
- width: 100%;
- flex-grow: 1;
- border: 0;
- }
- }
-
- @media (max-width: 48em) {
- #right-pane {
- height: calc(100dvh - var(--header-height));
- }
- }
-}
-
/* The tables of the app, which draws them with `ckeditor5-content.css`: Bootstrap's `.table` class
stretches the `<figure>` to the content's width, and `style.css` centers the cells vertically. A
resized table keeps the width the figure carries in its `style`. */
diff --git a/packages/share-theme/src/content/full_height.css b/packages/share-theme/src/content/full_height.css
new file mode 100644
index 0000000000..2d2843ffed
--- /dev/null
+++ b/packages/share-theme/src/content/full_height.css
@@ -0,0 +1,71 @@
+body:has(#content.full-height) {
+ #right-pane {
+ height: 100vh;
+ }
+
+ #main {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ padding: 0;
+ }
+
+ #content {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-height: 0;
+ }
+
+ #content-footer {
+ margin-top: 0;
+ }
+
+ #title-row {
+ display: flex;
+ flex: none;
+ gap: 12px;
+ align-items: center;
+ padding: 12px 20px;
+ border-bottom: 1px solid var(--main-border-color);
+
+ > .tn-icon {
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
+ 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;
+ border-bottom: 0;
+ font-size: 1.5rem;
+ font-weight: 400;
+ line-height: 1;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ }
+ }
+
+ #content > iframe {
+ flex: 1;
+ width: 100%;
+ height: auto;
+ min-height: 0;
+ border: 0;
+ }
+
+ @media (max-width: 48em) {
+ #right-pane {
+ height: calc(100dvh - var(--header-height));
+ }
+ }
+}
diff --git a/packages/share-theme/src/index.ts b/packages/share-theme/src/index.ts
index 674bad428b..c6c5789ae5 100644
--- a/packages/share-theme/src/index.ts
+++ b/packages/share-theme/src/index.ts
@@ -16,6 +16,7 @@ import "./content/external_links.css";
import "./content/task_states.css";
import "./content/adaptive_colors.css";
import "./content/link_embed.css";
+import "./content/full_height.css";
import "./content/app_view.css";
import setupMath from "./content/math.js";
import setupAppView from "./content/app_view.js";
diff --git a/packages/share-theme/src/model/page.spec.ts b/packages/share-theme/src/model/page.spec.ts
index 54c55eebbb..6088e58e29 100644
--- a/packages/share-theme/src/model/page.spec.ts
+++ b/packages/share-theme/src/model/page.spec.ts
@@ -437,9 +437,12 @@ describe("getContentClasses", () => {
.toBe("type-file full-content-width");
});
- it("gives an app view the full width", () => {
- expect(getContentClasses(fakeNote({ noteId: "map", type: "book" }), false, true))
- .toBe("type-book full-content-width app-view");
+ it("gives full-height content and app views the full width", () => {
+ expect(getContentClasses(fakeNote({ noteId: "site", type: "webView" }), false, { isFullHeight: true }))
+ .toBe("type-webView full-content-width full-height");
+ const map = fakeNote({ noteId: "map", type: "book" });
+ expect(getContentClasses(map, false, { isAppView: true, isFullHeight: true }))
+ .toBe("type-book full-content-width full-height app-view");
});
});
diff --git a/packages/share-theme/src/model/page.ts b/packages/share-theme/src/model/page.ts
index 8a7253b35c..56fade090a 100644
--- a/packages/share-theme/src/model/page.ts
+++ b/packages/share-theme/src/model/page.ts
@@ -340,18 +340,25 @@ export function getShareLink(note: ShareNote, sanitizeUrl: (url: string) => stri
/**
* Returns the classes of the content element: the note's type, `ck-content` for content the text
* editor's styles apply to (text notes and Markdown code notes), `full-content-width` for a note
- * with `#fullContentWidth` or of a type the app always shows at full width, and `no-content` when
- * empty. A Markdown note reads as text, so its type does not make it full width.
+ * with `#fullContentWidth`, of a type the app always shows at full width or taking the page's full
+ * height, `full-height` and `app-view` for content that takes the page's full height and for an
+ * app view, and `no-content` when empty. A Markdown note reads as text, so its type does not make it
+ * full width.
*/
-export function getContentClasses(note: ShareNote, isEmpty = false, isAppView = false) {
+export function getContentClasses(
+ note: ShareNote,
+ isEmpty = false,
+ { isAppView = false, isFullHeight = false }: { isAppView?: boolean; isFullHeight?: boolean } = {}
+) {
const isEditorContent = note.type === "text"
|| (note.type === "code" && note.mime === "text/x-markdown");
const isFullWidth = (!isEditorContent && isFullWidthNoteType(note.type, note.mime))
- || note.isLabelTruthy("fullContentWidth") || isAppView;
+ || note.isLabelTruthy("fullContentWidth") || isFullHeight;
return [
`type-${note.type}`,
isEditorContent && "ck-content",
isFullWidth && "full-content-width",
+ isFullHeight && "full-height",
isAppView && "app-view",
isEmpty && "no-content"
].filter(Boolean).join(" ");
diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.ts
index bef1192e1e..b385c5e8a7 100644
--- a/packages/trilium-core/src/share/content_renderer.spec.ts
+++ b/packages/trilium-core/src/share/content_renderer.spec.ts
@@ -1716,7 +1716,7 @@ 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", () => {
+ it("titles full-height content 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"
}))));
@@ -1724,6 +1724,13 @@ describe("content_renderer pages", () => {
.toBe(true);
expect(appPage.querySelector("#title-row > h1#title")?.textContent).toBe("A <picture>");
+ const pdfPage = parse(String(renderNoteContent(buildSitePage({
+ type: "file", mime: "application/pdf", title: "Manual", content: ""
+ }))));
+ expect(pdfPage.querySelector("#content")?.classList.contains("full-height")).toBe(true);
+ expect(pdfPage.querySelector("#content")?.classList.contains("app-view")).toBe(false);
+ expect(pdfPage.querySelector("#title-row > h1#title")?.textContent).toBe("Manual");
+
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);
diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.ts
index b8bdfc71dd..9d2c90917a 100644
--- a/packages/trilium-core/src/share/content_renderer.ts
+++ b/packages/trilium-core/src/share/content_renderer.ts
@@ -59,10 +59,15 @@ export interface Result {
content: string | Uint8Array | undefined;
/** Set to `true` if the provided content should be rendered as empty. */
isEmpty?: boolean;
+ /**
+ * Set to `true` if the content takes the page's full height, such as a PDF, a web view or an
+ * app view, below a title row like the app's and without the subpages, the date and the links
+ * to the neighboring pages.
+ */
+ isFullHeight?: 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 below a title row like the app's, without the subpages, the
- * date and the links to the neighboring pages.
+ * an image. An app view also takes the page's full height.
*/
isAppView?: boolean;
}
@@ -243,7 +248,7 @@ interface IconPackFont {
function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs) {
// Static export preserves full embed nesting; the live share view renders only the first level.
- const { header, content, isEmpty, isAppView } = getContent(note, {
+ const { header, content, isEmpty, isAppView, isFullHeight } = getContent(note, {
expandNestedEmbeds: renderArgs.isStatic,
canAccessEmbed: renderArgs.canAccessEmbed
});
@@ -259,14 +264,14 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
sanitizeUrl: sanitize.sanitizeUrl,
iconPackPrefixes: renderArgs.iconPackSupportedPrefixes
});
- const childLinks = isAppView ? [] : getChildLinks(note, {
+ const childLinks = isFullHeight ? [] : getChildLinks(note, {
sanitizeUrl: sanitize.sanitizeUrl,
iconPackPrefixes: renderArgs.iconPackSupportedPrefixes,
getText: (child) => getExcerptSource(child as SNote | BNote),
// `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 titleIcon = isFullHeight ? note.getIcon(renderArgs.iconPackSupportedPrefixes) : null;
const opts = {
note,
header,
@@ -282,16 +287,16 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)
head: getPageHead(note, siteRoot),
snippets: getHtmlSnippets(note),
logo,
- prevNext: isAppView ? { previous: null, next: null } : getPrevNextLinks(note, siteRoot),
+ prevNext: isFullHeight ? { previous: null, next: null } : getPrevNextLinks(note, siteRoot),
navigation,
childLinks,
childLinksLayout: getChildLinksLayout(note),
- contentClasses: getContentClasses(note, isEmpty, isAppView),
+ contentClasses: getContentClasses(note, isEmpty, { isAppView, isFullHeight }),
language: getPageLanguages(note, {
displayLanguage,
defaultContentLanguage: options.getOptionOrNull("defaultContentLanguage")
}),
- lastUpdated: isAppView ? null : getLastUpdated(note, displayLanguage),
+ lastUpdated: isFullHeight ? null : getLastUpdated(note, displayLanguage),
showTitle: true,
titleIcon,
fontPreloads: getFontPreloads(renderArgs.iconPackFonts, [
@@ -945,6 +950,7 @@ function hostInAppView(result: Result, note: SNote, container: string) {
};
const json = JSON.stringify(payload).replace(/</g, "\\u003c");
result.isAppView = true;
+ result.isFullHeight = true;
const content = String(result.content ?? "");
result.content = `<div class="${container}" data-note-id="${note.noteId}">${content}</div>`
+ `<script type="application/json" class="share-froca">${json}</script>`;
@@ -979,6 +985,7 @@ function renderImage(result: Result, note: SNote | BNote) {
function renderFile(note: SNote | BNote, result: Result) {
if (note.mime === "application/pdf") {
result.content = `<iframe class="pdf-view" src="api/notes/${note.noteId}/view"></iframe>`;
+ result.isFullHeight = true;
} else {
result.content = `<button type="button" onclick="location.href='api/notes/${note.noteId}/download'">Download file</button>`;
}
@@ -1015,6 +1022,7 @@ function renderWebView(note: SNote | BNote, result: Result) {
// embedding it; only dropping allow-same-origin would isolate it.
frame.setAttribute("sandbox", "allow-same-origin allow-scripts allow-popups");
result.content = frame.toString();
+ result.isFullHeight = true;
}
/**