Closed svoop closed 1 year ago
Thanks for catching that! Hmm… seems like we'd want to add an extra filter to ensure the files are not coming from different origin paths.
I'm working around it with helpers:
# Return the canonical (not localized) URL
def canonical(url)
url.sub(%r{^/(?:#{I18n.available_locales.join('|')})/}, '/')
end
# Return the localized resources matching the given one
def localized_resources(resource)
canonical_relative_url = canonical(resource.relative_url)
resource.all_locales.select do |localized_resource|
canonical_relative_url == canonical(localized_resource.relative_url)
end
end
One ugly hack, but canonical URLs are really essential to do SEO right on i18nized sites. Even thought about monkey patching in resource.relative_canonical_url
and resource.absolute_canonical_url
for a second, but that's guaranteed to break sooner or later.
@jaredcwhite Since the all_locales
is fixed (thanks, @vvveebs !) – what do you think about the other idea mentioned above to add two methods to resources:
resource.relative_canonical_url
relative_url
of the canonical page (page of the primary locale) resource.absolute_canonical_url
absolute_url
of the canonical page (page of the primary locale) -> necessary for SEO with <link rel="canonical" href="<%= resource.absolute_canonical_url %>">
.In case you find this useful, I'd create a new issue for it. Cheers!
what do you think about the other idea mentioned above to add two methods to resources
@svoop Sure, if that's useful for SEO why not? If you could write up an issue that would be great. Thanks!
With two locales
:de
and:en
and given the following structure:Doing a
resource.all_locales
on any of the four resources will return an array of all four resources due to theselect
filtering by slug only:https://github.com/bridgetownrb/bridgetown/blob/1aef49d3ab34686f6cbc942572aa2093d515d072/bridgetown-core/lib/bridgetown-core/concerns/localizable.rb#L15
(I'm not quite sure whether this is a bug or the intended behavior clashing with how I organize my pages. However, it also happens if you have say two product subdirs each with
license.xx.md
.)Bridgetown Version: 1.1.0 (code unchanged in Main as of today)
To Reproduce
Current behavior The
select
filters by slug across all resources.Expected behavior The
select
should filter by slug across all resources of the same subdir only.Maybe add support for canonical URLs? Something along the lines of:
resource.relative_canonical_url
relative_url
of the canonical page (page of the primary locale) –> could be added to theselect
above.resource.absolute_canonical_url
absolute_url
of the canonical page (page of the primary locale) -> necessary for SEO with<link rel="canonical" href="<%= resource.absolute_canonical_url %>">
.