Last active
July 9, 2025 05:10
-
-
Save Moyf/999276158867512893e76008aeb85616 to your computer and use it in GitHub Desktop.
搜索并插入标题链接
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%* | |
| // 这是个用于 Templater 插件的脚本模板吗,请保存到自己的库里,将后缀名修改为 md | |
| const headings = []; | |
| const headingDict = {}; | |
| const files = app.vault.getMarkdownFiles(); | |
| files.forEach(file => { | |
| let headingsInNote = app.metadataCache.getFileCache(file).headings; | |
| if (headingsInNote) { | |
| headingsInNote.forEach(heading => { | |
| if (heading.heading){ | |
| const headingStr = heading.heading; | |
| const headingDisplayText = `[#${headingStr}] | ${file.basename}`; | |
| const LinkContent = `[[${file.basename}#${headingStr}|${headingStr}]]`; | |
| const selection = { | |
| headingStr: headingDisplayText, | |
| LinkContent: LinkContent | |
| } | |
| // console.log(headingStr); | |
| headingDict[headingDisplayText] = LinkContent; | |
| headings.push(selection); | |
| } | |
| }); | |
| // headings.concat(app.metadataCache.getFileCache(file).headings); | |
| // console.log(app.metadataCache.getFileCache(file).headings); | |
| }; | |
| }); | |
| const userSelected = await tp.system.suggester( (item) => item.headingStr, headings) | |
| console.log(userSelected); | |
| tR += userSelected ? userSelected.LinkContent : ""; | |
| %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment