Fix page paths
Update PostListPageGenerator.swift
This commit is contained in:
parent
f8150e0809
commit
dd2b7d6cd2
@ -16,6 +16,13 @@ extension String {
|
|||||||
return decoded
|
return decoded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var withLeadingSlashRemoved: String {
|
||||||
|
if !hasPrefix("/") {
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
return String(dropFirst("/".count))
|
||||||
|
}
|
||||||
|
|
||||||
var removingSurroundingQuotes: String {
|
var removingSurroundingQuotes: String {
|
||||||
if hasPrefix("\"") && hasSuffix("\"") {
|
if hasPrefix("\"") && hasSuffix("\"") {
|
||||||
return dropBeforeFirst("\"").dropAfterLast("\"")
|
return dropBeforeFirst("\"").dropAfterLast("\"")
|
||||||
|
@ -23,7 +23,14 @@ struct FeedGeneratorSource: PostListPageGeneratorSource {
|
|||||||
content.settings.localized(in: language).description
|
content.settings.localized(in: language).description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The url to the page, including a leading slash
|
||||||
|
*/
|
||||||
func pageUrlPrefix(for language: ContentLanguage) -> String {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,8 @@ final class PostListPageGenerator {
|
|||||||
|
|
||||||
let feedPageGenerator = FeedPageGenerator(content: source.content, results: source.results)
|
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(
|
let fileContent = feedPageGenerator.generatePage(
|
||||||
language: language,
|
language: language,
|
||||||
|
@ -13,6 +13,9 @@ protocol PostListPageGeneratorSource {
|
|||||||
|
|
||||||
var pageDescription: String { get }
|
var pageDescription: String { get }
|
||||||
|
|
||||||
|
/**
|
||||||
|
The url to the page, including a leading slash
|
||||||
|
*/
|
||||||
func pageUrlPrefix(for language: ContentLanguage) -> String
|
func pageUrlPrefix(for language: ContentLanguage) -> String
|
||||||
|
|
||||||
var postsPerPage: Int { get }
|
var postsPerPage: Int { get }
|
||||||
|
@ -250,7 +250,11 @@ final class FileResource: Item {
|
|||||||
*/
|
*/
|
||||||
var absoluteUrl: String {
|
var absoluteUrl: String {
|
||||||
if let customOutputPath {
|
if let customOutputPath {
|
||||||
return customOutputPath
|
if customOutputPath.hasPrefix("/") {
|
||||||
|
return customOutputPath
|
||||||
|
} else {
|
||||||
|
return "/" + customOutputPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let path = pathPrefix + "/" + id
|
let path = pathPrefix + "/" + id
|
||||||
return makeCleanAbsolutePath(path)
|
return makeCleanAbsolutePath(path)
|
||||||
|
@ -2,6 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
struct PostFeedPageNavigation {
|
struct PostFeedPageNavigation {
|
||||||
|
|
||||||
|
/// Includes a leading slash
|
||||||
let linkPrefix: String
|
let linkPrefix: String
|
||||||
|
|
||||||
let currentPage: Int
|
let currentPage: Int
|
||||||
@ -15,7 +16,7 @@ struct PostFeedPageNavigation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func pageLink(_ page: Int) -> String {
|
private func pageLink(_ page: Int) -> String {
|
||||||
"href='/\(linkPrefix)/\(page)'"
|
"href='\(linkPrefix)/\(page)'"
|
||||||
}
|
}
|
||||||
|
|
||||||
private func addPreviousButton(to result: inout String) {
|
private func addPreviousButton(to result: inout String) {
|
||||||
|
@ -38,7 +38,7 @@ struct SecurityBookmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fullPath(to relativePath: String) -> URL {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
let destination = url.appending(path: relativeDestination)
|
let destination = url.appending(path: relativeDestination.withLeadingSlashRemoved)
|
||||||
if exists(destination) {
|
if exists(destination) {
|
||||||
switch overwrite {
|
switch overwrite {
|
||||||
case .fail:
|
case .fail:
|
||||||
@ -328,11 +328,11 @@ struct SecurityBookmark {
|
|||||||
// MARK: Generic operations
|
// MARK: Generic operations
|
||||||
|
|
||||||
func with(relativePath: String, perform operation: (URL) -> Bool) -> Bool {
|
func with(relativePath: String, perform operation: (URL) -> Bool) -> Bool {
|
||||||
perform { operation($0.appending(path: relativePath)) }
|
perform { operation($0.appending(path: relativePath.withLeadingSlashRemoved)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func with<T>(relativePath: String, perform operation: (URL) -> T?) -> T? {
|
func with<T>(relativePath: String, perform operation: (URL) -> T?) -> T? {
|
||||||
perform { operation($0.appending(path: relativePath)) }
|
perform { operation($0.appending(path: relativePath.withLeadingSlashRemoved)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user