2020-01-28 21:05:59 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Devuelve una lista de títulos y UUID de todos los posts del mismo
|
|
|
|
# idioma que el actual, para usar con input-map.js
|
|
|
|
class MetadataRelatedPosts < MetadataArray
|
|
|
|
# Genera un Hash de { title | slug => uuid }
|
|
|
|
def values
|
2020-07-02 13:59:58 +00:00
|
|
|
@values ||= posts.map do |p|
|
2020-01-28 21:05:59 +00:00
|
|
|
{ title(p) => p.uuid.value }
|
|
|
|
end.inject(:merge)
|
|
|
|
end
|
|
|
|
|
2020-08-20 23:38:31 +00:00
|
|
|
# Las relaciones nunca son privadas
|
|
|
|
def private?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2020-01-28 21:05:59 +00:00
|
|
|
private
|
|
|
|
|
2020-07-02 13:59:58 +00:00
|
|
|
# Obtiene todos los posts y opcionalmente los filtra
|
|
|
|
def posts
|
|
|
|
@posts ||= site.posts(lang: lang).where(**filter)
|
|
|
|
end
|
|
|
|
|
2020-01-28 21:05:59 +00:00
|
|
|
def title(post)
|
2020-10-04 00:32:32 +00:00
|
|
|
post&.title&.value || post&.slug&.value
|
2020-01-28 21:05:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: Traer el idioma actual de otra forma
|
|
|
|
def lang
|
2020-10-04 00:32:32 +00:00
|
|
|
post&.lang&.value || I18n.locale
|
2020-01-28 21:05:59 +00:00
|
|
|
end
|
2020-07-02 13:59:58 +00:00
|
|
|
|
|
|
|
# Encuentra el filtro
|
|
|
|
def filter
|
|
|
|
layout.metadata.dig(name, 'filter')&.to_h&.symbolize_keys || {}
|
|
|
|
end
|
2020-01-28 21:05:59 +00:00
|
|
|
end
|