2021-05-17 18:33:46 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Indexa todos los artículos de un sitio
|
|
|
|
#
|
|
|
|
# TODO: Hacer opcional
|
|
|
|
class Site
|
|
|
|
module Index
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
# TODO: Debería ser un Job?
|
|
|
|
after_create :index_posts!
|
|
|
|
has_many :indexed_posts, dependent: :destroy
|
|
|
|
|
|
|
|
def index_posts!
|
|
|
|
Site.transaction do
|
2023-10-20 15:22:18 +00:00
|
|
|
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)
|
2021-05-17 18:33:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|