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

entries:normalize Hook

The entries:normalize hook runs once for each uncached entry after its input has been normalized into tags. It runs before Unhead assigns internal weights and deduplication keys.

At the start of resolution, Unhead compares the combined number of entries:resolve and entries:normalize listeners with the previous resolution. If that count changed, it clears every entry's normalization cache. Uncached entries pass through this hook once, then remain cached until their input changes or a later listener-count change invalidates them.

Hook Signature

export interface Hook {
  'entries:normalize': (ctx: {
    tags: HeadTag[]
    entry: HeadEntry<any>
  }) => SyncHookResult
}

Parameters

NameTypeDescription
ctx.tagsHeadTag[]Tags normalized from this entry
ctx.entryHeadEntry<any>The entry that produced the tags

This hook is synchronous. You may mutate ctx.tags in place or replace it with another array.

Usage Example

import { defineHeadPlugin } from 'unhead/plugins'

export const descriptionPrefixPlugin = defineHeadPlugin({
  key: 'description-prefix',
  hooks: {
    'entries:normalize': ({ tags }) => {
      for (const tag of tags) {
        if (tag.tag === 'meta' && tag.props.name === 'description')
          tag.props.content = `Preview: ${tag.props.content}`
      }
    }
  }
})

HeadEntry fields whose names begin with _ are internal. Avoid storing plugin state on them.

Did this page help you?