List of files linked to a file in any depth

What I’m trying to do

Hey, im trying to get a List with dataview of all the Notes that link to the notes that link to a file. It is like the lokal graph in depth=2. Idealy, i would like to do that in any depht.

Things I have tried

I am quite new to Dataview (and absolutely not familiar with dataviewjs) and have thought about some algrothmic solutions without any good idea about implementation. My first Idea was to find a usefull coding in the FROM statement. That would be the easiest option. But i cant connect the [] fuction in series.

The most naive solution (showing only backlinks) might look something like this:

// dataviewjs
const depth = 2;

function getBacklinkedNotes(page) {
	const backlinks = page.file.inlinks;
	const backlinkedNotes = backlinks.map(backlink => dv.page(backlink.path));
	return backlinkedNotes.array();
}

const result = {0: [dv.current()]};

for (let d = 1; d <= depth; d++) {
	result[d] = [].concat(...result[d - 1].map(getBacklinkedNotes));
	dv.header(1, `Depth ${d}`);
	dv.list(result[d].map(page => page.file.link));
}

Ok, nice thank you so much. I needed some time understanding the codeblock, but it works. Now i tried to manipulate it for my specific means and failed again. Thats why i share my total goal, not just the implementing one, maybe someone has like a very simple answer.

To be very precise in what i want, maybe, you can help me to understand how i can implement it:

  1. I want to select all Files links to present note with the tag ‘konzept’ and let them shown in a table
  2. This table schould contain a column with all notes linked to the ‘konzept’ notes that have the tag ‘Quotations’ and have access to their metadata.

What i tried first was like this:

table file.inlinks
from [[]] AND #Konzept 

But because the Notes in the second depth aren’t part of my selected database (due from), i can’t acess the metadata of my ‘Quotations’ (only the links as part of the metadata of the ‘konzept’ notes).

@ush for your codeblock i asked myself whether i can implement to different where clauses for to different depth and how to do so.

Hey, i think i got it now with my code, but somehow. THere is an Error: “Unexpected end of input”. That is my code:

\\ The function determinates a new variable called authorship.
function authorship(page) {
	if(page.file.tags == "#Literatur/Zitat") {
		const authorship = page.Autorin;
		return authorship;
\\ If it is a quotation (Literatur/Zitat), then authorship =Autorin
	 } else {
		const backlinks =page.file.inlinks; 
		const backlinkedNotes = backlinks.map(authorship => dv.page(authorship.Autorin));
		return authorship.array();	
\\ If it is something else (like a konzept), authorship is an array of the authors of the notes linking to that konzept. 
}
dv.list(authorship())
\\ i List the authorship of the current page. 

Where is the error? Thank you so much for helping me

You’re missing a closing brace on the else block near the end for starters. There are possibly also other errors…

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.