Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(core): canonical plugin#492

Merged
harlan-zw merged 3 commits into
mainfrom
feat/canonical-plugin
Feb 14, 2025
Merged

feat(core): canonical plugin#492
harlan-zw merged 3 commits into
mainfrom
feat/canonical-plugin

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Feb 13, 2025

Copy link
Copy Markdown
Collaborator

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Google requires your canonical URLs to use absolute paths. Facebook and Twitter will ignore images without a full URL. This plugin fixes both problems automatically
when you provide a relative path.

The plugin converts relative paths to absolute URLs in these tags:

  • og:image and twitter:image meta tags
  • og:url meta tag
  • rel="canonical" link tag

For example:

<!-- Before -->
<meta property="og:image" content="/images/hero.jpg">

<!-- After -->
<meta property="og:image" content="https://mysite.com/images/hero.jpg">

Setup

You should install the plugin in both your server & client entries.

import { CanonicalPlugin } from 'unhead/plugins'

const head = createHead({
  plugins: [
    CanonicalPlugin({
      canonicalHost: 'https://mysite.com/'
    })
  ]
})

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Size Gzipped Size Size Diff Gzipped Size Diff
Client 12.5 kB (12834 B) 5 kB (5157 B) 0.00% (0 B) 0.00% ( 0 B)
Server 9.9 kB (10111 B) 4 kB (4072 B) 0.00% (0 B) 0.00% ( 0 B)

@harlan-zw harlan-zw merged commit b1fd5ce into main Feb 14, 2025
@harlan-zw harlan-zw mentioned this pull request Feb 14, 2025
54 tasks
@harlan-zw harlan-zw mentioned this pull request Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant