Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(share): give a shared collection view the page to itself
Elian Doran9aeed223804b
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.htmlindex dda6fc6728..add4219449 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@@ -104,7 +104,7 @@and <code>children</code> (when it has no excerpt, its first ten visiblechildren, 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,- and with <code>#hideChildrenOverview</code>.</td>+ for a calendar or a geo map, and with <code>#hideChildrenOverview</code>.</td></tr><tr><td><code>childLinksLayout</code>@@ -116,7 +116,8 @@<td><code>prevNext</code></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>.</td>+ 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></tr><tr><td><code>language</code>@@ -129,7 +130,14 @@<td><code>lastUpdated</code></td><td>When the note was last changed, as <code>iso</code> for a <code><time></code> element- and as <code>text</code> in the application's language, or <code>null</code>.</td>+ 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>+ </tr>+ <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></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.mdindex 97473ecac8..0ccd25ecda 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@@ -34,11 +34,12 @@ Your template is rendered with a context object exposing the note and its render| `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, and with `#hideChildrenOverview`. |+| `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`. || `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`. |+| `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`. |+| `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. || `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/templates/page.ejs b/packages/share-theme/src/templates/page.ejsindex ce3d274674..abfcfc67f1 100644--- a/packages/share-theme/src/templates/page.ejs+++ b/packages/share-theme/src/templates/page.ejs@@ -73,7 +73,9 @@<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) { %><h1 id="title"><%= note.title %></h1>+ <% } %><% if (isEmpty && !childLinks.length && note.type !== "book") { %><p><%= t("share_page.no-content") %></p><% } else { %>@@ -116,7 +118,7 @@</div><% } %>- <% if (navigation.length) { %>+ <% if (navigation.length && (prevNext.previous || prevNext.next)) { %><%- include("prev_next") %><% } %>diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.tsindex d7b4280fe0..d9cf4e7ceb 100644--- a/packages/trilium-core/src/share/content_renderer.spec.ts+++ b/packages/trilium-core/src/share/content_renderer.spec.ts@@ -1504,6 +1504,7 @@ describe("content_renderer", () => {contentClasses: getContentClasses(note, isEmpty),language: { page: { lang: "en", dir: "ltr" }, content: null },lastUpdated: null,+ showTitle: true,headings: [],toc: [],isPageInNavigation: falsediff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.tsindex 1cc5fe1507..efa6c51306 100644--- a/packages/trilium-core/src/share/content_renderer.ts+++ b/packages/trilium-core/src/share/content_renderer.ts@@ -59,6 +59,11 @@ 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 is a collection view, such as a map, which takes the page+ * without the title, the subpages, the date and the links to the neighboring pages.+ */+ isCollectionView?: boolean;}interface Subroot {@@ -237,7 +242,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 } = getContent(note, {+ const { header, content, isEmpty, isCollectionView } = getContent(note, {expandNestedEmbeds: renderArgs.isStatic,canAccessEmbed: renderArgs.canAccessEmbed});@@ -253,7 +258,7 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)sanitizeUrl: sanitize.sanitizeUrl,iconPackPrefixes: renderArgs.iconPackSupportedPrefixes});- const childLinks = getChildLinks(note, {+ const childLinks = isCollectionView ? [] : getChildLinks(note, {sanitizeUrl: sanitize.sanitizeUrl,iconPackPrefixes: renderArgs.iconPackSupportedPrefixes,getText: (child) => getExcerptSource(child as SNote | BNote),@@ -275,7 +280,7 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)head: getPageHead(note, siteRoot),snippets: getHtmlSnippets(note),logo,- prevNext: getPrevNextLinks(note, siteRoot),+ prevNext: isCollectionView ? { previous: null, next: null } : getPrevNextLinks(note, siteRoot),navigation,childLinks,childLinksLayout: getChildLinksLayout(note),@@ -284,7 +289,8 @@ function renderNoteContentInternal(note: SNote | BNote, renderArgs: RenderArgs)displayLanguage,defaultContentLanguage: options.getOptionOrNull("defaultContentLanguage")}),- lastUpdated: getLastUpdated(note, displayLanguage),+ lastUpdated: isCollectionView ? null : getLastUpdated(note, displayLanguage),+ showTitle: !isCollectionView,fontPreloads: getFontPreloads(renderArgs.iconPackFonts, [logo.icon,...getNavigationIcons(navigation),@@ -907,6 +913,7 @@ function getViewType(note: SNote) {*/function renderCalendar(result: Result, note: SNote) {const payload = JSON.stringify(buildFrocaPayload(note)).replace(/</g, "\\u003c");+ result.isCollectionView = true;result.content = `<div class="share-calendar" data-note-id="${note.noteId}"></div>`+ `<script type="application/json" class="share-froca">${payload}</script>`;}@@ -922,6 +929,7 @@ function renderGeoMap(result: Result, note: SNote) {options: Object.fromEntries(SHARED_OPTIONS.map((name) => [ name, options.getOptionOrNull(name) ]))};const json = JSON.stringify(payload).replace(/</g, "\\u003c");+ result.isCollectionView = true;result.content = `<div class="share-geomap" data-note-id="${note.noteId}"></div>`+ `<script type="application/json" class="share-froca">${json}</script>`;}