Dataview plugin snippet showcase

Thanks you - works now)))!

1 Like

In order to easily reference which programming problems cover which topics I wrote this. It can easily be used for anything else by changing the filter tags. You can also get rid of the following :

  let include = new Set([
    "BFS","DFS","Recursion","Tree","Trie","Graph","Heap","Array","HashMap",
    "Set","LinkedList","GhostNodes","Sorting","SlidingWindow","Backtracking",
    "TopologicalSort","DP","TreeTraversal","BinarySearch"
  ].map((x) => `#${x}`));
tagMap.forEach((v, k) => {
    if (!include.has(k))
      tagMap.delete(k);
  });

If you want it to make tables for any tag.
Heres the snippet:

` ``dataviewjs
  var _a;
  let filtertags = ["programming", "problem"];
  let include = new Set([
    "BFS","DFS","Recursion","Tree","Trie","Graph","Heap","Array","HashMap",
    "Set","LinkedList","GhostNodes","Sorting","SlidingWindow","Backtracking",
    "TopologicalSort","DP","TreeTraversal","BinarySearch"
  ].map((x) => `#${x}`));
  let source = filtertags.map((tag) => `#${tag}`).join(" AND ");
  let files = dv.pages(`${source} AND -"00 Meta/06 Templates"`).map((p) => p.file);
  let tagMap = new Map();
  for (let page of files)
    for (let tag of page.tags) {
      let data = (_a = tagMap.get(tag)) != null ? _a : { tagnum: 0, pages: [] };
      data.tagnum++;
      data.pages.push(page);
      tagMap.set(tag, data);
    }
  filtertags.forEach((t) => tagMap.delete(`#${t}`));
  tagMap.forEach((v, k) => {
    if (!include.has(k))
      tagMap.delete(k);
  });
  let count = 1;
  let headers = [];
  let elements = [];
  let sorted = Array.from(tagMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
  for (let [tag, data] of sorted) {
    headers.push(`${tag.replace("#", "")} (${data.tagnum})`);
    elements.push(data.pages.map((p) => p.link));
    if (count++ % 3 == 0) {
      dv.table(headers, [elements]);
      headers = [], elements = [];
    }
  }
  if (headers.length > 0)
    dv.table(headers, [elements]);
` ``
5 Likes

I’m very new to Dataview and I have a question about this.

I’d like to create a template where my Daily note shows me the files I’ve worked on today. What I want to know is - if I use WHERE date(now), will that keep updating and changing? So if it’s run on yesterday’s note, will it update and then show what’s edited today? Or will it continue to show what was edited yesterday?

In other words, do I need to set the WHERE bit relative to a specific date that’s pulled from “today”? Or will date(now) work to set the date so it doesn’t keep updating as time moves forward? Thanks!

2 Likes

Hi @melhopkop,

I don’t think à robust solution is possible.

Even if you made a formula “where date modified is today 2022-02-28”, if you modify any of the notes it retrieves at a later date, it will no longer show in your list.

A good solution would be dataview could “print” a static version of the table, ie the actual column headings, files and data list/table. But it would only really be useful if the table could be converted to a static form at 23:59 at the end of the day. And that sounds clunky!

given the next md file

---
type: bookmarks
tags: #technology #noise
---
# Software
http://www.somewhere.com
http://www.somewhereelse.com
# Apps
http://www.othersomewhereelse.com

Is it possible to extract the links into a table with its heading?

Hi, If the name of your daily note is the today date, you could use:

.where(p => p.file.ctime.toFormat('yyyy-MM-dd') == dv.current().file.name)

As @dryice said, to keep the dataview table static you need to convert the dataview table to a Markdown table, you could use Dataviewjs script for creating Markdown table. Then copy the table at the end of the day. I think there is not an automatic solution for this.

I shared a snipped a few days ago that could be useful to you, you can find it here:

2 Likes

I do something similar as my first task the following morning: take the results of a “new notes prior to today” data view query, copy/paste into a static block and done. Kind of a pain and frankly I’m not sure how useful it has proven to be,.

This is awesome. I’m assigning it to a hotkey, and planning to overhaul my vault around this kind of view.

I’ve been playing with Obsidian for almost a year and still don’t understand all the fuss about MOCs, if they aren’t automatically/dynamically generated. A lot of maintenance to add everything to an MOC and keep it up-to-date, ain’t it? (Compared to just tagging and knowing it will be in the the right place when I look for it). A manually generated table of contents seems like a step backwards in a world of databases.

I inline tag certain tasks with #WaitingFor. These are things that I need done but are dependent on someone else; the ball’s in their court.

In my Daily Note, I’m currently making use of the following query for listing all my tasks:

TASK
FROM ""
WHERE !completed and file.name != "Daily Note Templater"
GROUP BY created
SORT DESC

I’d like to create a new heading in my Daily Note that shows only what I’m #WaitingFor while filtering out #WaitingFor from the query above.

What would this new query that lists only tags with #WaitingFor look like? I’m able to produce the following below, but this only gets me a table of the notes where the tag #WaitingFor is present. I’m looking for a LIST like the above query, but only displaying #WaitingFor.

TABLE file.ctime AS "Created" FROM #WaitingFor
SORT DESC
3 Likes

Hi,

I found this snippet below, that creates a dynamic link to daily note:

`="[[" + dateformat(date(today), "dd-MM-yyyy-EEE") + "]]"`

and it works great on my laptop that is in English, so that today’s date for an example is displayed as 10-03-2022-Thu. Problem is that my phone is in Finnish and even though Obsidian is set in English, the same code creates link to 10-03-2022-To as in “Torstai”.

Is there a way to set locale to English?

Thanks!

1 Like

How to change “dd-MM-yyyy-EEE” to return link to my daily note’s date style of “YYYY_MM_DD”?

Asked, then answered muhself!

FWIW

="[[" + dateformat(date(today), "dd-MM-yyyy-EEE") + "]]"
Shows: 10-03-2022-Thu

="[[" + dateformat(date(today), "yyyy_MM_dd") + "]]"
Shows: 2022_03_10

Dataview date syntax treats “YYYY” as… Well… “YYYY”.

Needz “yyyy” for “2022”

Woot!

1 Like

Yeah, this is exactly what I needed. Thx!

Try this, it uses dataviewjs instead of dataview but I think gets you what you are looking for

dv.taskList(dv.pages().file.tasks.where(t => !t.completed && t.text.includes("#WaitingFor")))

Hope that helps
Don

2 Likes

It seems like the only way to do this is with:
" ```query
tag:BookSumText

"
But I would like to sort and query by the Author and other metadata.

Easy ad-hoc symptom tracker in daily notes:

Hi, hope this is the right place for this kind of thing. Just getting over a bout of COVID over here and thought it would be useful to document my symptoms. In my daily notes I simply inlined:

symptoms:: here are my symptoms in one line

And then in a folder note, I later wrote this query:

list link(rows.file.link, rows.symptoms)
from "3 Resources/obsidian_assets/daily_notes"
group by dateformat(file.day, "DDDD") as Date
where any(rows.symptoms)
sort rows.file.ctime desc

Turns out this very simple list with bonus link to the daily note if I need to refer to anything else.

image

18 Likes

Brilliant. And open to other uses.

Thanks for sharing.

Hope you make a swift and full recovery.

Angel

Wonderful! Thanks!

Found one issue: The snippets kind of breaks when the inline contains a link. Any idea how to resolve that?

Interesting. Are you using a URL or an internal [[ ]] link? I think if it’s a URL like so:

URL:: http://www.example.com

you can just use an “elink” function:

list elink(rows.URL, "display text")
from "3 Resources/obsidian_assets/daily_notes"
group by dateformat(file.day, "DDDD") as Date
where any(rows.URL)
sort rows.file.ctime desc

Otherwise, I think it works for both uses cases if you just omit the function altogether:

list rows.URL
from "3 Resources/obsidian_assets/daily_notes"
group by dateformat(file.day, "DDDD") as Date
where any(rows.URL)
sort rows.file.ctime desc
2 Likes

I would love to use something like this for my bookrec:: inline, but I seem to be doing something wrong. Any ideas?

list link(rows.file.link, rows.bookrec) 
from "Daily Notes" 
group by dateformat(file.day, "DDDD") as Date 
where any(rows.bookrec) 
sort rows.file.ctime desc

That is really helpful. Is there a way to calculate the age as well with this method?