mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 23:36:21 +00:00
feat: poder obtener la ubicacion a partir de la key
This commit is contained in:
parent
5e6cbba28e
commit
3cd483bb79
3 changed files with 22 additions and 2 deletions
|
@ -15,6 +15,14 @@ module ActiveStorage
|
|||
end
|
||||
end
|
||||
|
||||
# Obtiene Blob#key desde la ubicación, la inversa de path_for
|
||||
#
|
||||
# @param :path [String,Pathname]
|
||||
# @return [String]
|
||||
def key_from_path(path)
|
||||
Pathname.new(path).dirname.basename.to_s
|
||||
end
|
||||
|
||||
# Solo copiamos el archivo si no existe
|
||||
#
|
||||
# @param :key [String]
|
||||
|
@ -87,7 +95,15 @@ module ActiveStorage
|
|||
# @param :key [String]
|
||||
# @return [String]
|
||||
def path_for(key)
|
||||
File.join root, folder_for(key), filename_for(key)
|
||||
File.join absolute_path_for(key), filename_for(key)
|
||||
end
|
||||
|
||||
# La ruta absoluta del directorio donde se almacena el archivo
|
||||
#
|
||||
# @param :key [String]
|
||||
# @return [String]
|
||||
def absolute_path_for(key)
|
||||
File.join root, folder_for(key)
|
||||
end
|
||||
|
||||
# @return [Site]
|
||||
|
|
|
@ -88,7 +88,7 @@ class MetadataFile < MetadataTemplate
|
|||
#
|
||||
# @return [String]
|
||||
def key_from_path
|
||||
@key_from_path ||= pathname.dirname.basename.to_s
|
||||
@key_from_path ||= site.blob_service.key_from_path(path: pathname)
|
||||
end
|
||||
|
||||
def path?
|
||||
|
|
|
@ -14,6 +14,10 @@ class Site
|
|||
DELETED_STATUSES = %i[deleted].freeze
|
||||
LOCALE_FROM_PATH = /\A_/.freeze
|
||||
|
||||
def blob_service
|
||||
@blob_service ||= ActiveStorage::Service::JekyllService.build_for_site(site: self)
|
||||
end
|
||||
|
||||
def index_posts!
|
||||
Site.transaction do
|
||||
docs.each(&:index!)
|
||||
|
|
Loading…
Reference in a new issue