How to create a hubnote of notes without any links with Dataview

What I’m trying to do

I want to create a “cockpit note” in which I can monitor which of my notes still don’t have any links, sorted from the latest ones I’ve created.

So the idea was to have a note with a Dataview query in which I pull notes which don’t have any inlinks nor outlinks, sorted by latest creation date, and limiting to the latest N notes (3, 5, 10, however many).

Things I have tried

What I found, after many searches, was the following query:

WHERE length(file.outlinks) = 0 AND length(file.inlinks) = 0
SORT file.cday DESC

Seems about right, except that the creation dates are totally out of whack, as can be seen below:

(Before it is proposed as a solution: no, I don’t use notes with dates in their names anymore, these are old files. Nowadays I create notes without any dates in their names.)

I should add that my notes are all created with a template that has a Date metadata, which apparently seems to affect the file.cday info.

For instance, the first file displayed in the query above has the following metadata (`Date is filled automatically with a {{date}}):

Something I’ve stumbled across was this post: Dataview - attribute - #4 by svenschuldt. If it is of any help, here is the result of the queries proposed by @mnvwvnm:

Something else I thought about, after many searches, was to just filter based on the Date field directly. But it doesn’t seem correct either, since it doesn’t show any recently created files without links (which I know exist):

WHERE length(file.outlinks) = 0 AND length(file.inlinks) = 0

I used LIMIT 100 to show its weird behavior:

Anyway, that’s as far as I could come up. It seems like such an easy thing to do, and yet it seems so convoluted to do, with no straight-forward code snippet anywhere online (as far as I could find). I’m sorry if it’s a dumb question, as I’m pretty new to the whole Dataview thing (as well as posting a question in this forum). Thanks!

PS: edited just to blur the files’ names :stuck_out_tongue:

Your data is actually sorted alphabetically in descending order, as you requested. But since your data format is include the name of the weekday first, this is the first part used when sorting.

Hence Wednesday, comes before Thursday, before Sunday, before Monday. And if you had any Tuesdays it would come before Thursday, and Saturdays before Mondays… Put another way, the weekday sorted alphabetically are: Wednesday, Thursday, Tuesday, Sunday, Saturday, Monday, Friday…

Stuff like this is why it’s strongly recommended to use the ISO8601 date format in fields like Date:, since it would allow for proper sorting, and actual recognition as date fields, and not strings as they’re in your case.

It’s a whole lot easier to format the dates for output format in your queries, then going the other way around, and trying to get to a proper date out of a “random” date string.

It could be in your case, that the following would work as a SORT clause, but it’s a temporarily fix, and you really ought to change to a proper date format of YYYY-MM-DD.

SORT regexreplace(Date, "(\d{2})-(\d{2})-(\d{4})", "$3-$2-$1")) DESC

Which possibly could be extended to include the time part if need be. (And if you change your date format, you should there be using YYYY-MM-DDTHH:mm (if I’m not mistaken) )

1 Like

W.r.t. the Date format, I see, I’ll change my templates to keep that in mind, thanks for the heads up.

As for your suggestion, it seems we’re getting closer! But it still seems to be filtering by the day name:

I suppose if there is something to just disconsider the day name, that would solve it. If it’s too difficult to do via Dataview query, I can try something out with a Python script later; I’m just looking for more straightforward solutions.

Ok, I have changed all my files’ Date tags to the format YYYY-MM-DD via a Python script (first time using ChatGPT but had to tweak it with a line or two, simple Try-Catching; impressive tho!). Thanks!

Just so it may help others who stumble upon this post, my final query for showing files without any links (inlinks or outlinks) is:

WHERE !contains(, "emplate") AND (length(file.outlinks) = 0 OR length(file.inlinks) = 0)

(note it sorts by the Date tag and disconsiders files with “emplate” in their names – had to remove Templates from this query.)

It shows as follows:

Note that the format it displays is different from the underlying Date tag format, as can be seen in the first file from the query:

Sidenote: Query of to-be-created notes

My other objective in this hubnote was to show files which still had to be created (“stub notes”), which was also satisfied by this corrected Date tag (important assumption: all my files are created from Templates which have a Date tag which fills automatically, of the sort Date: {{date:YYYY-MM-DD}}).

It may help others who try searching for it (as I did). I admit that the query I’m currently using is a patchwork of queries I’ve found in other posts, so it may not be the most coherent one (even understandable if I do say so myself :P).

The query is as follows:

key AS "ToBeCreatedZettel", AS "ReferencingFile", rows.Date AS "CreationDate"
FLATTEN file.outlinks as outlinks
WHERE !(outlinks.file) AND !(contains(meta(outlinks).path, "/"))
GROUP BY outlinks
SORT rows.Date DESC

It shows as below:

Note that it filters using the files’ Date tag (rows.Date). Note also that the left files are red (stub notes) and the right ones are blue (already exist), and that it even shows all files which link to their respective stub.

That’s it, it seems I’ve managed to create my hubnote as I wanted to. Thanks again! :smile:

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