Skip to content

Commit 9541dab

Browse files
authored
Backlinks update: fix for Windows (#232)
* Update backlinks.qml Fix for Windows; still compatible with Linux. Note that the paths in Windows within QOwnnotes also use "/" as separator. Function getSubFolder is no longer required, replaced with built-in functions. * Update info.json [BUG] Backlinks on Windows Fix #231
1 parent a748bdf commit 9541dab

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

Diff for: backlinks/backlinks.qml

+9-10
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ QtObject {
2525
}
2626
];
2727

28-
function getSubFolder(note, path) {
29-
var fileName = note.fullNoteFilePath;
30-
var pathRe = new RegExp(path + dirSep + "((.*)" + dirSep + ")*.*");
31-
var subfolderName = fileName.replace(pathRe, "$2");
32-
return subfolderName;
33-
}
34-
3528
function normalizeText(text) {
3629
return text.toLowerCase().replace(/[\-\s_]/g, "").replace(/\[\[([^\]]+)\|[^\]]+\]\]/g, "[[$1]]");
3730
}
@@ -52,6 +45,9 @@ QtObject {
5245
out += "<h2>Backlinks</h2>\n\n<ul>\n";
5346
for (var i = 0; i < backlinks.length; i++) {
5447
var backlinkPath = backlinks[i]["p"];
48+
if (script.platformIsWindows()) {
49+
backlinkPath = "/" + backlinkPath;
50+
}
5551
var backlinkTitle = backlinks[i]["t"];
5652
out += " <li><a href=\"file://" + backlinkPath + "\" title=\"" + backlinkPath + "\">" + backlinkTitle + "</a></li>\n";
5753
}
@@ -62,17 +58,20 @@ QtObject {
6258

6359
function getBacklinks(note) {
6460
var noteName = note.name;
65-
var path = script.currentNoteFolderPath();
66-
var subfolderName = getSubFolder(note, path);
61+
var subfolderName = note.relativeNoteFileDirPath;
6762
var nameNormalized = normalizeText(noteName);
63+
/* Does not work on Windows
64+
dirSep = script.dirSeparator();
65+
*/
66+
dirSep = "\/";
6867

6968
var noteIds = script.fetchNoteIdsByNoteTextPart("");
7069
var backlinks = [];
7170

7271
noteIds.forEach(function (pageId){
7372
var pageObj = script.fetchNoteById(pageId);
7473
var basename = pageObj.name;
75-
var pageGroup = getSubFolder(pageObj, path);
74+
var pageGroup = pageObj.relativeNoteFileDirPath;
7675
var text = pageObj.noteText;
7776
if (/\[\[.*\]\]/.test(text)) {
7877
var normalizedText = normalizeText(text);

Diff for: backlinks/info.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"script": "backlinks.qml",
55
"authors": ["@dohliam"],
66
"platforms": ["linux", "macos", "windows"],
7-
"version": "0.0.2",
7+
"version": "0.0.3",
88
"minAppVersion": "20.4.18",
99
"description" : "This script generates a list of backlinks to the current note from all other notes in the collection. Backlinks requires the use of wiki-style link syntax and should be installed alongside the wiki-links script. More information can be found at <a href='https://github.com/qownnotes/scripts/wiki/backlinks'>backlinks</a>."
1010
}

0 commit comments

Comments
 (0)