UNPKG

metafy-seo

Version:

Lightweight, SSR-safe React components and utilities for managing SEO metadata. Supports Next.js App Router, Vite, and any React environment.

116 lines (115 loc) 2.97 kB
/** * Next.js specific utilities for metafy-seo * * These helpers generate metadata objects compatible with: * - Next.js 14+ App Router `export const metadata` * - Next.js `generateMetadata()` function * * @example * ```tsx * // app/page.tsx * import { generateNextMetadata, blogPostPreset } from 'metafy-seo/next' * * export const metadata = generateNextMetadata(blogPostPreset({ * title: 'My Blog Post', * description: 'A great article', * slug: '/blog/my-post', * author: 'Nigel', * datePublished: '2025-01-01' * })) * ``` */ import type { SeoConfig } from './types'; /** * Next.js Metadata type (subset of what Next.js accepts) * Full type available from 'next' package */ export interface NextMetadata { title?: string | { default: string; template?: string; }; description?: string; robots?: string | { index?: boolean; follow?: boolean; }; viewport?: string | { width?: string; initialScale?: number; }; themeColor?: string; authors?: Array<{ name: string; url?: string; }>; publisher?: string; alternates?: { canonical?: string; languages?: Record<string, string>; }; openGraph?: { type?: string; siteName?: string; title?: string; description?: string; url?: string; images?: Array<{ url: string; alt?: string; width?: number; height?: number; }>; locale?: string; article?: { publishedTime?: string; modifiedTime?: string; authors?: string[]; section?: string; tags?: string[]; }; }; twitter?: { card?: 'summary' | 'summary_large_image' | 'app' | 'player'; site?: string; creator?: string; title?: string; description?: string; images?: string | string[]; }; icons?: { icon?: string | string[]; apple?: string | string[]; shortcut?: string; }; verification?: { google?: string; yandex?: string; other?: Record<string, string>; }; other?: Record<string, string>; } /** * Convert a metafy-seo SeoConfig to Next.js Metadata format. * * @param config - The SEO configuration object * @returns A Next.js compatible Metadata object * * @example * ```tsx * // app/page.tsx * import { generateNextMetadata } from 'metafy-seo' * * export const metadata = generateNextMetadata({ * title: 'My Page', * description: 'Page description', * canonical: '/my-page' * }) * ``` */ export declare function generateNextMetadata(config: SeoConfig): NextMetadata; /** * Type-safe helper for creating Next.js metadata with autocomplete. * Simply re-exports generateNextMetadata for semantic clarity. */ export declare const createMetadata: typeof generateNextMetadata;