kpumuk / meta-tags

Search Engine Optimization (SEO) for Ruby on Rails applications.
MIT License
2.73k stars 275 forks source link

Support additional mirrored values #236

Closed AxelTheGerman closed 2 years ago

AxelTheGerman commented 2 years ago

Besides only checking the normalized meta tags for mirrored values we can also check the plain meta_tags attribute. This supports, e.g. setting the og:url meta tag to the value of the canonical_link meta tag.


Let me know what you think - I came across this today as I was trying to achieve exactly this, setting the og:url to the canonical_link as I was already setting that.

kpumuk commented 2 years ago

Technically, your particular use-case can be implemented using canonical link:

display_meta_tags(canonical: 'https://google.com', og: { url: :canonical })

# <link rel="canonical" href="https://google.com">
# <meta property="og:url" content="https://google.com">

https://github.com/kpumuk/meta-tags#canonical-url

kpumuk commented 2 years ago

The idea is interesting, but the implementation introduces an inconsistency in the library.

When I call set_meta_tags(something: 'something-else'), I expect a meta tag <meta name="something" content="something-else"> (see Custom meta tags. After the change, the tag will be "consumed" by a nested custom meta tag (aka "og:url") - only because the hashes are processed before non-nested tags (which is an implementation detail, and can change at any moment).

AxelTheGerman commented 2 years ago

@kpumuk thanks for taking the time to point me to the right solution! (And that my implementation actually "consumes" the tag)

And thanks for this great library!