obsidian-dataview
obsidian-dataview copied to clipboard
Rename file links in queries when file is renamed
As the title describes, auto-rename file links that are in queries.
dataview
already autocompletes links when typing them out in a query, however when the file is renamed the link isn't renamed in the query. Obsidian automatically renames the link everywhere else though.
Query example:
WHERE project = [[Projects/P - Sample project]]
I'll have to see if I can hook into the existing renamer to also do codeblocks; as far as I'm aware, Obsidian intentionally skips frontmatter and codeblocks by default.
Thanks! I can imagine some people may want a switch to enable / disable this feature in the settings menu
Exactly what I need +1
Automatically renaming things inside Dataview scripts/queries sounds risky (it would need actual understanding of code structure), and also sounds like something that Obsidian doesn't even support (plugins are seemingly not notified about renamed files). So sure, the feature would be nice but sounds impossible at the moment.
Obsidian does change wikilinks if you rename the file or move it around but I agree that it's risky to do that in code. I wonder if Obs simply ignores wikilinks in code blocks.
Given that DV does parse the note contents, it does sound doable but then you'd need to support both wikilinks and markdown links and it honestly may be more trouble than it's worth. Perhaps a separate plugin could cover this and we could also request Obs to include this as a toggle-able setting?
As a possible workaround: You could extract the link to a inline field, so that the link is a proper content of the file and dataview will rename it for you while your query stays functional. Of course, that'd mean the link shows up in your graph.
queryKey:: [[Some project]]
```dataview
LIST
WHERE project = this.queryKey
```
As a possible workaround: You could extract the link to a inline field, so that the link is a proper content of the file and dataview will rename it for you while your query stays functional. Of course, that'd mean the link shows up in your graph.
queryKey:: [[Some project]] ```dataview LIST WHERE project = this.queryKey
the field can be made invisible with:
<span style="display:none">[ queryKey::[[Some project]] ]</span>
wthout "inline fields bracket syntax" does not work
I encountered this problem aswell and found my own solutien. I use these inline file links because I don't want them to appear on the graph. The direction in which I link my notes is very important because when a note links to it's parent, it is a dependency of that note. In other words the direction of links is a hirarchical dependency structure.
Here is my solution:
- I use templater to assign a unique identifier (YYMMDDhhmmss) to my notes
- Then I query this unique identifier:
dv.fileLink(dv.pages().where(p => p.note_id == 20230925104141)[0].file.path, false, "display")
There are a few caveats tho: If for some reason the ID of a note breaks I have no way of figuring out whether that note is linked somewhere.
My feature request therefor would be to allow the use of custom javascript snippets such as the ones that templater allows to use and in fact I use these a lot in my templates as I do a lot of scripting. Ideally I would want to be able to declare a simple function that I can use everywhere that is exposed through the dv
object that allows me to do some error handling or more advanced stuff such as including a smoll sqllite database. @s-blu @M-bot
EDIT: updated the query