5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 08:46:21 +00:00
panel/app/models/site/index.rb

30 lines
646 B
Ruby
Raw Normal View History

# 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
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
end
end
end
end