Class: Sakusei::ImagePathResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/sakusei/image_path_resolver.rb

Overview

Embeds local images as base64 data URIs so that Puppeteer can render them regardless of HTTP server basedir or working directory. Runs after ERB processing so documents can use standard relative paths (e.g. images/foo.jpg) and remain previewable in any standard markdown viewer.

Handles:

- Standard markdown images:  ![alt](images/foo.jpg)
- Vue component image props:  "image":"images/foo.jpg"

Leaves http://, https://, data:, and missing files untouched.

Constant Summary collapse

SKIP_PATTERN =
/\A(https?:|data:|\/\/)/i
MIME_TYPES =
{
  '.jpg'  => 'image/jpeg',
  '.jpeg' => 'image/jpeg',
  '.png'  => 'image/png',
  '.gif'  => 'image/gif',
  '.svg'  => 'image/svg+xml',
  '.webp' => 'image/webp'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(content, base_dir) ⇒ ImagePathResolver

Returns a new instance of ImagePathResolver.



28
29
30
31
# File 'lib/sakusei/image_path_resolver.rb', line 28

def initialize(content, base_dir)
  @content  = content
  @base_dir = base_dir
end

Instance Method Details

#resolveObject



33
34
35
36
37
# File 'lib/sakusei/image_path_resolver.rb', line 33

def resolve
  content = resolve_markdown_images(@content)
  content = resolve_component_image_props(content)
  content
end