Skip to content

Commit

Permalink
Scope Localizable#all_locales under directory
Browse files Browse the repository at this point in the history
Otherwise, sources with the same slug but
in another directory are included.
  • Loading branch information
neilvanbeinum committed Dec 17, 2022
1 parent ed9a4d3 commit 599c4d4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bridgetown-core/lib/bridgetown-core/concerns/localizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def all_locales
[]
end

result_set.select { |item| item.data.slug == data.slug }.sort_by do |item|
matching_resources = result_set.select do |item|
item.relative_path.parent == relative_path.parent && item.data.slug == data.slug
end

matching_resources.sort_by do |item|
site.config.available_locales.index item.data.locale
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
~~~ruby
{ title: "I'm a Third Level Page" }
~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
~~~ruby
{ title: "I'm a Third Level Page in French" }
~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
~~~ruby
{ title: "I'm a Third Level Page" }
~~~
21 changes: 21 additions & 0 deletions bridgetown-core/test/test_locales.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ def reset_i18n_config
end
end

context "a page with a slug that matches others in this directory and also another directory" do
setup do
@site = resources_site
@site.process
# @type [Bridgetown::Resource::Base]
@resource = @site.collections.pages.resources.find do |page|
page.relative_path.to_s == "_pages/my_directory/third-level-page.en.md"
end

@resource_with_matching_slug_in_same_directory = @site.collections.pages.resources.find do |page|
page.relative_path.to_s == "_pages/my_directory/third-level-page.fr.md"
end
end

context "#all_locales" do
should "list only the resources with the same slug and the same parent directory" do
assert_equal([@resource, @resource_with_matching_slug_in_same_directory], @resource.all_locales)
end
end
end

context "one page which is generated into multiple locales (as specified in locales key)" do
setup do
reset_i18n_config
Expand Down

0 comments on commit 599c4d4

Please sign in to comment.