getPathRobotConfig()
See if the Site is indexable within Nitro.
Nuxt SEO Pro
- Nuxt Redirects
- Nuxt Google Search Console
- Nuxt Internal Links
- Nuxt SEO Analyze
Save $170 on the presale now.
Introduction
The getPathRobotConfig()
Nitro composable gives you access to the page robots config, allowing you
to determine if the page can or can't be indexed and why.
This can be useful for disabling certain SEO features when the page does not allow for indexing. For example, Nuxt SEO uses this internally to disable OG Images when the page is not indexable.
Signature
type getPathRobotConfig = (e: H3Event, options?: { userAgent?: string, skipSiteIndexable?: boolean, path?: string }) => { rule: string, indexable: boolean, debug?: { source: string, line: string } }
Arguments
e
(H3Event
): The event object.options
(object
): Optional options.userAgent
(string
): The user agent to use for the check. Some pages may have different rules for different user agents.skipSiteIndexable
(boolean
): Skip the site indexable check. Allows you to check the page indexable while ignoring the site-wide config.path
(string
): An override for which path to check. By default, it will use the current path of theH3Event
.
Returns
rule
(string
): The rule for the page.indexable
(boolean
): Whether the page is indexable.debug
(object
): Debug information about the source of the rule and the line number in the source file. This is only available in development mode.
Example
server/plugins/strip-og-tags-maybe.ts
import { getPathRobotConfig } from '#imports'
export default defineNitroPlugin((nitroApp) => {
// strip og meta tags if the site is not indexable
nitroApp.hooks.hook('render:html', async (ctx, { event }) => {
const { indexable } = getPathRobotConfig(event)
if (!indexable) {
ctx.html = ctx.html.replace(/<meta property="og:.*?">/g, '')
}
})
})
Did this page help you?