Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GitMurf/56bcd1da7db082513878e73011c1da3f to your computer and use it in GitHub Desktop.
Save GitMurf/56bcd1da7db082513878e73011c1da3f to your computer and use it in GitHub Desktop.
When using headings with a [[page name]] in it, create a "search embed query" with all those headings expanded
<%*
const noteName = tp.file.title;
let queryKeyword = await tp.system.prompt("Keyword for Section search query (do NOT add [ ] brackets around it)", noteName);
if(queryKeyword) {
// Un-comment the next line if you want the keyword to require [] brackets around it for backlinks matching purposes
queryKeyword = `\\[\\[${queryKeyword}[\\|\\]]`; // the | pipe check accounts for alias links
tR = `
# Keyword Section Query
\`\`\`query
section:(/^#+ .*${queryKeyword}.*\\n+\\S[\\s\\S]*[^\\n]/) OR section:(/^#+ .*${queryKeyword}.*/ section:(/[\\s\\S]*[^\\n]/))
\`\`\`
`
} else {
return;
}
%>
@GitMurf
Copy link
Author

GitMurf commented May 30, 2022

Also keep in mind this is specifically for Headings / Section searches so will NOT show you ALL [[backlinks]] but only the ones where the [[backlink]] is in a Heading (and then all of the content below that Heading).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment