Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): canonical plugin #492

Merged
merged 3 commits into from
Feb 14, 2025
Merged

feat(core): canonical plugin #492

merged 3 commits into from
Feb 14, 2025

Conversation

harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Feb 13, 2025 β€’

πŸ”— 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/'
    })
  ]
})

Sorry, something went wrong.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Copy link
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
3 checks passed
@harlan-zw harlan-zw mentioned this pull request Feb 14, 2025
54 tasks
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.

None yet

1 participant