Skip to content

Commit 0213fe5

Browse files
committed
fetch-url-title-with-kanboard-cli: add script
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent a1cadd7 commit 0213fe5

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import QtQml 2.0
2+
3+
/**
4+
* This script uses kanboard-cli to fetch the title of Kanboard task URLs.
5+
*
6+
* Dependency:
7+
* https://github.com/digital-blueprint/kanboard-cli
8+
*/
9+
QtObject {
10+
property string kanboardCliPath
11+
property string kanbanUrlPrefixes
12+
13+
property variant settingsVariables: [
14+
{
15+
"identifier": "kanboardCliPath",
16+
"name": "kanboard-cli path",
17+
"description": "Please select the path to your kanboard-cli executable:",
18+
"type": "file",
19+
"default": "kanboard-cli"
20+
},
21+
{
22+
"identifier": "kanbanUrlPrefixes",
23+
"name": "Kanban URL prefixes",
24+
"description": "Enter Kanboard base URL prefixes, one per line. Matching task URLs below those prefixes will be resolved with kanboard-cli.",
25+
"type": "text",
26+
"default": "https://kanboard.example.com"
27+
},
28+
]
29+
30+
/**
31+
* This function is called before QOwnNotes tries to fetch a webpage title
32+
* in the link dialog.
33+
*
34+
* @param url string the URL whose title should be fetched
35+
* @return string the title for the URL, or an empty string to let QOwnNotes fetch it
36+
*/
37+
function fetchUrlTitleHook(url) {
38+
var taskId = taskIdFromConfiguredPrefix(url);
39+
40+
if (taskId === "") {
41+
return "";
42+
}
43+
44+
var result = script.startSynchronousProcess(kanboardCliPath, ["--json", "task", "get", taskId]);
45+
46+
try {
47+
var task = JSON.parse(String(result));
48+
return task.title || "";
49+
} catch (error) {
50+
script.log("Could not fetch Kanboard task title: " + error);
51+
}
52+
53+
return "";
54+
}
55+
56+
function taskIdFromConfiguredPrefix(url) {
57+
var prefixes = kanbanUrlPrefixes.split(/\r?\n/);
58+
59+
for (var i = 0; i < prefixes.length; i++) {
60+
var prefix = prefixes[i].trim();
61+
62+
if (prefix === "" || url.indexOf(prefix) !== 0) {
63+
continue;
64+
}
65+
66+
var rest = url.substring(prefix.length);
67+
var taskIdMatch = /^(?:\/)?task\/(\d+)(?:[/?#]|$)/.exec(rest);
68+
69+
if (taskIdMatch !== null) {
70+
return taskIdMatch[1];
71+
}
72+
}
73+
74+
return "";
75+
}
76+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "Fetch URL Title with Kanboard CLI",
3+
"identifier": "fetch-url-title-with-kanboard-cli",
4+
"script": "fetch-url-title-with-kanboard-cli.qml",
5+
"authors": ["@pbek"],
6+
"platforms": ["linux", "macos", "windows"],
7+
"version": "0.0.1",
8+
"minAppVersion": "26.5.10",
9+
"description": "Fetches Kanboard task titles for matching task URLs in the link dialog by using <a href='https://github.com/digital-blueprint/kanboard-cli'>kanboard-cli</a>."
10+
}

0 commit comments

Comments
 (0)