5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 20:46:21 +00:00

fix: locales

This commit is contained in:
f 2023-10-06 17:30:37 -03:00
parent ad3d52e2e7
commit 5b9df0d020
No known key found for this signature in database
3 changed files with 13 additions and 15 deletions

View file

@ -6,11 +6,16 @@ class MetadataLocales < MetadataHasAndBelongsToMany
# #
# @return { lang: { title: uuid } } # @return { lang: { title: uuid } }
def values def values
@values ||= site.locales.map do |locale| @values ||= other_locales.to_h do |other_locale|
[locale, posts.where(lang: locale).map do |post| [
[title(post), post.uuid.value] other_locale,
end.to_h] posts.where(locale: other_locale).pluck(:title, :layout, :post_id).to_h do |row|
end.to_h row.tap do |value|
value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})"
end
end
]
end
end end
# Siempre hay una relación inversa # Siempre hay una relación inversa
@ -33,9 +38,7 @@ class MetadataLocales < MetadataHasAndBelongsToMany
# #
# @return [Array] # @return [Array]
def other_locales def other_locales
@other_locales ||= site.locales.reject do |other_locale| @other_locales ||= site.locales - [locale]
other_locale.to_s == locale
end
end end
# Obtiene todos los posts de los otros locales con el mismo layout # Obtiene todos los posts de los otros locales con el mismo layout

View file

@ -8,11 +8,11 @@ class MetadataRelatedPosts < MetadataArray
# #
# @return [Hash] # @return [Hash]
def values def values
@values ||= posts.pluck(:title, :layout, :post_id).map do |row| @values ||= posts.pluck(:title, :layout, :post_id).to_h do |row|
row.tap do |value| row.tap do |value|
value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})" value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})"
end end
end.to_h end
end end
# Las relaciones nunca son privadas # Las relaciones nunca son privadas
@ -37,10 +37,6 @@ class MetadataRelatedPosts < MetadataArray
site.indexed_posts.where(locale: locale).where.not(post_id: post.uuid.value).where(**filter) site.indexed_posts.where(locale: locale).where.not(post_id: post.uuid.value).where(**filter)
end end
def title(post)
"#{post&.title&.value || post&.slug&.value} (#{post.layout.humanized_name})"
end
# Encuentra el filtro desde el esquema del atributo # Encuentra el filtro desde el esquema del atributo
# #
# @return [Hash] # @return [Hash]

View file

@ -6,7 +6,6 @@
post: post, attribute: attribute, metadata: metadata post: post, attribute: attribute, metadata: metadata
- site.locales.each do |locale| - site.locales.each do |locale|
- next if post.lang.value == locale
- locale_t = t("locales.#{locale}.name", default: locale.to_s.humanize) - locale_t = t("locales.#{locale}.name", default: locale.to_s.humanize)
- value = metadata.value.find do |v| - value = metadata.value.find do |v|
- metadata.values[locale].values.include? v - metadata.values[locale].values.include? v