DataviewJS Snippet Showcase

Ah thanks, I am absolutely going to check out your version!!!

  • I do the frontmatter-only version because I use inline keys for lazy description lists :smiley:…for now. I got the idea from other people, but I can’t find a link anywhere for the life of me.
  • I actually did several versions bouncing between different formats for holding the data, but my primary motivation was being rusty with JavaScript; I just needed a version that catered to the things I remember better :sweat_smile:. I would like to explore options that are more straightforward, so I REALLY appreciate you providing links and feedback!
  • localeCompare is pretty great :grin:

I want to iterate more on this soon, but I’m pretty pleased with what I have for my first dataviewjs block ever :slightly_smiling_face:.

1 Like

I forgot to answer your question: for frontmatter, capitalization and punctuation differences are all counted separately (at least in my snippet)! I tested this with the following keys (all brand-new to my vault and placed together in one file’s YAML), and all of them were treated as unique and each was only counted once: catch:, Catch:, mind:, mind!:, head space:, head-space:, and headspace:.

1 Like

Hello, in my vault i have a folder called work here i create one note for each case i’m working. Inside those notes/cases I create a task list with dates like this - [ ] Do something [🗓️:: 2022-05-23].
Today i use this query to filter my tasks:

dv.taskList(dv.pages('"Notes/Work"')
.sort(p => p.file.name, 'asc')
.file.tasks
.where(t => !t.completed))        

My question is:

  1. Can i render task list where i filter only the tasks with [🗓️:: 2022-05-23] maker?
  2. Can i order this list by date of the marker [🗓️:: 2022-05-23] ?
  3. Can i render a list in this parameters: [ ] DATE: LINK_FOR_THE_NOTE
1 Like

Dataview as of recently supports that emoji notation for certain task fields without the :: to be compatible with the Tasks plugin. If using that shorthand, the calendar/dates emoji turns into a field called due so you can write things like .where(t => t.due) or .sort(t => t.due, 'desc'). I don’t know whether it’ll work like that with your formatting - you’ll have to experiment!

I don’t understand your question 3 - could you elaborate a little more?

Now it renders like this:

image

And i want to render like this:

I see. I only know how to help with part of that. To get rid of the grouping into different lists, pass false as a second argument to the dv.taskList call. i.e. dv.taskList(..., false). You might be able to change what is displayed per-line by using a call to map(t => ...) at the end of your query after all the filtering and sorting. I imagine you could use that to put the file link in front of the task text for example. However since the due date is part of the task text I’m not sure how you would reorder that.

1 Like

First, thank you for sharing this and for all your other generous activity in the forum.

Because the Hotkey names are given in terms of Windows naming conventions, e.g. Alt not Opt, it can be confusing. This is particularly true for hotkeys that use the Mac Control key as it also listed as Ctrl. For example:

  • The default Hotkey for Open Settings is listed in this query as Ctrl+,. On a Mac that translates to Command+,
  • If I assign something to Control+, (Mac key names), it also shows up in the DV table as Ctrl+,

Here’s a clipping from the report after assigning Open Vault to “Control+,” as described above.

Both Open Settings and Open Vault appear to be assigned to “Ctrl+,” when, in fact, settings uses Command and Vault uses Control.

Would it be possible to modify the script to show the key names in Mac-speak (Command, Control, Option)?

1 Like

Hya,

sorry for the sudden ping on this, but it is almost exactly what I need.
A few short questions:

  1. Is it possible to exlude all notes within anyone of a set of folders when checking how many links some note has? For specific things I need a link threshold of 1, but I don’t want the 85-ish missing lecture files across 15 subjects to show up, nor some equally-yet-to-be-populated TOCs from elsewhere.
  2. Similar to above, could one exclude any file from being shown if the filename itself follows either a specified regex, or just a string-match against an array of blacklisted strings? Basically the same reason, only that I’d need to exclude certain sets of files in directories which also contain files I’d like to see.
  3. Does the snippet also take into account aliases within the frontmatter, or does it only match against exact filenames?
2 Likes

Question

What :: DataviewJS By Example Q181
fromURL :: patrick_ambrosso: DataviewJS Snippet Showcase Q181

Question :: How to get the number of orphan notes?

Answer :: See Code T06_A first.
WebUpdatedOn :: 2022-06-25
KeyClasses :: DataviewJS
toURL :: Solutions

Test06: Get the number of orphan notes(Tagged: Habit )

Inline DataviewJS Queries

ONLY for Inline Queries

T06_A_the number of orphan notes: $=dv.pages("#Habit").where((page)=>page.file.inlinks.length===0&&page.file.outlinks.length===0).file.name.length

  • Here is the output(non-HTML).
5
The following also can be executed within a DataviewJS block
  • dv.span() or dv.list() may be omitted in Inline DataviewJS Queries.

T06_B_the number of orphan notes: $=dv.span(dv.pages("#Habit").where((page)=>page.file.inlinks.length===0&&page.file.outlinks.length===0).file.name.length)

  • Here is the output(non-HTML).
5
DataviewJS block

T06_C_the number of orphan notes:

dv.span(
    dv
        .pages("#Habit")
        .where(
            (page) =>
                page.file.inlinks.length === 0 &&
                page.file.outlinks.length === 0
        ).file.name.length
);
  • Here is the output(non-HTML).
5
1 Like