Skip to content

Commit

Permalink
Fix asset url resolution (#48)
Browse files Browse the repository at this point in the history
Fixes an issue when base url contains a subpath component:
- add base url as a prefix to assets
  • Loading branch information
tib authored Oct 27, 2024
1 parent b648c9b commit 1dbff25
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/ToucanSDK/PageBundle/PageBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct PageBundle {

let id: String
let url: URL
let baseUrl: String

let slug: String
let permalink: String
Expand Down Expand Up @@ -48,7 +49,7 @@ struct PageBundle {
return path
}
let src = String(path.dropFirst(prefix.count))
return "/" + config.assets.folder + "/" + assetsLocation + "/" + src
return baseUrl + config.assets.folder + "/" + assetsLocation + "/" + src
}

// MARK: -
Expand Down
1 change: 1 addition & 0 deletions Sources/ToucanSDK/PageBundle/PageBundleLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public struct PageBundleLoader {
return .init(
id: id,
url: dirUrl,
baseUrl: sourceConfig.site.baseUrl,
slug: slug,
permalink: slug.permalink(
baseUrl: sourceConfig.site.baseUrl
Expand Down
1 change: 1 addition & 0 deletions Sources/ToucanSDK/Renderers/HTMLRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ struct HTMLRenderer {
let finalBundle = PageBundle(
id: pageBundle.id,
url: pageBundle.url,
baseUrl: source.sourceConfig.site.baseUrl,
slug: finalSlug,
permalink: finalSlug.permalink(
baseUrl: source.sourceConfig.site.baseUrl
Expand Down
3 changes: 3 additions & 0 deletions Tests/ToucanSDKTests/Mocks/PageBundle+Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extension PageBundle {
static let post1 = PageBundle(
id: "post-1",
url: URL(fileURLWithPath: "/"),
baseUrl: "http://localhost:3000/",
slug: "post-1",
permalink: "post-1",
title: "Post 1",
Expand Down Expand Up @@ -59,6 +60,7 @@ extension PageBundle {
static let author1 = PageBundle(
id: "author-1",
url: URL(fileURLWithPath: "/"),
baseUrl: "http://localhost:3000/",
slug: "author-1",
permalink: "author-1",
title: "Author 1",
Expand Down Expand Up @@ -101,6 +103,7 @@ extension PageBundle {
static let page1 = PageBundle(
id: "page-1",
url: URL(fileURLWithPath: "/"),
baseUrl: "http://localhost:3000/",
slug: "page-1",
permalink: "page-1",
title: "Page 1",
Expand Down

0 comments on commit 1dbff25

Please sign in to comment.