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)
15 16 17 |
# File 'lib/jekyll-auto-thumbnails/url_resolver.rb', line 15 def self.external?(url) url.start_with?("http://", "https://", "//") end |
.resolve_path(url, base_dir) ⇒ String?
Resolve relative path to absolute site-relative path
24 25 26 27 28 29 30 |
# File 'lib/jekyll-auto-thumbnails/url_resolver.rb', line 24 def self.resolve_path(url, base_dir) return nil if external?(url) return url if url.start_with?("/") # Join with base_dir and normalize Pathname.new(File.join(base_dir, url)).cleanpath.to_s end |
.to_filesystem_path(url, site_source) ⇒ String?
Convert site-relative URL to filesystem path
37 38 39 40 41 |
# File 'lib/jekyll-auto-thumbnails/url_resolver.rb', line 37 def self.to_filesystem_path(url, site_source) return nil if external?(url) File.join(site_source, url) end |