Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions backlinks/backlinks.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ QtObject {
}
];

function getSubFolder(note, path) {
var fileName = note.fullNoteFilePath;
var pathRe = new RegExp(path + dirSep + "((.*)" + dirSep + ")*.*");
var subfolderName = fileName.replace(pathRe, "$2");
return subfolderName;
}

function normalizeText(text) {
return text.toLowerCase().replace(/[\-\s_]/g, "").replace(/\[\[([^\]]+)\|[^\]]+\]\]/g, "[[$1]]");
}
Expand All @@ -52,6 +45,9 @@ QtObject {
out += "<h2>Backlinks</h2>\n\n<ul>\n";
for (var i = 0; i < backlinks.length; i++) {
var backlinkPath = backlinks[i]["p"];
if (script.platformIsWindows()) {
backlinkPath = "/" + backlinkPath;
}
var backlinkTitle = backlinks[i]["t"];
out += " <li><a href=\"file://" + backlinkPath + "\" title=\"" + backlinkPath + "\">" + backlinkTitle + "</a></li>\n";
}
Expand All @@ -62,17 +58,20 @@ QtObject {

function getBacklinks(note) {
var noteName = note.name;
var path = script.currentNoteFolderPath();
var subfolderName = getSubFolder(note, path);
var subfolderName = note.relativeNoteFileDirPath;
var nameNormalized = normalizeText(noteName);
/* Does not work on Windows
dirSep = script.dirSeparator();
*/
dirSep = "\/";

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

noteIds.forEach(function (pageId){
var pageObj = script.fetchNoteById(pageId);
var basename = pageObj.name;
var pageGroup = getSubFolder(pageObj, path);
var pageGroup = pageObj.relativeNoteFileDirPath;
var text = pageObj.noteText;
if (/\[\[.*\]\]/.test(text)) {
var normalizedText = normalizeText(text);
Expand Down
2 changes: 1 addition & 1 deletion backlinks/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"script": "backlinks.qml",
"authors": ["@dohliam"],
"platforms": ["linux", "macos", "windows"],
"version": "0.0.2",
"version": "0.0.3",
"minAppVersion": "20.4.18",
"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>."
}