Create Notes for unresolved Links with Suggester #227
shabegom
started this conversation in
Templates Showcase
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This command shows a list of all links in a vault. If the link has a note associated with it, it opens that note. If not it creates the note. Adjust to suit your needs:
<%*
const files = await app.vault.getMarkdownFiles()
const links = []
const filesWithLinks = files.forEach((file) => {
const linksInFile = app.metadataCache.getFileCache(file).links
if (linksInFile) {
links.push(linksInFile)
}
})
const finalLinkArr = links.flat().filter((link, index, array) =>
array.findIndex(t => t.link === link.link) === index
).map(link => link.link)
const selection = await tp.system.suggester(finalLinkArr, finalLinkArr)
if (selection) {
const selectedFile = files.filter(file => file.name === selection + ".md")[0]
if (selectedFile) {
app.workspace.activeLeaf.openFile(selectedFile)
} else {
await app.vault.create(selection + ".md", "")
const newFile = app.vault.getAbstractFileByPath(selection + ".md")
app.workspace.activeLeaf.openFile(newFile)
}
}
%>
Beta Was this translation helpful? Give feedback.
All reactions