Index of every page on this site: llms.txt
TypeScript
Hooks

tags:beforeResolve Hook

The tags:beforeResolve hook is the first of three synchronous tags:* hooks. It runs after entry normalization, weighting, deduplication, title-template resolution, and conversion of the deduplication map back into ctx.tags.

Hook Signature

export interface Hook {
  'tags:beforeResolve': (ctx: TagResolveContext) => SyncHookResult
}

interface TagResolveContext {
  tagMap: Map<string, HeadTag>
  tags: HeadTag[]
}

Parameters

NameTypeDescription
ctx.tagsHeadTag[]Current deduplicated tag array
ctx.tagMapMap<string, HeadTag>Deduplication lookup built by the resolver

This hook is synchronous. Mutate or replace ctx.tags to change the tags that continue through resolution. Adding or deleting a tagMap entry alone does not rebuild ctx.tags.

Prefer ctx.tags when walking the complete result. Arrayable meta groups may use an array-like aggregate in tagMap at runtime even though the public lookup type is Map<string, HeadTag>.

Usage Example

import { defineHeadPlugin } from 'unhead/plugins'

export const markExternalScriptsPlugin = defineHeadPlugin({
  key: 'mark-external-scripts',
  hooks: {
    'tags:beforeResolve': ({ tags }) => {
      for (const tag of tags) {
        if (tag.tag === 'script' && /^https?:\/\//.test(tag.props.src))
          tag.props['data-external'] = ''
      }
    }
  }
})
Did this page help you?