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
|
2021-03-25 22:56:50 +00:00
|
|
|
# Genera un Hash de { title | slug => uuid } y excluye el Post actual
|
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|
|
2021-03-25 22:56:50 +00:00
|
|
|
next if p.uuid.value == post.uuid.value
|
|
|
|
|
2020-11-07 23:51:00 +00:00
|
|
|
[title(p), p.uuid.value]
|
2021-03-25 22:56:50 +00:00
|
|
|
end.compact.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
|
|
|
|
|
2021-05-06 15:33:28 +00:00
|
|
|
def indexable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2021-05-06 16:00:05 +00:00
|
|
|
def indexable_values
|
2021-05-17 20:27:01 +00:00
|
|
|
posts.where(uuid: value).map(&:title).map(&:value)
|
2021-05-06 16:00:05 +00:00
|
|
|
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
|
2021-05-13 22:47:00 +00:00
|
|
|
site.posts(lang: lang).where(**filter)
|
2020-07-02 13:59:58 +00:00
|
|
|
end
|
|
|
|
|
2020-01-28 21:05:59 +00:00
|
|
|
def title(post)
|
2021-03-27 13:38:37 +00:00
|
|
|
"#{post&.title&.value || post&.slug&.value} (#{post.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
|