blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
6.97k stars 410 forks source link

Transclusion of links #57

Open Gnopps opened 3 years ago

Gnopps commented 3 years ago

Thanks for developing this plugin!

Would it be possible to have the results published transcluded? So instead of the list produced being [[File_name]] it would be ![[File_name]].?

blacksmithgu commented 3 years ago

It would probably be a different view (maybe a list view, or a 'transcude view?'), but yes, definitely possible.

erichalldev commented 3 years ago

I'm very interested in this as it would replace a chunk of my workflow I've written some custom code for. It looks like the infrastructure is there based off what I see in this function: https://github.com/blacksmithgu/obsidian-dataview/blob/067ca4d5faffb83c6e5558df9ba3ddf6efca438a/src/data/value.ts#L75

I might take a stab at implementing this if I find the time.

QuaCKeReD commented 2 years ago

Hi,

This is exactly what I am looking for, as a replacement for 'Text Expander' (since the CM6 move broke it)

Has there been any activity on reaching this goal?

Thanks Mark

AB1908 commented 2 years ago

Could you explain how this is related to text expander?

QuaCKeReD commented 2 years ago

Could you explain how this is related to text expander?

I currently use text expander to transclude a list of files. DV can provide the list of links, but not the β€˜!’ to transclude them.

AB1908 commented 2 years ago

Oh yeah, hmm. I imagine this is doable in DVJS though. Could also hook it up to templater to provide the list at runtime but it's quite hacky IMO.

QuaCKeReD commented 2 years ago

If you could point me in right direction... πŸ˜›

Haven't figured out how to change the output formatting of DVJS 😟

AB1908 commented 2 years ago

The general idea is that you could find the files you need with some DVJS and then output or append them to current file with Obsidian's API. For example:

let tfile = app.vault.getAbstractFileByPath("path/to/file");
let output = dv.pages("#test").file.name.map(t=>`![[${t}]]`).join("\n");
await app.vault.append(tfile, output);
QuaCKeReD commented 2 years ago

Above kept erroring, so worked and got this

dv.list(
  dv.pages('"Diary" AND #test')
  .file.name
  .map(t=>`![[${t}]]`));

which does transclude the first file, but then rest just show as file names. Tried it using file.link and !${t}, with same result 😟

QuaCKeReD commented 2 years ago

This works!

dv.list(
  dv.pages('"Diary" AND #test')
  .forEach(p => dv.paragraph(dv.fileLink(p.file.name, true)))
);
Gnopps commented 2 years ago

I've created a slightly different workaround using dataviewjs. See the last line in the code below.

let meetings = dv.current().file.inlinks
meetings = meetings.sort(k => dv.page(k).date, 'desc')
for (let meeting of meetings){
if (dv.page(meeting).file.tags.indexOf("#meeting")>-1){
dv.el("p", "![[" + dv.page(meeting).file.name + "]]");}
}
blacksmithgu commented 2 years ago

Embed links seem to situationally work, and I've had better luck with them in DataviewJS than in Dataview for whatever reason.

autolyticus commented 2 years ago

Hello, this still seems to be completely hit-or-miss for me after trying all the above methods (and playing around with dv.sectionLink and dv.fileLink with embed=true). I don't know if it's because of the live editor, but the embeds just seem to show the file name in plain text (not even as a link)

AB1908 commented 2 years ago

What's your use case?

blacksmithgu commented 2 years ago

Nothing has really changed Obsidian-side w.r.t. being able to do embeds; there isn't much I can do in Dataview aside from manually trying to re-implement some common use cases like image embedding (via embed(link(...))).

AB1908 commented 2 years ago

I found a good example of this over in SRS. Happy to help anyone walk through implementing that but I expect it won't work with live preview.

QuaCKeReD commented 2 years ago

Hi, Yes, please, would love to see how this can be done.

PS: No idea what SRS is? πŸ˜›

AB1908 commented 1 year ago

I've seen a transclusion implementation here: https://github.com/st3v3nmw/obsidian-spaced-repetition/blob/80af505c082495e1956ca5aad11ddbe90c495af3/src/flashcard-modal.tsx#L418

stoweboyd commented 1 year ago

My use case is this:

  1. I create a topical kanban file, and add metadata to the yaml, like 'ΓΈ: work futures' to represent a project name and 'ΓΈΓΈ: meritocracy' to demote a subproject. These attributes are inherited by all tasks in the kanban. So far so good.
  2. The kanban tasks -- generally -- created in place as tranclusions, like ![[2022-09-17 pamela paul - when diversity isnt the right kind of diversity#^d88bdc]], which resolves in the kanban and markdown views.
  3. If I create a dataview query to find all tasks with those project and subproject attributes it 'works' -- the kanban tasks are all listed -- but the transclusions are not resolved:

2022-11-02 meritocracy dataview

I can click through on a task which takes me to the kanban task. Fine. And it is resolved there. But what might be best would be a dataview directive to same 'please resolve transclusions in the results'.

blacksmithgu commented 1 year ago

I've seen a transclusion implementation here: https://github.com/st3v3nmw/obsidian-spaced-repetition/blob/80af505c082495e1956ca5aad11ddbe90c495af3/src/flashcard-modal.tsx#L418

I guess I can just steal this embedding magic wholesale inside the Dataview renderMarkdown function.

AB1908 commented 1 year ago

I really wish Obsidian included a cleaner way of rendering embeds but this works for now. It took me quite a while to understand what was happening there haha.

QuaCKeReD commented 1 year ago

ooo, is it ready for testing?

AB1908 commented 1 year ago

No, not yet. Keep an eye on the releases for updates.