Action
Backlinks
Posted by Short Meeting,
Last update
about 3 years ago
- Unlisted
Steps
-
script
let title = draft.displayTitle; if (title.length == 0) { app.displayErrorMessage("This Draft has no title!"); } // query for other drafts with the link to this one... let pattern = `"[[${title}]]"`; let drafts = Draft.query(pattern, "all", [], [], "modified", true); // didn't find any! if (drafts.length == 0) { app.displayInfoMessage("No backlinked drafts found."); context.cancel(); }else{ let backlinks = []; for(let draft of drafts){ //Add with a "d:" otherwise the inserted backlink matches as a wikilink and around the circle we go... backlinks.push("[[d:" + draft.displayTitle + "]]"); } let result = draft.content.match(/((#+\sBacklinks)[\s\S]\s*(\[\[.*?\]\][\s\S])*)/); if(result == null){ draft.content = draft.content + "\n## Backlinks\n\n" + backlinks.join("\n"); draft.update(); }else{ let tobereplaced = result[1]; let blTitle = result[2]; draft.content = draft.content.replace(tobereplaced,blTitle + "\n\n" + backlinks.join("\n") + "\n"); draft.update(); } }
Options
-
After Success Nothing Notification None Log Level None
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.