5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 16:06:23 +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 } }
def values
@values ||= site.locales.map do |locale|
[locale, posts.where(lang: locale).map do |post|
[title(post), post.uuid.value]
end.to_h]
end.to_h
@values ||= other_locales.to_h do |other_locale|
[
other_locale,
posts.where(locale: other_locale).pluck(:title, :layout, :post_id).to_h do |row|
row.tap do |value|
value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})"
end
end
]
end
end
# Siempre hay una relación inversa
@ -33,9 +38,7 @@ class MetadataLocales < MetadataHasAndBelongsToMany
#
# @return [Array]
def other_locales
@other_locales ||= site.locales.reject do |other_locale|
other_locale.to_s == locale
end
@other_locales ||= site.locales - [locale]
end
# Obtiene todos los posts de los otros locales con el mismo layout

View file

@ -8,11 +8,11 @@ class MetadataRelatedPosts < MetadataArray
#
# @return [Hash]
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|
value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})"
end
end.to_h
end
end
# 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)
end
def title(post)
"#{post&.title&.value || post&.slug&.value} (#{post.layout.humanized_name})"
end
# Encuentra el filtro desde el esquema del atributo
#
# @return [Hash]

View file

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