Module: JekyllAutoThumbnails::UrlResolver
- Defined in:
- lib/jekyll-auto-thumbnails/url_resolver.rb
Overview
URL resolution and path handling
Handles conversion between URLs (as seen in HTML) and filesystem paths, distinguishes between external URLs and local paths, and resolves relative paths.
Class Method Summary collapse
-
.external?(url) ⇒ Boolean
Check if URL is external (http/https/protocol-relative).
-
.resolve_path(url, base_dir) ⇒ String?
Resolve relative path to absolute site-relative path.
-
.to_filesystem_path(url, site_source) ⇒ String?
Convert site-relative URL to filesystem path.
Class Method Details
.external?(url) ⇒ Boolean
Check if URL is external (http/https/protocol-relative)
13 14 15 |
# File 'lib/jekyll-auto-thumbnails/url_resolver.rb', line 13 def self.external?(url) url.start_with?("http://", "https://", "//") end |
.resolve_path(url, base_dir) ⇒ String?
Resolve relative path to absolute site-relative path
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jekyll-auto-thumbnails/url_resolver.rb', line 22 def self.resolve_path(url, base_dir) return nil if external?(url) return url if url.start_with?("/") # Relative path - resolve against base_dir # Remove ./ prefix if present cleaned_url = url.sub(%r{^\./}, "") # Join with base_dir and normalize require "pathname" Pathname.new(File.join(base_dir, cleaned_url)).cleanpath.to_s end |
.to_filesystem_path(url, site_source) ⇒ String?
Convert site-relative URL to filesystem path
40 41 42 43 44 45 46 |
# File 'lib/jekyll-auto-thumbnails/url_resolver.rb', line 40 def self.to_filesystem_path(url, site_source) return nil if external?(url) # Strip leading slash and join with site source cleaned_url = url.sub(%r{^/}, "") File.join(site_source, cleaned_url) end |