mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-17 03:26:21 +00:00
feat: realiza el paso inverso sutty/editor#59
This commit is contained in:
parent
1adfc91a7f
commit
04622751ef
1 changed files with 20 additions and 1 deletions
|
@ -24,7 +24,11 @@ class MetadataContent < MetadataTemplate
|
|||
end
|
||||
|
||||
def to_s
|
||||
sanitizer.sanitize value, tags: [], attributes: []
|
||||
Nokogiri::HTML.fragment(value).tap do |html|
|
||||
html.css('[src^="public/"]').each do |element|
|
||||
element['src'] = convert_internal_path_to_src element['src']
|
||||
end
|
||||
end.to_s
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -76,6 +80,21 @@ class MetadataContent < MetadataTemplate
|
|||
html.to_s.html_safe
|
||||
end
|
||||
|
||||
# Convierte una ubicación local al sitio en una URL de ActiveStorage
|
||||
#
|
||||
# XXX: Por qué son tan díficiles de encontrar las rutas de AS
|
||||
#
|
||||
# @param path [String]
|
||||
# @return [String]
|
||||
def convert_internal_path_to_src(path)
|
||||
key = path.split('/').second
|
||||
blob = ActiveStorage::Blob.find_by(service_name: site.name, key: key)
|
||||
|
||||
return unless blob
|
||||
|
||||
"/rails/active_storage/blobs/#{blob.signed_id}/#{blob.filename}"
|
||||
end
|
||||
|
||||
# Convierte una URI en una ruta interna del sitio actual
|
||||
#
|
||||
# XXX: No verifica si el archivo existe o no. Se supone que existe
|
||||
|
|
Loading…
Reference in a new issue