Fancy backlink previewer with sorting option (dataviewjs code)

Since I am a heavy user of backlinks in my workflow, I quickly needed code that previews their content.

It was easy to do, just with the following code:


// USER CONDITIONS ==============================================================
let EXCLUDE_DATAVIEW_FILES = true;
// ==============================================================================


var inlinks = Array.from(dv.current().file.inlinks);
var flippedInlinks = inlinks.reverse();
var text_print;
var excludeFolder = ["👨‍💻Automations", "🔎 Traceability of literature reading"];
var excludeFilesWithNamesStartingWith = ["datav"]; // DO NOT ADD "datav"!

var notesToGiveOnlyLinks = ["REPORT PLOTS"]
let L_excl_folder = excludeFolder.length;
let L_notesToGiveOnlyLinks = notesToGiveOnlyLinks.length;

if (EXCLUDE_DATAVIEW_FILES) {
    excludeFilesWithNamesStartingWith.push("datav");
} else {
    // Check if "datav" exists in the array and remove it if found
    const index = excludeFilesWithNamesStartingWith.indexOf("datav");
    if (index !== -1) {
        excludeFilesWithNamesStartingWith.splice(index, 1);
    }
}


for (let p of flippedInlinks) { // Loop through pages 
    let ppath = p.path;
    let excludeNote = false;
	let  showOnlyLink = false;
    // Check if the note's path contains an excluded folder
    for (let iFolder = 0; iFolder < L_excl_folder; iFolder++) {
        if (ppath.includes(excludeFolder[iFolder])) {
            excludeNote = true;
            break; // No need to check further, exclude the note
        }
    }

    if (!excludeNote) {
        // Check if the note's name starts with any excluded string
        for (let iFileName = 0; iFileName < excludeFilesWithNamesStartingWith.length; iFileName++) {
            if (ppath.startsWith(excludeFilesWithNamesStartingWith[iFileName])) {
                excludeNote = true;
                break; // No need to check further, exclude the note
            }
        }

        if (!excludeNote) {
            dv.header("5", p);
		    for (let iFile = 0; iFile < L_notesToGiveOnlyLinks; iFile++) {
		        if (ppath.includes(notesToGiveOnlyLinks[iFile])) {
		            showOnlyLink = true;
		            break; // No need to check further, exclude the note
		        }
		    }
			if (!showOnlyLink) {
	            dv.el("article", await dv.io.load(ppath));
	            dv.el("article", "---");
            }
        }
    }
}

However, this previews them only with one column. I wanted something that previews them with many columns.

See the video of the result in this google drive link.

Code is quite large, and given in this repo.

1 Like

Longform writers, beware :slight_smile:

Not getting the reference

The dv.io.load will put the complete content of each file in the parent file, I gather. Will be rough, especially with a lot of links.

Yes, it is. My experience is that it is still quite acceptable, and I have a very large vault.

In any case, I also use a filter to omit some note that are quite large.

I presume you use dv.view for this script.

I use the await dv.io.load(link.path).

Do you know of any better alternative?

In any case, this was my goal; to “unfold” the content of the linked mentions and be able to read them without hoping to each one of them.

What I meant is that in case you didn’t know about it, you’d do well to use dv.view to load the script in notes otherwise the code takes up too much space in each note.

I get the use case, but I use this sort of thing on demand and with a view to coping lines.
This was done by someone else in the past (last one in list).