mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 12:26:21 +00:00
47 lines
1.3 KiB
Ruby
47 lines
1.3 KiB
Ruby
# 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
|
|
# @todo ¿Deberíamos indexar algo de esto?
|
|
include Metadata::NonIndexableConcern
|
|
include Metadata::AlwaysPublicConcern
|
|
|
|
# Genera un Hash de { title (schema) => uuid } para usar en
|
|
# options_for_select
|
|
#
|
|
# @return [Hash]
|
|
def values
|
|
@values ||= posts.pluck(:title, :layout, :post_id).map do |row|
|
|
row.tap do |value|
|
|
value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})"
|
|
end
|
|
end.to_h
|
|
end
|
|
|
|
private
|
|
|
|
# Obtiene todos los posts menos el actual y opcionalmente los filtra
|
|
#
|
|
# @return [IndexedPost::ActiveRecord_AssociationRelation]
|
|
def posts
|
|
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]
|
|
def filter
|
|
layout.metadata.dig(name, 'filter')&.to_h&.symbolize_keys || {}
|
|
end
|
|
|
|
def sanitize(uuid)
|
|
super(uuid.map do |u|
|
|
u.to_s.gsub(/[^a-f0-9\-]/i, '')
|
|
end)
|
|
end
|
|
end
|