Defining tags?

Hi Everyone,

I am trying to figure out if defining a tag that gets indexed automatically without adding the tag as text to the page / object is possible. For instance, I was surprised that external links aren’t included in the ‘link’ tag. (Note that that’s an example, I may want to do this for a host of other reasons, so an external link specific solution isn’t what I’m looking for.)

I can successfully query for them by looking in the text or name of objects for ‘http’. Is it possible to define a tag that gets indexed based on a function or some sort of schema? The index.defineTag adds to the metatable, can it be used to create a new tag altogether? Or there’s the “tagDefinitions” path in config that takes a spec, but how is the spec defined? I looked for examples in the GitHub but am at a bit of a loss right now.

Is it possible to define custom tags that get indexed the way “pages”, “tasks”, internal “links”, etc. or can you only create tags by adding them to frontmatter or in the page?

Thanks for any help.

This is actually a good point and I thought we did it, but just checked and we don’t — we only do if the [page](page) is used for internal links. Maybe something to add…

As to your bigger question, there is no straight forward way to do this at the moment. There is the page:index event you can hook into, and then use the index.indexObjects API to create objects yourself, but honestly I wouldn’t recommend it at the moment because page:index will give you a parse tree of the markdown document, which is near-impossible to manipulate from Space Lua right now. This is something I want to tackle at some point, but haven’t gotten there yet.

Anyway, the short answer is: you are not missing anything, there’s no obvious way to do this at the moment. If there’s sufficient demand and compelling use cases, I can definitely look at adding this though. Infrastructurally this can be supported, we’d just have to find an elegant way to do it.

Thanks so much for the reply. The “index.defineTag” naming kept making me think it was possible and now I can stop trying to make it work. :slight_smile: I think there are other ways to accomplish what I want to do anyway. For now I’ll look at writing a command that adds an “#elink” tag to external links.

1 Like