Skip to content

Commit fe72c14

Browse files
author
hhaensel
committed
support case-sensitive cdn providers
1 parent a8b50ec commit fe72c14

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

src/Assets.jl

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ Generates the path to an asset file.
105105
function asset_path(; file::String, host::String = Genie.config.base_path, package::String = "", version::String = "",
106106
prefix::String = "assets", type::String = "$(split(file, '.')[end])", path::String = "", min::Bool = false,
107107
ext::String = "$(endswith(file, type) ? "" : ".$type")", skip_ext::Bool = false, query::String = "") :: String
108-
startswith(host, '/') && (host = host[2:end])
109-
endswith(host, '/') && (host = host[1:end-1])
110-
startswith(path, '/') && (path = path[2:end])
111-
endswith(path, '/') && (path = path[1:end-1])
112-
113-
(
114-
(external_assets(host) ? "" : "/") *
115-
join(filter([host, package, version, prefix, type, path, file*(min ? ".min" : "")*(skip_ext ? "" : ext)]) do part
116-
! isempty(part)
117-
end, '/') *
118-
query) |> lowercase
108+
endswith(host, '/') || (host *= '/')
109+
path = strip(path, '/')
110+
external = external_assets(host)
111+
112+
assetpath = string(
113+
host,
114+
join(filter(!isempty, [join([package, version], external ? '@' : '/'), prefix, type, path, file*(min ? ".min" : "")*(skip_ext ? "" : ext)]), '/'),
115+
query
116+
)
117+
return external ? assetpath : lowercase(assetpath)
119118
end
120119
function asset_path(file::String; kwargs...) :: String
121120
asset_path(; file, kwargs...)
@@ -140,14 +139,13 @@ Generates the route to an asset file.
140139
function asset_route(; file::String, package::String = "", version::String = "", prefix::String = "assets",
141140
type::String = "$(split(file, '.')[end])", path::String = "", min::Bool = false,
142141
ext::String = "$(endswith(file, type) ? "" : ".$type")", skip_ext::Bool = false, query::String = "") :: String
143-
startswith(path, '/') && (path = path[2:end])
144-
endswith(path, '/') && (path = path[1:end-1])
142+
path = strip(path, '/')
145143

146-
('/' *
147-
join(filter([package, version, prefix, type, path, file*(min ? ".min" : "")*(skip_ext ? "" : ext)]) do part
148-
! isempty(part)
149-
end, '/') *
150-
query) |> lowercase
144+
string(
145+
'/',
146+
join(filter(!isempty, [package, version, prefix, type, path, file*(min ? ".min" : "")*(skip_ext ? "" : ext)]), '/'),
147+
query
148+
) |> lowercase
151149
end
152150
function asset_route(file::String; kwargs...) :: String
153151
asset_route(; file, kwargs...)
@@ -168,9 +166,7 @@ Generates the file system path to an asset file.
168166
"""
169167
function asset_file(; cwd = "", file::String, path::String = "", type::String = "$(split(file, '.')[end])", prefix::String = "assets",
170168
ext::String = "$(endswith(file, type) ? "" : ".$type")", min::Bool = false, skip_ext::Bool = false) :: String
171-
joinpath((filter([cwd, prefix, type, path, file*(min ? ".min" : "")*(skip_ext ? "" : ext)]) do part
172-
! isempty(part)
173-
end)...) |> normpath
169+
joinpath(filter(!isempty, [cwd, prefix, type, path, file*(min ? ".min" : "")*(skip_ext ? "" : ext)])...) |> normpath
174170
end
175171

176172

0 commit comments

Comments
 (0)