Skip to content

Commit 2e9f2b7

Browse files
author
vaifix
committed
1.0
1 parent e5b4516 commit 2e9f2b7

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
# Trilium-Heatmap
22
Display a note modification heatmap in your Trilium note, just like the Github contributions heatmap!
3+
![](./Trilium-Heatmap.png)
4+
Powered by [d3.js](https://d3js.org/).
5+
6+
## Features
7+
- Display a heatmap of note edits in Trilium.
8+
- View the number of edits per day for each note.
9+
- Click to navigate to the corresponding date.
10+
11+
## Installation
12+
1. Download the zip file from the latest Releases.
13+
2. Right-click on the zip file in the Trilium note tree and select "Import", uncheck "Safe import", and click the "Import" button.
14+
3. If you don't have any note data for the first use, you need to restart Trilium or press F5 to refresh the frontend.
15+
4. Enjoy it!
16+
17+
## Tip
18+
If you have a Trilium server, you can schedule it to run on the server periodically to reduce the number of database queries.
19+
20+
You can download or copy the [runOnServer.js](./runOnServer.js) file into a note of type "JS backend" in Trilium and add the following tags: `#run=hourly #runAtHour=2 #runOnInstance=sync_server`, where you need to replace "sync_server" with your Trilium instance.

Trilium-Heatmap.png

45.3 KB
Loading

Trilium-Heatmap.zip

98.3 KB
Binary file not shown.

runOnServer.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = function () {
2+
const datas = {};
3+
let today = new Date();
4+
let tomorrow = new Date(today);
5+
tomorrow.setDate(today.getDate() + 1);
6+
let startDate = new Date(today.getFullYear() - 1, today.getMonth(), today.getDate());
7+
8+
while (startDate <= tomorrow) {
9+
let formattedDate = startDate.toISOString().slice(0,10);
10+
const counts = api.sql.getColumn(`SELECT COUNT(*) AS data_count FROM notes WHERE utcDateModified LIKE '%${formattedDate}%'; `);
11+
12+
if (counts != 0){
13+
datas[formattedDate] = counts[0];
14+
}
15+
startDate.setDate(startDate.getDate() + 1);
16+
}
17+
18+
let str = JSON.stringify(datas);
19+
let codeContent = "module.exports = function () {var arr=" + str + ";return arr}";
20+
const note = api.getNoteWithLabel("heatmapDatas");
21+
note.setContent(codeContent);
22+
}

0 commit comments

Comments
 (0)