getPathRobotConfig()
See if the Site is indexable within Nitro.
Introduction
The
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.
API
function getPathRobotConfig(e: H3Event, options?: GetPathRobotConfigOptions): GetPathRobotResult
interface GetPathRobotConfigOptions {
userAgent?: string
skipSiteIndexable?: boolean
path?: string
}
interface GetPathRobotResult {
rule: string
indexable: boolean
debug?: { source: string, line: string }
}
Arguments
e: H3Event : The request event object, used to determine the current path.options : 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: boolean : 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?: { source: string, line: string } : 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 { defineNitroPlugin, 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?