Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the legacy URL and UrlDrop classes #891

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ module Bridgetown
autoload :Slot, "bridgetown-core/slot"
autoload :StaticFile, "bridgetown-core/static_file"
autoload :Transformable, "bridgetown-core/concerns/transformable"
autoload :URL, "bridgetown-core/url"
autoload :Utils, "bridgetown-core/utils"
autoload :VERSION, "bridgetown-core/version"
autoload :Watcher, "bridgetown-core/watcher"
Expand Down
152 changes: 0 additions & 152 deletions bridgetown-core/lib/bridgetown-core/drops/url_drop.rb

This file was deleted.

54 changes: 35 additions & 19 deletions bridgetown-core/lib/bridgetown-core/generated_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,40 +97,56 @@ def permalink
data&.permalink
end

def add_permalink_suffix(template, permalink_style)
template = template.dup

case permalink_style
when :pretty, :simple
template << "/"
else
template << "/" if permalink_style.to_s.end_with?("/")
template << ":output_ext" if permalink_style.to_s.end_with?(".*")
end

template
end

# The template of the permalink.
#
# @return [String]
def template
if !html?
"/:path/:basename:output_ext"
"/:dir/:basename:output_ext"
elsif index?
"/:path/"
"/:dir/"
else
Utils.add_permalink_suffix("/:path/:basename", site.permalink_style)
add_permalink_suffix("/:dir/:basename", site.permalink_style)
end
end

# The generated relative url of this page. e.g. /about.html.
#
# @return [String]
def url
@url ||= URL.new(
template:,
placeholders: url_placeholders,
permalink:
).to_s
end
alias_method :relative_url, :url
return @url if @url

tmpl = permalink || template
placeholders = { dir: @dir, basename:, output_ext: }

results = placeholders.inject(tmpl) do |result, token|
break result if result.index(":").nil?

# Returns a hash of URL placeholder names (as symbols) mapping to the
# desired placeholder replacements. For details see "url.rb"
def url_placeholders
{
path: @dir,
basename: @basename,
output_ext:,
}
if token.last.nil?
# Remove leading "/" to avoid generating urls with `//`
result.gsub("/:#{token.first}", "")
else
result.gsub(":#{token.first}", token.last)
end
end.then { Addressable::URI.normalize_component _1 }

@url = "/#{results.sub("#", "%23")}".gsub("..", "/").gsub("./", "").squeeze("/")
end
alias_method :relative_url, :url

# Layout associated with this resource
# This will output a warning if the layout can't be found.
Expand Down Expand Up @@ -241,7 +257,7 @@ def place_into_layouts
#
# @return [String]
def destination(dest)
path = site.in_dest_dir(dest, URL.unescape_path(url))
path = site.in_dest_dir(dest, Utils.unencode_uri(url))
path = File.join(path, "index") if url.end_with?("/")
path << output_ext unless path.end_with? output_ext
path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def final_ext
end

def output_path
path = URL.unescape_path(relative_url)
path = Utils.unencode_uri(relative_url)
if resource.site.base_path.present?
path = path.delete_prefix resource.site.base_path(strip_slash_only: true)
end
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/static_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def destination(dest)
if site.base_path.present? && collection
dest_url = dest_url.delete_prefix site.base_path(strip_slash_only: true)
end
site.in_dest_dir(dest, Bridgetown::URL.unescape_path(dest_url))
site.in_dest_dir(dest, Bridgetown::Utils.unencode_uri(dest_url))
end

def destination_rel_dir
Expand Down
Loading