mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 22:51:41 +00:00
52 lines
1.3 KiB
Ruby
52 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Site
|
|
# Obtiene todos los archivos relacionados en artículos del sitio y los
|
|
# sube a Sutty.
|
|
class StaticFileMigration
|
|
# Tipos de metadatos que contienen archivos
|
|
STATIC_TYPES = %i[file image].freeze
|
|
|
|
attr_reader :site
|
|
|
|
def initialize(site:)
|
|
@site = site
|
|
end
|
|
|
|
def migrate!
|
|
modified = site.docs.map do |doc|
|
|
next unless STATIC_TYPES.map do |field|
|
|
next unless doc.attribute? field
|
|
next unless doc[field].path?
|
|
next unless doc[field].static_file
|
|
|
|
true
|
|
end.any?
|
|
|
|
log.write "#{doc.path.relative};no se pudo guardar\n" unless doc.save(validate: false)
|
|
|
|
doc.path.absolute
|
|
end.compact
|
|
|
|
log.close
|
|
|
|
return if modified.empty?
|
|
|
|
# TODO: Hacer la migración desde el servicio de creación de sitios?
|
|
site.repository.commit(file: modified,
|
|
message: I18n.t('sites.static_file_migration'),
|
|
usuarie: author)
|
|
end
|
|
|
|
private
|
|
|
|
def author
|
|
@author ||= GitAuthor.new email: "sutty@#{Site.domain}",
|
|
name: 'Sutty'
|
|
end
|
|
|
|
def log
|
|
@log ||= File.open(File.join(site.path, 'migration.csv'), 'w')
|
|
end
|
|
end
|
|
end
|