query to extract external urls and their tags

i'm looking for a way to list all external urls present in my notes, along with any tags associated with the block where the link is located.

i want to create a table where one column is the url itself and the other is the list of tags.

any examples would be greatly appreciated.

1 Like

It may well be that external links are currently not indexed. This was actually on my list of things to check and fix. I’ll get back to this tomorrow.

2 Likes

Confirmed, they weren't indexed before, I've now fixed this: Enhance link indexing to support additional link types · silverbulletmd/silverbullet@40895ad · GitHub

will be on the edge builds in a few minutes and part of the next release.

2 Likes

great to hear! thanks for the update. i started using silverbullet yesterday, evaluating if i can move over from capacities.io.

being able to easily filter weblinks is a huge part of my workflow.

with your changes, is there a simple way to list links as special tags (like weblink instead of just link)? or what would be the best way to query only weblinks and filter them by specific tags?

for example: how would i list only weblinks that also have a "tools" tag?

1 Like

I'm not sure what you mean with a link "having" a tag? If you mean tags inherited from the page itself then you can filter based on the itags attribute.

From the commit I pointed to link objects will have a type attribute, which is either page (for page links), file (for links to documents) or url for external link. So you'll want to filter on the latter:

query[[from l = tags.link where l.type == "url"]]

if you want to only want to list external links that appear on pages tagged with sometag you can do:

query[[
  from l = tags.link
  where l.type == "url" and table.includes(l.itags, "sometag")
]]

Again, this hasn't been released yet, so you'll have to use the edge builds and then perform a Space: Reindex to rebuild the index.

1 Like

thanks for the clarification, zef!

regarding the tags, i was thinking about tags on the same line or block as the link, rather than page-level tags.

for example, if i have a line like: silverbullet #tools #notes

my intention is to query all external links that are "contextually tagged" with #tools or #notes, even if the page itself has different tags.

1 Like

Ok, that is not supported right now. The challenge here is that it's already quite tricky to determine what a tag should apply to, here are the current rules: Hashtags

This means that in your example the tags would be applied to the paragraph not the link.

2 Likes