Get a list of pages that refer to the current page?

While the Linked References section is useful, it’s usually just too much information for my needs.
What would really help me is a simple list of page links.

Example: In a page called Page One, which is mentioned in pages A, B, and C the query would return something like: [[A]], [[B]], [[C]].

I have great trouble figuring out how to use queries, but I find it hard to believe that this isn’t possible.
Can someone help me out?

Would the Local Graph / Page Graph be a possible alternative?

Well, yeah, but it’d be “friction-y” for my workflow.
I’m used to seeing information arranged in a particular way, and I’d prefer to make the tool fit my preferences than the other way round.

Would this be a result you can use?

#+BEGIN_QUERY
{:query [:find ?tag
   :in $ ?current
   :where
     [?p :block/name ?current]
     [?b :block/refs ?p]
     [?b :block/page ?page]
     [?page :block/name ?tag]
 ]
 :inputs [:current-page]
 :result-transform (fn [result] (sort result))
 :view (fn [tags] [:div (for [tag (flatten tags)] [:a.tag.mr-1 {:href (str "#/page/" tag)} (str "#" tag)] )] )
}
#+END_QUERY
2 Likes

Wow. Yup, that’s basically it.
Don’t really need the links to appear as tags, but I’m pretty sure I can now figure any further tweaks myself.

Thanks very much!

(I feel compelled to add, however, that I really don’t understand how such a simple result requires so much weird code. But that’s a rant for another day.)

1 Like

We can argue over “weird code” :joy:
But essentially the first part is just getting the actual data. We have a page, then we have a block that references that page, and finally we have a page that the block is on. We return the name of that last page in :find ?tag.
The :result-transform sorts the result, feel free to omit I guess.
And the :view determines how it is displayed.
You can change that view in any number of ways to change how the result is viewed.
Without the :view you get the raw data, basically one long string without spaces.
I was experimenting a little and you technically don’t need all aspects of the view.
(fn [tags] ...) is just defining a function with input labeled tags.
(for [tag (flatten tags)] ...) is basically flatten tags to a string and then for each of the items in tags.
[:a ...] is where the link is made with the type .tag.mr-1 actually ensure you have spaces between the tags.
(str ...) is a concert to string and also concatenate. Add #/page/ to the result, for the link url part and add # to the result for the link text part.
It’s just what you deem weird. The view transforms raw data into something readable.

If you want a simple vertical list you can try this query instead.

#+BEGIN_QUERY
{:query [:find (pull ?page [*])
   :in $ ?current
   :where
     [?p :block/name ?current]
     [?b :block/refs ?p]
     [?b :block/page ?page]
 ]
 :inputs [:current-page]
}
#+END_QUERY
2 Likes

Thanks for the explanation. I kind of figured it out just be reading the query, but I do appreciate you taking the time to provide such a lucid description.

Like I wrote earlier, I’ll leave discussions of syntax to another day. No point cluttering things up here.

1 Like

what if my page has alias? I cannot use this query to find pages refer to alias.
Thanks!

Welcome. You may utilize attribute :block/alias (e.g. like here, but read about the mistake).

1 Like

Aha I see that, GREAT!!