Use TriliumNext as Blogger

- w
2025-04-28

About two years ago, I discovered Trilium (later I migrated to TriliumNext since it went into maintenance mode) as a personal knowledge management software. The extensive functionalities are really impressive compared to other open-source software, especially since it supports different kinds of notes and allows scripting.

As for me, WYSIWYG is essential for a note-taking app. Even though plain text formats like Markdown have many advantages, such as being easy to store and allowing it to be read without special software, they have limited expressiveness compared to formats particularly designed for typesetting like Microsoft Word or LaTeX. Trilium uses HTML for text notes, which is still plain text but enables complex typesetting.

Sharing Function

The sharing function of Trilium Notes really shines when it comes to the flexibility of use. With the tag #shareRoot, you can turn a shared note and its child notes into a website or a blog. In this case, you don't resort to the same tools to deploy your webpages somewhere. You can simply edit your pages somewhere in Trilium and sync with a Trilium server. Then, the webpage is accessible on the web, no intermedia actions.

Online Service

I didn't choose to self-host the Trilium server since my database is not large enough. Instead, I use Trilium.cc to host my content. It is not that expensive. You can even get a 15% discount when you pay yearly ($36 per year), but before you choose this service, remember that you should not store the large media files in Trilium (it is not reasonable to put media files in a note software anyway). If you'd like to host the server yourself, you can download the server package or even use Docker to facilitate the deployment of the server.

After the you have the server, you can use synchonization in the Trilium Desktop to synchronize all your notes to the server. You can go to the Sync in Settings in the desktop version to set it up.

Then your notes will be able to be accessed everywhere.

Blog Setup

Now, all you need to do is set a note subtree in the Trilium to Shared like below so it can be accessed by anyone without the need of authentication like below.

However, you may need to figure out how to organize the notes and customize the theme since the default theme does not appeal as a blog at all. I use Ankia Theme for my blog since it provides an easy mechanism for managing the blog posts and it is visually comfortable. After you import Ankia Theme to Trilium, you may need to share the subtree you just imported and set the Home as the #shareRoot. In the subtree, you can create an activity (说说) or a blog post under a subtree of categories (文章分类). Every activity and post should be based on the template Blog Template (博客模板) so you can add tags. You don't need to modify the structure in Tags (标签); a background script will automatically create them.

I translated it partially into English; if you are interested, you can access it from my fork. I will translate the rest depending on how I use it. The original Ankia Theme is mainly used by the Chinese community. I added some functionality so it can access more common services like Disqus and Google Analytics. More functions will be added later.

Adding Functionality

Disqus for Comments

I added Disqus to the template so that we can add comments to each webpage. The code is inserted at the end of each post:

<!-- Disqus -->
<% if (subRoot.note.hasLabel("enableDisqus")) { %>
<div id="disqus_thread"></div>
<script>
  /**
  *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
  *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables    */
  var disqus_config = function () {
    this.page.url = window.location.protocol + "//" + window.location.host + window.location.pathname;
    this.page.identifier = "<%= note.noteId %>";
  };

  (function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = "<%= subRoot.note.getLabelValue("disqusEmbedJs") %>";
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
  })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<% } %>

You need to follow the instructions on Disqus to get the URL of the embedded JavaScript. Then you need to add #enableDisqus and #disqusEmbedJs to the root of your subtree.

Modify Word Count

The original version counts Chinese characters accurately, which is not suitable for languages like English, where every word is separated by spaces. I changed this mechanism so it counts content in English (or languages like French, too).

Summary

Trilium is excellent note-taking software. Its flexibility allows many possibilities. Shared notes make it possible to share knowledge. Thanks to the Trilium contributors and their users, I can create this beautiful blog and have a hassle-free way to manage the posts.


Content