diff --git a/app/models/metadata_order.rb b/app/models/metadata_order.rb index 577e3c85..f63a7d49 100644 --- a/app/models/metadata_order.rb +++ b/app/models/metadata_order.rb @@ -5,7 +5,7 @@ class MetadataOrder < MetadataTemplate # El valor según la posición del post en la relación ordenada por # fecha, a fecha más alta, posición más alta def default_value - super || (site.indexed_posts(locale: locale).first.order + 1) + super || ((site.indexed_posts.where(locale: locale).first&.order || 0) + 1) end def save diff --git a/app/models/metadata_related_posts.rb b/app/models/metadata_related_posts.rb index f513b4fb..6d52096e 100644 --- a/app/models/metadata_related_posts.rb +++ b/app/models/metadata_related_posts.rb @@ -34,14 +34,14 @@ class MetadataRelatedPosts < MetadataArray # # @return [IndexedPost::ActiveRecord_AssociationRelation] def posts - site.indexed_posts.where(locale: locale).where.not(post_id: post.uuid.value).where(**filter) + site.indexed_posts.where(locale: locale).where.not(post_id: post.uuid.value).where(filter) end # Encuentra el filtro desde el esquema del atributo # - # @return [Hash] + # @return [Hash,nil] def filter - layout.metadata.dig(name, 'filter')&.to_h&.symbolize_keys || {} + layout.metadata.dig(name, 'filter')&.to_h&.symbolize_keys end def sanitize(uuid) diff --git a/app/models/post/indexable.rb b/app/models/post/indexable.rb index 9629efd0..3aa8ce59 100644 --- a/app/models/post/indexable.rb +++ b/app/models/post/indexable.rb @@ -51,7 +51,7 @@ class Post indexable_attributes.select do |attr| self[attr].front_matter? end.each do |attr| - ifm[attr] = self[attr].indexable_values + ifm[attr] = self[attr].try(:indexable_values) end end end diff --git a/app/models/site/index.rb b/app/models/site/index.rb index cfa4030a..2cb950cb 100644 --- a/app/models/site/index.rb +++ b/app/models/site/index.rb @@ -16,7 +16,12 @@ class Site def index_posts! Site.transaction do - docs.each(&:index!) + jekyll.read + jekyll.documents.each do |doc| + doc.read! + + Post.new(document: doc, site: self, layout: layouts[doc['layout'].to_sym]).index! + end update(last_indexed_commit: repository.head_commit.oid) end diff --git a/app/views/posts/attribute_ro/_related_posts.haml b/app/views/posts/attribute_ro/_related_posts.haml index 6014e160..aa4aff2e 100644 --- a/app/views/posts/attribute_ro/_related_posts.haml +++ b/app/views/posts/attribute_ro/_related_posts.haml @@ -2,10 +2,9 @@ %th= post_label_t(attribute, post: post) %td %ul{ dir: dir, lang: locale } - - metadata.value.each do |v| - - p = site.indexed_posts(locale: post.lang.value).find_by(post_id: v)&.post + - site.indexed_posts.where(locale: post.lang.value, post_id: metadata.value).find_each do |p| -# XXX: Ignorar todos los posts no encontrados (ej: fueron borrados o el uuid cambió) - next unless p - %li= link_to p.title.value, site_post_path(site, p.id) + %li= link_to p.title, site_post_path(site, p.path)