From 88d4c14cbb3472b21629c7769db3276049e68737 Mon Sep 17 00:00:00 2001 From: Ben Syverson Date: Mon, 27 Jan 2020 13:05:26 -0600 Subject: [PATCH 1/5] Uses filename as fallback for item title --- Sources/Publish/Internal/MarkdownContentFactory.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Publish/Internal/MarkdownContentFactory.swift b/Sources/Publish/Internal/MarkdownContentFactory.swift index 1f06cc06..c6b461fb 100644 --- a/Sources/Publish/Internal/MarkdownContentFactory.swift +++ b/Sources/Publish/Internal/MarkdownContentFactory.swift @@ -69,7 +69,7 @@ private extension MarkdownContentFactory { let video = try decoder.decodeIfPresent("video", as: Video.self) return Content( - title: title ?? markdown.title ?? "", + title: title ?? markdown.title ?? file.nameExcludingExtension, description: description ?? "", body: Content.Body(html: markdown.html), date: date, From 19d4aaeec43d8c2494c1dc16c4007d32419a5367 Mon Sep 17 00:00:00 2001 From: Ben Syverson Date: Tue, 28 Jan 2020 10:50:58 -0600 Subject: [PATCH 2/5] Test excludedPaths in SiteMap using prefixes rather than exact match --- .../Internal/Collection+ContainsPrefix.swift | 14 ++++++++++++++ .../Publish/Internal/MarkdownContentFactory.swift | 2 +- Sources/Publish/Internal/SiteMapGenerator.swift | 12 +++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 Sources/Publish/Internal/Collection+ContainsPrefix.swift diff --git a/Sources/Publish/Internal/Collection+ContainsPrefix.swift b/Sources/Publish/Internal/Collection+ContainsPrefix.swift new file mode 100644 index 00000000..283c0956 --- /dev/null +++ b/Sources/Publish/Internal/Collection+ContainsPrefix.swift @@ -0,0 +1,14 @@ +// +// Collection+ContainsPrefix.swift +// +// +// Created by Ben Syverson on 2020/01/28. +// + +import Foundation + +internal extension Collection where Element: StringWrapper { + func containsPrefixFor(_ string: String) -> Bool { + reduce(false){ $0 || string.hasPrefix($1.string) } + } +} diff --git a/Sources/Publish/Internal/MarkdownContentFactory.swift b/Sources/Publish/Internal/MarkdownContentFactory.swift index c6b461fb..1f06cc06 100644 --- a/Sources/Publish/Internal/MarkdownContentFactory.swift +++ b/Sources/Publish/Internal/MarkdownContentFactory.swift @@ -69,7 +69,7 @@ private extension MarkdownContentFactory { let video = try decoder.decodeIfPresent("video", as: Video.self) return Content( - title: title ?? markdown.title ?? file.nameExcludingExtension, + title: title ?? markdown.title ?? "", description: description ?? "", body: Content.Body(html: markdown.html), date: date, diff --git a/Sources/Publish/Internal/SiteMapGenerator.swift b/Sources/Publish/Internal/SiteMapGenerator.swift index b196c7d4..688708ac 100644 --- a/Sources/Publish/Internal/SiteMapGenerator.swift +++ b/Sources/Publish/Internal/SiteMapGenerator.swift @@ -27,11 +27,17 @@ struct SiteMapGenerator { } } +internal extension Collection where Element: StringWrapper { + func containsPath(_ path: Path) -> Bool { + containsPrefixFor(path.string) + } +} + private extension SiteMapGenerator { func makeSiteMap(for sections: [Section], pages: [Page], site: Site) -> SiteMap { SiteMap( .forEach(sections) { section in - guard !excludedPaths.contains(section.path) else { + guard !excludedPaths.containsPath(section.path) else { return .empty } @@ -46,7 +52,7 @@ private extension SiteMapGenerator { )) ), .forEach(section.items) { item in - guard !excludedPaths.contains(item.path) else { + guard !excludedPaths.containsPath(item.path) else { return .empty } @@ -60,7 +66,7 @@ private extension SiteMapGenerator { ) }, .forEach(pages) { page in - guard !excludedPaths.contains(page.path) else { + guard !excludedPaths.containsPath(page.path) else { return .empty } From b139a991e3af27b0c508d6933ebe491fe8a08687 Mon Sep 17 00:00:00 2001 From: Ben Syverson Date: Sat, 12 Sep 2020 15:19:13 -0500 Subject: [PATCH 3/5] Inlines path prefix check, and adds test cases to SiteMapGenerationTests --- .../Internal/Collection+ContainsPrefix.swift | 14 -------------- Sources/Publish/Internal/SiteMapGenerator.swift | 3 ++- .../Tests/SiteMapGenerationTests.swift | 6 ++++++ 3 files changed, 8 insertions(+), 15 deletions(-) delete mode 100644 Sources/Publish/Internal/Collection+ContainsPrefix.swift diff --git a/Sources/Publish/Internal/Collection+ContainsPrefix.swift b/Sources/Publish/Internal/Collection+ContainsPrefix.swift deleted file mode 100644 index 283c0956..00000000 --- a/Sources/Publish/Internal/Collection+ContainsPrefix.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// Collection+ContainsPrefix.swift -// -// -// Created by Ben Syverson on 2020/01/28. -// - -import Foundation - -internal extension Collection where Element: StringWrapper { - func containsPrefixFor(_ string: String) -> Bool { - reduce(false){ $0 || string.hasPrefix($1.string) } - } -} diff --git a/Sources/Publish/Internal/SiteMapGenerator.swift b/Sources/Publish/Internal/SiteMapGenerator.swift index 688708ac..8fea7d73 100644 --- a/Sources/Publish/Internal/SiteMapGenerator.swift +++ b/Sources/Publish/Internal/SiteMapGenerator.swift @@ -29,7 +29,7 @@ struct SiteMapGenerator { internal extension Collection where Element: StringWrapper { func containsPath(_ path: Path) -> Bool { - containsPrefixFor(path.string) + contains(where: { path.string.hasPrefix($0.string) }) } } @@ -37,6 +37,7 @@ private extension SiteMapGenerator { func makeSiteMap(for sections: [Section], pages: [Page], site: Site) -> SiteMap { SiteMap( .forEach(sections) { section in + print("Excluded paths: \(excludedPaths)") guard !excludedPaths.containsPath(section.path) else { return .empty } diff --git a/Tests/PublishTests/Tests/SiteMapGenerationTests.swift b/Tests/PublishTests/Tests/SiteMapGenerationTests.swift index eefe808e..983f4dcf 100644 --- a/Tests/PublishTests/Tests/SiteMapGenerationTests.swift +++ b/Tests/PublishTests/Tests/SiteMapGenerationTests.swift @@ -40,11 +40,14 @@ final class SiteMapGenerationTests: PublishTestCase { .addItem(.stub(withPath: "itemB")), .addItem(.stub(withPath: "itemC", sectionID: .two)), .addItem(.stub(withPath: "itemD", sectionID: .two)), + .addItem(.stub(withPath: "itemE", sectionID: .three)), + .addItem(.stub(withPath: "posts/itemF", sectionID: .three)), .addPage(.stub(withPath: "pageA")), .addPage(.stub(withPath: "pageB")), .generateSiteMap(excluding: [ "one/itemB", "two", + "three/posts/", "pageB" ]) ]) @@ -55,6 +58,7 @@ final class SiteMapGenerationTests: PublishTestCase { let expectedLocations = [ "https://swiftbysundell.com/one", "https://swiftbysundell.com/one/itemA", + "https://swiftbysundell.com/three/itemE", "https://swiftbysundell.com/pageA" ] @@ -63,6 +67,7 @@ final class SiteMapGenerationTests: PublishTestCase { "https://swiftbysundell.com/two", "https://swiftbysundell.com/two/itemC", "https://swiftbysundell.com/two/itemD", + "https://swiftbysundell.com/three/posts/itemF", "https://swiftbysundell.com/pageB" ] @@ -77,6 +82,7 @@ final class SiteMapGenerationTests: PublishTestCase { XCTAssertNotNil(site.sections[.one].item(at: "itemB")) XCTAssertNotNil(site.sections[.two].item(at: "itemC")) XCTAssertNotNil(site.sections[.two].item(at: "itemD")) + XCTAssertNotNil(site.sections[.three].item(at: "itemE")) XCTAssertNotNil(site.pages["pageB"]) } } From 18a552bdafcc6a1b40530bc122ec8d38797a11a5 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 30 Dec 2020 15:41:42 +0100 Subject: [PATCH 4/5] SiteMapGenerator: Move path exclusion logic to a private method --- Sources/Publish/Internal/SiteMapGenerator.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Publish/Internal/SiteMapGenerator.swift b/Sources/Publish/Internal/SiteMapGenerator.swift index 8fea7d73..632877f4 100644 --- a/Sources/Publish/Internal/SiteMapGenerator.swift +++ b/Sources/Publish/Internal/SiteMapGenerator.swift @@ -27,18 +27,18 @@ struct SiteMapGenerator { } } -internal extension Collection where Element: StringWrapper { - func containsPath(_ path: Path) -> Bool { - contains(where: { path.string.hasPrefix($0.string) }) +private extension SiteMapGenerator { + func shouldIncludePath(_ path: Path) -> Bool { + !excludedPaths.contains(where: { + path.string.hasPrefix($0.string) + }) } -} -private extension SiteMapGenerator { func makeSiteMap(for sections: [Section], pages: [Page], site: Site) -> SiteMap { SiteMap( .forEach(sections) { section in print("Excluded paths: \(excludedPaths)") - guard !excludedPaths.containsPath(section.path) else { + guard shouldIncludePath(section.path) else { return .empty } @@ -53,7 +53,7 @@ private extension SiteMapGenerator { )) ), .forEach(section.items) { item in - guard !excludedPaths.containsPath(item.path) else { + guard shouldIncludePath(item.path) else { return .empty } @@ -67,7 +67,7 @@ private extension SiteMapGenerator { ) }, .forEach(pages) { page in - guard !excludedPaths.containsPath(page.path) else { + guard shouldIncludePath(page.path) else { return .empty } From 05d20e56a0cd4bb7e6d1b4b2258589b785dc0267 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 30 Dec 2020 15:42:47 +0100 Subject: [PATCH 5/5] SiteMapGenerator: Remove print statement --- Sources/Publish/Internal/SiteMapGenerator.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Publish/Internal/SiteMapGenerator.swift b/Sources/Publish/Internal/SiteMapGenerator.swift index 632877f4..02463eac 100644 --- a/Sources/Publish/Internal/SiteMapGenerator.swift +++ b/Sources/Publish/Internal/SiteMapGenerator.swift @@ -37,7 +37,6 @@ private extension SiteMapGenerator { func makeSiteMap(for sections: [Section], pages: [Page], site: Site) -> SiteMap { SiteMap( .forEach(sections) { section in - print("Excluded paths: \(excludedPaths)") guard shouldIncludePath(section.path) else { return .empty }