Hooks
entries:normalize Hook
On this page
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
| Name | Type | Description |
|---|---|---|
ctx.tags | HeadTag[] | Tags normalized from this entry |
ctx.entry | HeadEntry<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?
On this page