lib/bluedoc/import/gitbook.rb
# Upload images to BlueDoc storage and replace body url
Upload images to BlueDoc storage and replace body url
Upload images to BlueDoc storage and replace body url
def upload_images(filepath, body)
        html = BlueDoc::HTML.render(body, format: :markdown)
        doc = Nokogiri::HTML(html)
        filedir = File.dirname(filepath)
        doc.css("img").each do |node|
          src = node.attr("src")
          next if src.blank?
          src_path = src
          unless BlueDoc::Validate.url?(src_path)
            src_path = File.join(filedir, src)
          end
          begin
            url = BlueDoc::Blob.upload(src_path)
            body = body.gsub(src, url)
          rescue BlueDoc::Blob::FileNotFoundError => e
            logger.warn "upload_attachments error: #{e}"
          end
        end
        body
      end
def upload_images ( filepath , body ) html = BlueDoc :: HTML . render ( body , format : :markdown ) doc = Nokogiri :: HTML ( html ) filedir = File . dirname ( filepath ) doc . css ( "img" ) . each do | node | src = node . attr ( "src" ) next if src . blank? src_path = src unless BlueDoc :: Validate . url? ( src_path ) src_path = File . join ( filedir , src ) end begin url = BlueDoc :: Blob . upload ( src_path ) body = body . gsub ( src , url ) rescue BlueDoc :: Blob :: FileNotFoundError => e logger . warn "upload_attachments error: #{e}" end end body end
Upload images to BlueDoc storage and replace body url
Upload images to BlueDoc storage and replace body url
filepath
<not_specific>
body
<not_specific>