Skip to content

Build your personal knowledge base with Trilium Notes

Enable sliding categories and extract TODOs

Zack Rauen5391521c0855
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 0000000000..4abd37e19b
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,29 @@
+# TODOs
+
+This doc contains a list of TODOs taken from the code and organized. This _does not_ includes things like upcoming features or fixes.
+
+## Scripts
+
+- Create a logger
+- Modify esbuild to allow for a development build to contain debug logs
+- Modify custom highlight.js plugin to include highlighting for jQuery global functions
+- Either move highlight.js inclusion to template or use a mapping of note IDs to files
+- Adjust search to use separate function (clean code)
+- Consider never removing the search results from the page and update container instead
+- Consolidate theme initialization (DRY)
+
+## Styles
+
+-
+
+## Templates
+
+- Consider adding highlight.js into the templates instead of scripts
+- Find a better way to integrate ts/js to templates (maybe via includes?)
+
+## Other
+
+- Create a logical set of attributes for setting open-graph/twitter metadata
+- Consider making book type notes explicitly required for full-link category
+ - This lets text type notes still have content but require clicking arrow to expand
+- Find a way to better map template to notes and allow for automatically creating new ones
\ No newline at end of file
diff --git a/src/scripts/index.ts b/src/scripts/index.ts
index b05c31441c..38f0933b16 100644
--- a/src/scripts/index.ts
+++ b/src/scripts/index.ts
@@ -1,30 +1,11 @@
-// import fixActiveLink from "./fixes/activelink";
-// import fixTableHeaders from "./fixes/tableheaders";
import highlight from "./modules/highlight";
-// import buildSidenav from "./navigation/sidenav";
-// import buildBreadcrumbs from "./navigation/breadcrumbs";
-// import fixSubMenus from "./fixes/submenu";
import setupToC from "./modules/toc";
-// import addExternalLinks from "./fixes/externallinks";
-// import injectSwagger from "./other/swagger";
-// import makeMobileMenu from "./other/mobile";
import setupExpanders from "./modules/expanders";
import setupMobileMenu from "./modules/mobile";
import setupSearch from "./modules/search";
import setupThemeSelector from "./modules/theme";
-// const ETAPI_REF_NOTE_ID = "pPIXi0uwF5GX";
-// const HIDDEN_SUBMENUS = ["blog"];
-// const EXTERNAL_LINKS = {
-// EGFtX8Uw96FQ: "https://github.com/zadam/trilium",
-// dXAKFE0fJtom: "https://discord.gg/eTaTXUgcBr"
-// };
-// const ALIASES = {
-// WqBnya4Ye8rS: "",
-// ZapIU17QNEyU: "blog"
-// };
-
function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Parameters<T>) {
try {
func.apply(func, args);
@@ -33,51 +14,9 @@ function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Paramete
console.error(e); // eslint-disable-line no-console
}
}
-
-/**
- * Lots of these functions seem to depend on each other indirectly
- * through DOM changes or classes or what-have-you. This is
- * obviously not ideal as it makes things less clear, and also
- * makes TypeScript less helpful.
- *
- * TODO: Find a good way of restructuring that allows things
- * to act a bit more harmoniously.
- *
- * TODO: Make use of esbuild's define api to enable a debug
- * build that contains all the console logs and such.
- */
-
-// Perform fixes first
-// $try(fixActiveLink, ALIASES);
-// $try(fixTableHeaders);
-// $try(fixSubMenus, HIDDEN_SUBMENUS);
-// $try(addExternalLinks, EXTERNAL_LINKS);
-
-// Now layout changes
-// $try(buildBreadcrumbs);
-// $try(buildSidenav);
-
$try(setupToC);
-
-// Finally, other features
-// TODO: how difficult this would be to implement via
-// templates or trilium
$try(highlight);
-// $try(injectSwagger, ETAPI_REF_NOTE_ID);
-
-// "Standard" Modules I would recommend the new share
-// theme have
$try(setupExpanders);
$try(setupMobileMenu);
$try(setupSearch);
$try(setupThemeSelector);
-// $try(makeMobileMenu);
-
-/**
- * This no longer uses a traefik plugin and instead a custom
- * template being served through Trilium.
- *
- * TODO: Figure out some good attributes to use to populate
- * this inside the template to make it more dynamic
- */
-// $try(addOpenGraphMeta);
diff --git a/src/scripts/modules/expanders.ts b/src/scripts/modules/expanders.ts
index ebcb2ba778..276f345071 100644
--- a/src/scripts/modules/expanders.ts
+++ b/src/scripts/modules/expanders.ts
@@ -1,30 +1,3 @@
-// function anchorToId(anchor: HTMLAnchorElement) {
-// return anchor.href.replace("./", "");
-// }
-//
-// const stored = localStorage.getItem("expanded") ?? "[]";
-// let parsed: string[];
-// try {
-// parsed = JSON.parse(stored) as string[];
-// }
-// catch (e) {
-// parsed = [];
-// }
-// const state = new Set(parsed);
-// const submenus = Array.from(document.querySelectorAll("#menu .submenu-item"));
-// for (const sub of submenus) {
-// try {
-// if (state.has(anchorToId(sub.children[0] as HTMLAnchorElement))) sub.classList.add("expanded");
-// }
-// catch (e) {
-// // TODO: create logger
-// console.warn("Could not restore expanded state"); // eslint-disable-line no-console
-// console.error(e); // eslint-disable-line no-console
-// }
-// }
-
-// TODO: Swap this system to use type-book for full-link category
-
// In case a linked article lead to a new tree
const activeLink = document.querySelector("#menu a.active");
if (activeLink) {
@@ -45,15 +18,10 @@ export default function setupExpanders() {
if ((e.target as Element).closest(".submenu-item,.item") !== ex) return;
e.preventDefault();
e.stopPropagation();
- // ex.parentElement.parentElement.classList.toggle("expanded");
- ex.classList.toggle("expanded");
- // const id = anchorToId(ex.closest("a")!);
- // if (state.has(id)) state.delete(id);
- // else state.add(id);
- // // TODO: be able to remove all submenus of currently collapsed
- // localStorage.setItem("expanded", JSON.stringify([...state]));
+ const ul = ex.querySelector("ul")!;
+ ul.style.height = `${ul.scrollHeight}px`;
+ setTimeout(() => ex.classList.toggle("expanded"), 1);
+ setTimeout(() => ul.style.height = ``, 200);
});
}
-
-
}
\ No newline at end of file
diff --git a/src/scripts/modules/highlight.ts b/src/scripts/modules/highlight.ts
index 2465c5a687..5d59e7708f 100644
--- a/src/scripts/modules/highlight.ts
+++ b/src/scripts/modules/highlight.ts
@@ -19,7 +19,6 @@ const highlightJQuery: HLJSPlugin = {
result.value = result.value.replaceAll(/([^A-Za-z0-9.])\$\((.+)\)/g, function(match, prefix, variable) {
return `${prefix}<span class="hljs-variable language_">$(</span>${variable}<span class="hljs-variable language_">)</span>`;
});
- // TODO: add highlighting for static calls like $.ajax
}
};
@@ -32,14 +31,12 @@ export default function addHljs() {
if (!codeblocks.length) return; // If there are none, don't add dependency
// Add the hightlight.js styles from the child note of this script
- // TODO: make this a mapping
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "api/notes/cVaK9ZJwx5Hs/download";
document.head.append(link);
// Add the highlight.js script too
- // TODO: make this a mappin as well
const script = document.createElement("script");
script.src = "api/notes/6PVElIem02b5/download";
script.addEventListener("load", () => {
diff --git a/src/scripts/modules/search.ts b/src/scripts/modules/search.ts
index c7c77c014b..f9c362da58 100644
--- a/src/scripts/modules/search.ts
+++ b/src/scripts/modules/search.ts
@@ -25,7 +25,6 @@ function buildResultItem(result: SearchResult) {
export default function setupSearch() {
const searchInput: HTMLInputElement = document.querySelector(".search-input")!;
- // TODO: move listener to another function
searchInput.addEventListener("keyup", debounce(async () => {
// console.log("CHANGE EVENT");
const current = document.body.dataset.noteId;
@@ -48,7 +47,7 @@ export default function setupSearch() {
container.style.minWidth = `${rect.width}px`;
const existing = document.querySelector(".search-results");
- if (existing) existing.replaceWith(container); // TODO: consider updating existing container and never removing
+ if (existing) existing.replaceWith(container);
else document.body.append(container);
}, 500));
diff --git a/src/scripts/modules/theme.ts b/src/scripts/modules/theme.ts
index 1e3d57a3b9..35a2400c28 100644
--- a/src/scripts/modules/theme.ts
+++ b/src/scripts/modules/theme.ts
@@ -12,7 +12,6 @@ if (preference) {
export default function setupThemeSelector() {
const themeSwitch: HTMLInputElement = document.querySelector(".theme-selection input")!;
- // TODO: consolidate this with initialization (DRY)
themeSwitch?.addEventListener("change", () => {
if (themeSwitch.checked) {
document.body.classList.add("theme-dark");
diff --git a/src/scripts/test.ts b/src/scripts/test.ts
index 01a0c62a4b..d809aa06af 100644
--- a/src/scripts/test.ts
+++ b/src/scripts/test.ts
@@ -1,10 +1,5 @@
/* eslint-disable no-console */
-/**
- * This script was used for testing ToC generation in the page template...
- * TODO: find a better way to integrate ts/js into the templates so I'm
- * not debugging on the fly constantly.
- */
// const data = `<figure class="image"><img src="api/images/rU1cVNuH33Qg/image.png"></figure><p><a href="https://github.com/zadam/trilium">Trilium&nbsp;</a> really does rock! Don't believe me? Well this entire website was made using the shared notes feature inside Trilium with a little bit of extra CSS and JS also contained in Trilium.</p><figure class="image"><img src="api/images/hqhAFecLJzEK/image.png"></figure><p>It turns Trilium into an insanely powerful WYSIWYG website creator. But that's just a side feature of Trilium, it's so much more powerful with endless possibilities.</p><h2>Why It Rocks</h2><p>If somehow you aren't already convinced, take a look below for even more reasons why Trilium rocks!</p><h3>Built-in Features</h3><p>This section is shamelessly borrowed from Trilium's README.</p><ul style="list-style-type:disc;"><li>Notes can be arranged into arbitrarily deep tree. Single note can be placed into multiple places in the tree (see <a href="https://github.com/zadam/trilium/wiki/Cloning-notes">cloning</a>)</li><li>Rich WYSIWYG note editing including e.g. tables, images and <a href="https://github.com/zadam/trilium/wiki/Text-notes#math-support">math</a> with markdown <a href="https://github.com/zadam/trilium/wiki/Text-notes#autoformat">autoformat</a></li><li>Support for editing <a href="https://github.com/zadam/trilium/wiki/Code-notes">notes with source code</a>, including syntax highlighting</li><li>Fast and easy <a href="https://github.com/zadam/trilium/wiki/Note-navigation">navigation between notes</a>, full text search and <a href="https://github.com/zadam/trilium/wiki/Note-hoisting">note hoisting</a></li><li>Seamless <a href="https://github.com/zadam/trilium/wiki/Note-revisions">note versioning</a></li><li>Note <a href="https://github.com/zadam/trilium/wiki/Attributes">attributes</a> can be used for note organization, querying and advanced <a href="https://github.com/zadam/trilium/wiki/Scripts">scripting</a></li><li><a href="https://github.com/zadam/trilium/wiki/Synchronization">Synchronization</a> with self-hosted sync server<ul><li>there's a <a href="https://trilium.cc/paid-hosting">3rd party service for hosting synchronisation server</a></li></ul></li><li><a href="https://github.com/zadam/trilium/wiki/Sharing">Sharing</a> (publishing) notes to public internet</li><li>Strong <a href="https://github.com/zadam/trilium/wiki/Protected-notes">note encryption</a> with per-note granularity</li><li>Sketching diagrams with built-in Excalidraw (note type "canvas")</li><li><a href="https://github.com/zadam/trilium/wiki/Relation-map">Relation maps</a> and <a href="https://github.com/zadam/trilium/wiki/Link-map">link maps</a> for visualizing notes and their relations</li><li><a href="https://github.com/zadam/trilium/wiki/Scripts">Scripting</a> - see <a href="https://github.com/zadam/trilium/wiki/Advanced-showcases">Advanced showcases</a></li><li><a href="https://github.com/zadam/trilium/wiki/ETAPI">REST API</a> for automation</li><li>Scales well in both usability and performance upwards of 100 000 notes</li><li>Touch optimized <a href="https://github.com/zadam/trilium/wiki/Mobile-frontend">mobile frontend</a> for smartphones and tablets</li><li><a href="https://github.com/zadam/trilium/wiki/Themes">Night theme</a></li><li><a href="https://github.com/zadam/trilium/wiki/Evernote-import">Evernote</a> and <a href="https://github.com/zadam/trilium/wiki/Markdown">Markdown import &amp; export</a></li><li><a href="https://github.com/zadam/trilium/wiki/Web-clipper">Web Clipper</a> for easy saving of web content</li></ul><h3>Community Addons</h3><p><a href="https://github.com/Nriver">Nriver </a>maintains an awesome list of addons for Trilium made by the community. Check out the <a href="https://github.com/Nriver/awesome-trilium">official list on GitHub</a>. We do mirror the list here on the <a href="#root/WqBnya4Ye8rS/lMLmqcrPVHvE">Showcase</a> page if you just want a quick look.</p><h3>Custom Scripts</h3><p>In addition to using community made scripts, widgets, themes, and everything in between, Trilium leaves things open-ended for you the end-user. You can script as much or as little as you like inside Trilium. You can automate all kinds of workflows, do data analysis, or even simple things like set a keybind to open a specific note. The world is your oyster as they say, and Trilium is your world. Pretend that made sense.</p><p>&nbsp;</p><h2>About This Site</h2><p>This website is not at all affiliated with Trilium Notes or its creator(s). The site is broken up into a few main sections that you can see in the navigation bar at the top of the page. At a high level, there's two sections targeting end-users, two sections targeting developers, and one meant for everyone.</p><h3>Status</h3><p>This site is still a work-in-progress! Writing documentation isn't the most fun thing in the world so this will just be something I work on when I have free time. You'll usually find me working on one of my Trilium-related addons, Trilium itself, or my other open-source project: <a href="https://betterdiscord.app">BetterDiscord</a>.</p><h3>Goals</h3><p>Rather than saying some specific goals of what this site strives to be, I'll say what it strives <i>not </i>to be; This site is not meant to be a complete recreation of the Wiki with every detail and page included. It <i>is</i> meant to be a (mostly) one-stop shop for users and developers alike looking to supplement their knowledge. It may at some point expand and include everything from the wiki because users tend to prefer a fancier UI like this, but it is not the end-goal.</p><h3>Contributing</h3><p>Since this entire site is just a share from my personal Trilium instance, there is no easy way to contribute new pages or fixes for typos. At some point I will create a GitHub repository for this site's supplementary CSS and JS, and that repository can also act as a home for issues and discussion. But who knows, maybe within that time frame I'll think of some clever way to introduce contributions.</p><p>&nbsp;</p>`;
const data = `<h2>Frontend API</h2><p>The frontend api supports two styles, regular scripts that are run with the current app and note context, and widgets that export an object to Trilium to be used in the UI. In both cases, the frontend api of Trilium is available to scripts running in the frontend context as global variable <code>api</code>. The members and methods of the api can be seen on the <a href="https://zadam.github.io/trilium/frontend_api/FrontendScriptApi.html">FrontendScriptApi </a>page.</p><h3>Scripts</h3><p>Scripts don't have any special requirements. They can be run at will using the execute button in the UI or they can be configured to run at certain times using <a href="https://github.com/zadam/trilium/wiki/Attributes">Attributes</a> on the note containing the script.</p><h4>Global Events</h4><p>This attribute is called <code>#run</code> and it can have any of the following values:</p><ul><li><code>frontendStartup</code> - executes on frontend upon startup.</li><li><code>mobileStartup</code> - executes on mobile frontend upon startup.</li><li><code>backendStartup</code> - executes on backend upon startup.</li><li><code>hourly</code> - executes once an hour on backend.</li><li><code>daily</code> - executes once a day on backend.</li></ul><h4>Entity Events</h4><p>These events are triggered by certain <a href="https://github.com/zadam/trilium/wiki/Attributes#relations">relations</a> to other notes. Meaning that the script is triggered only if the note has this script attached to it through relations (or it can inherit it).</p><ul><li><code>runOnNoteCreation</code> - executes when note is created on backend.</li><li><code>runOnNoteTitleChange</code> - executes when note title is changed (includes note creation as well).</li><li><code>runOnNoteContentChange</code> - executes when note content is changed (includes note creation as well).</li><li><code>runOnNoteChange</code> - executes when note is changed (includes note creation as well).</li><li><code>runOnNoteDeletion</code> - executes when note is being deleted.</li><li><code>runOnBranchCreation</code> - executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.</li><li><code>runOnBranchDeletion</code> - executes when a branch is delete. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).</li><li><code>runOnChildNoteCreation</code> - executes when new note is created under this note.</li><li><code>runOnAttributeCreation</code> - executes when new attribute is created under this note.</li><li><code>runOnAttributeChange</code> - executes when attribute is changed under this note.</li></ul><h3>Widgets</h3><p>Conversely to scripts, widgets do have some specific requirements in order to work. A widget must:</p><ul><li>Extend <a href="https://zadam.github.io/trilium/frontend_api/BasicWidget.html">BasicWidget </a>or one of it's subclasses.</li><li>Create a new instance and assign it to <code>module.exports</code>.</li><li>Define a <code>parentWidget</code> member to determine where it should be displayed.</li><li>Define a <code>position</code> (integer) that determines the location via sort order.</li><li>Have a <code>#widget</code> attribute on the containing note.</li><li>Create, render, and return your element in the render function.<ul><li>For <a href="https://zadam.github.io/trilium/frontend_api/BasicWidget.html">BasicWidget </a>and <a href="https://zadam.github.io/trilium/frontend_api/NoteContextAwareWidget.html">NoteContextAwareWidget</a> you should create <code>this.$widget</code> and render it in <code>doRender()</code>.</li><li>For <a href="https://zadam.github.io/trilium/frontend_api/RightPanelWidget.html">RightPanelWidget </a>the <code>this.$widget</code> and <code>doRender()</code> are already handled and you should instead return the value in <code>doRenderBody()</code>.</li></ul></li></ul><h4>parentWidget</h4><ul><li><code>left-pane</code> - This renders the widget on the left side of the screen where the note tree lives.</li><li><code>center-pane</code> - This renders the widget in the center of the layout in the same location that notes and splits appear.</li><li><code>note-detail-pane</code> - This renders the widget <i>with</i> the note in the center pane. This means it can appear multiple times with splits.</li><li><code>right-pane</code> - This renders the widget to the right of any opened notes.</li></ul><h4>Tutorial</h4><p>For more information on building widgets, take a look at <a href="#root/WqBnya4Ye8rS/wmgYY4gYKq69/MLpHDpX0NhDg/X7pxYpiu0lgU">Widget Basics</a>.</p>`;
const headingRe = /(<h[1-6]>)(.+?)(<\/h[1-6]>)/g;
diff --git a/src/styles/navbar/navbar.css b/src/styles/navbar/navbar.css
index 7e1adf0e88..5b93d1d3e1 100644
--- a/src/styles/navbar/navbar.css
+++ b/src/styles/navbar/navbar.css
@@ -50,7 +50,7 @@
}
#menu li > ul {
- transition: height 1000ms ease;
+ transition: height 200ms ease;
}
#menu li:not(.expanded) > ul {
diff --git a/src/templates/page.ejs b/src/templates/page.ejs
index 480f65c3c8..afbded51a4 100644
--- a/src/templates/page.ejs
+++ b/src/templates/page.ejs
@@ -65,7 +65,7 @@ const customServerYml = `- url: "{protocol}://{domain}:{port}/etapi"
<% } %>
<%- header %>
<title><%= note.title %><% if (note.noteId !== subRoot.noteId) { %> - <%= subRoot.title %><% } %></title>
- <!-- TODO: determine a good way to populate this via labels -->
+
<!-- HTML Meta Tags -->
<meta name="description" content="A website for guides, reference, showcase, inspiration, and more, all for Trilium Notes! Not convinced? Come see for yourself just what Trilium can do."
><!-- Facebook Meta Tags -->
@@ -97,9 +97,9 @@ content = content.replaceAll(headingRe, (...match) => {
%>
<body data-note-id="<%= note.noteId %>" class="type-<%= note.type %><%= themeClass %>">
<div id="mobile-header">
- <a href="./<%= subRoot.shareId %>">
+ <a href="./">
<% if (subRoot.hasRelation("shareLogo")) { %>
- <img src="api/notes/<%= subRoot.getRelation("shareLogo").value %>/download" alt="Logo" />
+ <img src="api/images/<%= subRoot.getRelation("shareLogo").value %>/logo.svg" alt="Logo" />
<% } %>
<%= subRoot.title %>
</a>
@@ -109,9 +109,9 @@ content = content.replaceAll(headingRe, (...match) => {
<div id="left-pane">
<div id="navigation">
<div id="site-header">
- <a href="./<%= subRoot.shareId %>">
+ <a href="./">
<% if (subRoot.hasRelation("shareLogo")) { %>
- <img src="api/notes/<%= subRoot.getRelation("shareLogo").value %>/download" alt="Logo" />
+ <img src="api/images/<%= subRoot.getRelation("shareLogo").value %>/logo.svg" alt="Logo" />
<% } %>
<%= subRoot.title %>
</a>
@@ -198,12 +198,8 @@ content = content.replaceAll(headingRe, (...match) => {
<div id="toc-pane">
<h3>On This Page</h3>
<ul id="toc">
- <%
- let active = true;
- for (const entry of toc) {
- %>
- <%- include('toc_item', {entry, active}) %>
- <% active = false %>
+ <% for (const entry of toc) { %>
+ <%- include('toc_item', {entry}) %>
<% } %>
</ul>
</div>
diff --git a/src/templates/toc_item.ejs b/src/templates/toc_item.ejs
index d613e52f9a..1a85710922 100644
--- a/src/templates/toc_item.ejs
+++ b/src/templates/toc_item.ejs
@@ -5,14 +5,14 @@ const slug = slugify(entry.name);
<li>
- <a href="#<%= slug %>"<% if (active) { %> class="active"<% } %>>
+ <a href="#<%= slug %>">
<%= entry.name %>
</a>
<% if (entry.children.length) { %>
<ul>
<% for (const subentry of entry.children) { %>
- <%- include('toc_item', {entry: subentry, active: false}) %>
+ <%- include('toc_item', {entry: subentry}) %>
<% } %>
</ul>
<% } %>
diff --git a/src/templates/tree_item.ejs b/src/templates/tree_item.ejs
index dd50a108ae..8b3f5ecc5e 100644
--- a/src/templates/tree_item.ejs
+++ b/src/templates/tree_item.ejs
@@ -6,10 +6,10 @@ const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "
%>
<% if (note.noteId !== subRoot.noteId) { %>
-<a class="<%= linkClass %>" href="<%= linkHref %>"<%= target %>>
- <% if (note.hasVisibleChildren()) { %><button class="collapse-button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon right-triangle"><path d="M3 8L12 17L21 8"></path></svg></button><% } %>
- <%= note.title %>
-</a>
+ <a class="<%= linkClass %>" href="<%= linkHref %>"<%= target %>>
+ <% if (note.hasVisibleChildren()) { %><button class="collapse-button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon right-triangle"><path d="M3 8L12 17L21 8"></path></svg></button><% } %>
+ <%= note.title %>
+ </a>
<% } %>