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 }
|
2020-11-07 23:51:00 +00:00
|
|
|
# @return [Hash]
|
2020-01-28 21:05:59 +00:00
|
|
|
def values
|
2020-07-02 13:59:58 +00:00
|
|
|
@values ||= posts.map do |p|
|
2020-11-07 23:51:00 +00:00
|
|
|
[title(p), p.uuid.value]
|
|
|
|
end.to_h
|
2020-01-28 21:05:59 +00:00
|
|
|
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)
|
2021-03-25 22:50:40 +00:00
|
|
|
"#{post&.title&.value || post&.slug&.value} (#{layout.humanized_name})"
|
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
|
2021-02-11 19:16:25 +00:00
|
|
|
|
|
|
|
def sanitize(uuid)
|
|
|
|
super(uuid.map do |u|
|
|
|
|
u.to_s.gsub(/[^a-f0-9\-]/i, '')
|
|
|
|
end)
|
|
|
|
end
|
2020-01-28 21:05:59 +00:00
|
|
|
end
|