Giter VIP home page Giter VIP logo

Comments (17)

zachdaniel avatar zachdaniel commented on June 4, 2024 3

For anyone else that ends up here, I used the recommendation above to build a dataviewjs block that brings in the list of quotes of my files tagged w/ people (which use a template that adds a quotes section using the comment delimiters I refer to in the snippet:

let quotesPromises = dv.pages("#people").map(async (p) => {
  const link = p.file.link;
  return await dv.io.load(p.file.link).then((contents) => {
    const indexOfQuotes = contents.indexOf("<!-- quotes -->");
    if (indexOfQuotes > 0) {
	  const quoteStart = contents
	    .substr(indexOfQuotes + 16)
		
	  const quotes = quoteStart.substr(0, quoteStart.indexOf("<!-- end quotes -->")).trim();
	  
	  if (quotes === "") {
	    return [];
	  } else {
	    return quotes.split(">").map(q => q.trim()).filter((q) => q !== "").map((quote) => [p.file.link, quote]);
	  }
	} else {
	  return []
	}
  });
});

let quotes = (await Promise.all(quotesPromises)).flat().filter((q) => q.length > 0);

dv.table(["Author", "Quote"], quotes);

Which yields something like this:
CleanShot 2021-10-31 at 01 54 11

from obsidian-dataview.

blacksmithgu avatar blacksmithgu commented on June 4, 2024 2

Interesting idea. I am planning on adding a "embed query", where you can query for sections / blocks / whatnot and they will render similarly to if you had done a bunch of manual ![[]] embed statements, which will get part of what you want.

Editing in place sounds cool, though would be difficult (dataview generally works where you write the query in edit mode, and view the result dynamically in preview mode). It might be possible via a custom view (i.e., a "query" view where you type in a query at the top and you can view results at the bottom), though that would be further in the future.

from obsidian-dataview.

pjeby avatar pjeby commented on June 4, 2024 1

Editing in place sounds cool, though would be difficult (dataview generally works where you write the query in edit mode, and view the result dynamically in preview mode). It might be possible via a custom view (i.e., a "query" view where you type in a query at the top and you can view results at the bottom), though that would be further in the future.

I didn't mean that; I meant editing the contents of the sections or blocks, with the dataview being a window onto the underlying files, so that it'd be like a spreadsheet view of parts of my notes. But being able to click on the embeds to open the relevant note sections in another pane would be a good substitute.

from obsidian-dataview.

pjeby avatar pjeby commented on June 4, 2024 1

Yeah, that's not really what I had in mind, which was more to either 1) query list items from all headings with a certain name across all files containing that heading, or 2) generate a TABLE query and put the contents found under a heading (list or otherwise) as one of the columns. For example, if I had a bunch of notes with headers (or block IDs) A, B, and C, then being able to generate a table that showed a row for each note with columns A, B, and C containing the rendered contents under those headings (or block IDs).

In other words, the goal wasn't to query all list items in a note and then filter or group them by section, but to extract specific blocks or sections from queried notes and render them in a dataview table, with the entire list (or other block/section contents) embedded in a column, as though the heading were a dataview field.

from obsidian-dataview.

pjeby avatar pjeby commented on June 4, 2024 1

It would be best if sections were just inline fields whose values could be a list or markdown. So that would be more like they just exist as top level properties (e.g. file["some section"]), especially if they were something that the table rendering was smart enough to turn back into a list in the cell (and the query language allows you to name fields that way, I guess).

Anyway, the main goal is that it should be easy to write a non-JS table query that puts the contents of a named file sections into different table cell. It'd be ideal if that was a single step like file["some section name"], where the section name uses kebab-casing internally to match the heading. (Both of your examples are using lists rather than maps, which means you have to write a loop for every such column you want to create, vs file{"section A"], file["section B"] to create two columns in a table query.

from obsidian-dataview.

NearlCrews avatar NearlCrews commented on June 4, 2024

@blacksmithgu quick question on this:

Interesting idea. I am planning on adding a "embed query", where you can query for sections / blocks / whatnot and they will render similarly to if you had done a bunch of manual ![[]] embed statements, which will get part of what you want.

I've got a bunch of notes structured like this, with the file name being an account name:

##### 2020-04-29
- This is a note.
- This is another note.

I generate reports from Obsidian by using a manually structured table. One of the cells includes a link to the most recent section, e.g. ![[That Account#2020-04-29]], which embeds the notes from that section directly into the report. Would the feature you mentioned above replicate that behavior? That's currently the only item holding me back from converting everything over to Dataview. I just wanted to make sure before opening a FR: no reason if it's already planned.

Thanks and keep up the great work!

from obsidian-dataview.

zachdaniel avatar zachdaniel commented on June 4, 2024

Is there any way at all to access the contents of a file using data view? I don't even mind having to write a regex or something to do it, but it would be awesome if possible.

from obsidian-dataview.

blacksmithgu avatar blacksmithgu commented on June 4, 2024

You can use await dv.io.load(path|link) using DataviewJS, though it is not supported in Dataview currently.

from obsidian-dataview.

zachdaniel avatar zachdaniel commented on June 4, 2024

ohhh, nice let me try that out :) I've ended up using dataviewjs instead of dataview in most places since I know js anyway.

from obsidian-dataview.

zachdaniel avatar zachdaniel commented on June 4, 2024

One other thing that would be amazing is if there was some way to use dv.io.load(link) and get a specific heading. I'm trying to iterate over files and get a specific heading out of each of them, so I don't see a way currently to go from file link to file + heading link.

from obsidian-dataview.

zachdaniel avatar zachdaniel commented on June 4, 2024

This prevents me from needing to regex a markdown heading.

from obsidian-dataview.

AB1908 avatar AB1908 commented on June 4, 2024

You can now query list items under specific section headings. Does that fulfill the original ask?

from obsidian-dataview.

pjeby avatar pjeby commented on June 4, 2024

You can now query list items under specific section headings.

How? I just checked the DQL reference and didn't see anything for that. The only reference to sections I found was in relation to TASK queries, which doesn't handle plain list items (or text)?

from obsidian-dataview.

AB1908 avatar AB1908 commented on June 4, 2024

Can be found under the file.lists object and you can inspect list items to see that they now have a section attribute.

from obsidian-dataview.

blacksmithgu avatar blacksmithgu commented on June 4, 2024

@pjeby From an API perspective, would you prefer the section data to be:

  1. directly inline in the results, like:
{
  file: {
    sections: [
       { name: ..., }
    ]
  }
}
  1. or as links which are de-referenced into section objects, such as:
{
  file: {
    sections: [
      [[File#Section 1]],
      ...
    ]
  }
}

from obsidian-dataview.

JeppeKlitgaard avatar JeppeKlitgaard commented on June 4, 2024

I would be very interested in having access to sections as well. For my use-case having a list of sections with their name and content in file.sections would be sufficient, similar to the first suggestion mentioned here: #29 (comment)

from obsidian-dataview.

d0020002 avatar d0020002 commented on June 4, 2024

Does this possible now?

from obsidian-dataview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.