diff --git a/CHDataManagement/Extensions/String+Extensions.swift b/CHDataManagement/Extensions/String+Extensions.swift index d110c5a..42ad981 100644 --- a/CHDataManagement/Extensions/String+Extensions.swift +++ b/CHDataManagement/Extensions/String+Extensions.swift @@ -16,6 +16,13 @@ extension String { return decoded } + var withLeadingSlashRemoved: String { + if !hasPrefix("/") { + return self + } + return String(dropFirst("/".count)) + } + var removingSurroundingQuotes: String { if hasPrefix("\"") && hasSuffix("\"") { return dropBeforeFirst("\"").dropAfterLast("\"") diff --git a/CHDataManagement/Generator/Post Lists/FeedGeneratorSource.swift b/CHDataManagement/Generator/Post Lists/FeedGeneratorSource.swift index 5a68e8b..f5716d2 100644 --- a/CHDataManagement/Generator/Post Lists/FeedGeneratorSource.swift +++ b/CHDataManagement/Generator/Post Lists/FeedGeneratorSource.swift @@ -23,7 +23,14 @@ struct FeedGeneratorSource: PostListPageGeneratorSource { content.settings.localized(in: language).description } + /** + The url to the page, including a leading slash + */ func pageUrlPrefix(for language: ContentLanguage) -> String { - content.settings.localized(in: language).feedUrlPrefix + let prefix = content.settings.localized(in: language).feedUrlPrefix + if prefix.hasPrefix( "/" ) { + return prefix + } + return "/" + prefix } } diff --git a/CHDataManagement/Generator/Post Lists/PostListPageGenerator.swift b/CHDataManagement/Generator/Post Lists/PostListPageGenerator.swift index 1d38116..a00e74a 100644 --- a/CHDataManagement/Generator/Post Lists/PostListPageGenerator.swift +++ b/CHDataManagement/Generator/Post Lists/PostListPageGenerator.swift @@ -74,7 +74,8 @@ final class PostListPageGenerator { let feedPageGenerator = FeedPageGenerator(content: source.content, results: source.results) - let languageButtonUrl = "/" + pageUrl(in: language.next, pageNumber: pageIndex) + // Includes leading slash + let languageButtonUrl = pageUrl(in: language.next, pageNumber: pageIndex) let fileContent = feedPageGenerator.generatePage( language: language, diff --git a/CHDataManagement/Generator/Post Lists/PostListPageGeneratorSource.swift b/CHDataManagement/Generator/Post Lists/PostListPageGeneratorSource.swift index 4f2b619..f44396e 100644 --- a/CHDataManagement/Generator/Post Lists/PostListPageGeneratorSource.swift +++ b/CHDataManagement/Generator/Post Lists/PostListPageGeneratorSource.swift @@ -13,6 +13,9 @@ protocol PostListPageGeneratorSource { var pageDescription: String { get } + /** + The url to the page, including a leading slash + */ func pageUrlPrefix(for language: ContentLanguage) -> String var postsPerPage: Int { get } diff --git a/CHDataManagement/Model/FileResource.swift b/CHDataManagement/Model/FileResource.swift index e9bbdb3..e141798 100644 --- a/CHDataManagement/Model/FileResource.swift +++ b/CHDataManagement/Model/FileResource.swift @@ -250,7 +250,11 @@ final class FileResource: Item { */ var absoluteUrl: String { if let customOutputPath { - return customOutputPath + if customOutputPath.hasPrefix("/") { + return customOutputPath + } else { + return "/" + customOutputPath + } } let path = pathPrefix + "/" + id return makeCleanAbsolutePath(path) diff --git a/CHDataManagement/Page Elements/PostFeedPageNavigation.swift b/CHDataManagement/Page Elements/PostFeedPageNavigation.swift index 37ae413..c9fb8fd 100644 --- a/CHDataManagement/Page Elements/PostFeedPageNavigation.swift +++ b/CHDataManagement/Page Elements/PostFeedPageNavigation.swift @@ -2,6 +2,7 @@ import Foundation struct PostFeedPageNavigation { + /// Includes a leading slash let linkPrefix: String let currentPage: Int @@ -15,7 +16,7 @@ struct PostFeedPageNavigation { } private func pageLink(_ page: Int) -> String { - "href='/\(linkPrefix)/\(page)'" + "href='\(linkPrefix)/\(page)'" } private func addPreviousButton(to result: inout String) { diff --git a/CHDataManagement/Storage/SecurityBookmark.swift b/CHDataManagement/Storage/SecurityBookmark.swift index 8b18b83..4b7c0c4 100644 --- a/CHDataManagement/Storage/SecurityBookmark.swift +++ b/CHDataManagement/Storage/SecurityBookmark.swift @@ -38,7 +38,7 @@ struct SecurityBookmark { } func fullPath(to relativePath: String) -> URL { - url.appending(path: relativePath, directoryHint: .notDirectory) + return url.appending(path: relativePath.withLeadingSlashRemoved, directoryHint: .notDirectory) } /** @@ -167,7 +167,7 @@ struct SecurityBookmark { return false } - let destination = url.appending(path: relativeDestination) + let destination = url.appending(path: relativeDestination.withLeadingSlashRemoved) if exists(destination) { switch overwrite { case .fail: @@ -328,11 +328,11 @@ struct SecurityBookmark { // MARK: Generic operations func with(relativePath: String, perform operation: (URL) -> Bool) -> Bool { - perform { operation($0.appending(path: relativePath)) } + perform { operation($0.appending(path: relativePath.withLeadingSlashRemoved)) } } func with(relativePath: String, perform operation: (URL) -> T?) -> T? { - perform { operation($0.appending(path: relativePath)) } + perform { operation($0.appending(path: relativePath.withLeadingSlashRemoved)) } } /**