Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interprets excludedPaths as path prefixes in the SiteMap generator #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Sources/Publish/Internal/SiteMapGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ struct SiteMapGenerator<Site: Website> {
}

private extension SiteMapGenerator {
func shouldIncludePath(_ path: Path) -> Bool {
!excludedPaths.contains(where: {
path.string.hasPrefix($0.string)
})
}

func makeSiteMap(for sections: [Section<Site>], pages: [Page], site: Site) -> SiteMap {
SiteMap(
.forEach(sections) { section in
guard !excludedPaths.contains(section.path) else {
guard shouldIncludePath(section.path) else {
return .empty
}

Expand All @@ -46,7 +52,7 @@ private extension SiteMapGenerator {
))
),
.forEach(section.items) { item in
guard !excludedPaths.contains(item.path) else {
guard shouldIncludePath(item.path) else {
return .empty
}

Expand All @@ -60,7 +66,7 @@ private extension SiteMapGenerator {
)
},
.forEach(pages) { page in
guard !excludedPaths.contains(page.path) else {
guard shouldIncludePath(page.path) else {
return .empty
}

Expand Down
6 changes: 6 additions & 0 deletions Tests/PublishTests/Tests/SiteMapGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
])
])
Expand All @@ -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"
]

Expand All @@ -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"
]

Expand All @@ -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"])
}
}
Expand Down