Tags to Wiki-Style Cross-Links

Tags to Wiki-Style Cross-Links - can this be done?

Objective: Run an action that will, based on selected “tag” - gather all Drafts titles in “Wiki-Style Cross-Linking” format and add these wikilink titles to the clipboard.

Looks like this:

  1. Invoke action (Let’s call it Tags to Wikilinks)
  2. Pop up calls for tag
  3. Enter desired tag
  4. Action collects all Drafts assigned to desired tag
  5. Converts said tagged Drafts titles to Wikilink format
  6. Places wikilinks in clipboard, 1 per line

Example:
3 Drafts with the tag: “coffee”

Drafts with tag “coffee” are:
Starbucks cafe latte
Nespresso espresso
Learn to make a longo

Tag “coffee” is entered at the start of the action.

Output is:
[[Starbucks cafe latte]]
[[Nespresso espresso]]
[[Learn to make a longo]]

Not bad to do. Below example shows the query and construction of the result. It has a hard coded tag name, but could be extended to get that tag value from a prompt:

// tag to lookup. could be gathered from prompt...
let tag = "my-tag";
// query for drafts with that tag...
let taggedDrafts = Draft.query("", "all", [tag]);
// setup var to store titles
let titles = [];

// loop over drafts, adding each title to results
for (let d of taggedDrafts) {
	titles.push(d.processTemplate("[[display_title]]"));
}

// turn titles into wiki-linked titles
titles = titles.map(t => `[[${t}]]`);

// create result string and put it in clipboard
let results = titles.join("\n");
app.setClipboard(results);
2 Likes