Function canonical

Generates canonical URL meta tags for the HTML head section.

Canonical URLs help prevent duplicate content issues by telling search engines which URL is the "official" version of a page. Also supports hreflang for international SEO.

import { canonical } from '@raven-js/beak/seo';

// Basic canonical URL
const tags = canonical({
domain: 'example.com',
path: '/my-page'
});
// Output:
// <link rel="canonical" href="https://example.com/my-page" />

// Canonical with hreflang
const hreflangTags = canonical({
domain: 'example.com',
path: '/my-page',
hreflang: 'en-US'
});
// Output:
// <link rel="canonical" href="https://example.com/my-page" hreflang="en-US" />

// Canonical for mobile
const mobileTags = canonical({
domain: 'example.com',
path: '/my-page',
media: 'only screen and (max-width: 640px)'
});
// Output:
// <link rel="canonical" href="https://example.com/my-page" media="only screen and (max-width: 640px)" />
  • Parameters

    • config: CanonicalConfig

      Configuration object for canonical tags

    Returns string

    The generated canonical meta tags as an HTML string