dalcantara7 / obsidian-auto-moc

GNU General Public License v3.0
40 stars 1 forks source link

Feature Request: build list based on linked heading #4

Closed naarcissus closed 2 years ago

naarcissus commented 2 years ago

I want to generate lists made up of file links that refer to a specific heading in the current file. Example: Filename = Filename

# Lists
## List

Then: Files with [[Filename#Lists]] and [[Filename#List]] are listed under their specific headings. Alternatively, to work similar to how it does currently, the plug-in checks to see which subheading the cursor is under, then lists the links that refer specifically to that heading. Might work best as a togglable option.

dalcantara7 commented 2 years ago

Could you give me a concrete example of how this should work? Something with real file/heading names. I'm not sure I understood from the example above.

naarcissus commented 2 years ago

Well, for my situation, I'm writing a story and using obsidian as a character and organization DB, basically. Each organization has ranks, so I list headings for each rank in the organization roster. Then on the character bios, I list which organizations they are a part of and what rank they are, but rather than have two links or tags for this(or separate files for each), I combine them into a single link, for example: [[Resistance#Captain]] Which when hovered over in view mode, brings up a small window that displays the contents of that heading in the Resistance file, handy for seeing who else is there. So what I want from AutoMOC is when I place my cursor under a heading, it not only notes the file the cursor is in, but the heading under which it is currently placed, then when building the list, it only includes links to that specific heading and not say, [[Resistance#infantry]], and places them into the list. So given these links: [[Resistance#Captain]] in the file Doe, John and [[Resistance#Leader]] in Doe, Jane, when I place the cursor under the Captain heading in the Resistance note and start AutoMOC, I end up with

# Resistance
## Leader
## Captain
[[Doe, John|John Doe]]
## Infantry

Rather than:

# Resistance
## Leader
## Captain
[[Doe, Jane|Jane Doe]]
[[Doe, John|John Doe]]
## Infantry

Does that make sense?

Note: In a perfect world, this would be automagic and would occur when I made the link in the first place…. 🤷‍♂️

naarcissus commented 2 years ago

A bit of a different approach I just thought of would be to find all the back links to the file, then note the #heading in each link, then just populate each of the headings in the current file with the appropriate links(maybe even adding headings based on link?), placing links without headings under than main, # (H1) heading or something. Though I could see this running into issues with messing with some people's organization or something. Doing it individually might be the better way, for now.

dalcantara7 commented 2 years ago

So let me make sure I'm understanding. This example is based off your first reply. The files that are to be linked to have the headings in their file

File: Jane Doe some info about jane Heading 1 some other info Heading 2 Heading 3

Then in the file you are calling AutoMOC from you have Heading 1 Heading 2

So the result for the file after AutoMOC would be: Heading 1 [[Jane Doe]] Heading 2: [[Jane Doe]]

Does that track with what you're looking for?

P.S. The same example for your second suggestion would result in the same thing except if your cursor was under heading 1 then

Heading 1: [[Jane Doe]] Heading 2:

since it only applies for the heading it is under.

naarcissus commented 2 years ago

Ah, forgot that the links don't necessarily track a heading path, though [[file#heading1#heading2]] can be done and is valid, though when hovered over, only previews the last heading, heading2 in this example, so having AutoMOC work from the top of a file and work it's way down, filling out the headings could be problematic since sub-heads of two different sections of the same file can have the same name….

Anyway, I think you've misunderstood, so I'll try again. Going forward, I'm going to refer to the note that we are populating with links as the "list file". Then, I'll refer to the notes that link to it as "source files". Using my example above, we'll make a simple file structure ("▼" denotes a folder):

▼characters
 Doe, Jane
 Doe, John
▼groups
 Resistance

Okay, now the contents of the Source Files, "Doe, Jane" and "Doe, John":

#Doe, Jane
A woman with a plan and other great and wonderful things or something.
## Associated Organizations
[[Resistance#Leaders]]
#Doe, John
A supportive dummy.
## Associated Organizations
[[Resistance#Captains]]

And now the contents of the List File, "Resistance":

#Resistance
A world super-power that controls everything worth anything.
## Leaders

## Captains

"Resistance" is the file where we are making our lists. As it works now, if I place the cursor under the ##Captains heading and activate AutoMOC, here is the result:

#Resistance
A world super-power that controls everything worth anything.
## Leaders

## Captains
[[Doe, Jane]]
[[Doe, John]]

What I want to happen is: placing the cursor under the ##Captains heading as described, then activating AutoMOC, I get this:

#Resistance
A world super-power that controls everything worth anything.
## Leaders

## Captains
[[Doe, John]]

"Doe, Jane" is not listed because it's link ([[Resistance#Leaders]]) refers to a different heading. The idea is to collect the links that refer to that specific heading of that specific note. The headings in the Source Files are irrelevant, only the links matter. https://help.obsidian.md/How+to/Internal+link#Link+to+headings Just to clarify what I mean by links that point to headings.

dalcantara7 commented 2 years ago

Okay thanks, that example clears it up. For me this becomes a question of "how broadly useful is this feature?" This seems like a rather specific use case. It's also not trivial to implement. It would require a good amount of reworking to incorporate this.

I also see this being easy to work around by importing all the missing links at the bottom of your note and then manually moving them into place under their appropriate heading. This is how I tend to use the plugin now.

This might be a case of "close as won't fix" (at least for now). If the plugin gains some traction and there is demand for it more broadly, then it may be worth the work to implement.

naarcissus commented 2 years ago

Ah, okay, kinda figured it would end up that way as I considered some of the irregularities with linking to headings. Thanks for considering it.

dalcantara7 commented 2 years ago

Sure thing. Thanks for the suggestion. Going to close this for now, but if others come across it, please comment and let me know if there is demand for this feature.