Skip to content

Commit

Permalink
doc: added some code comments since I already forgot the logic behind…
Browse files Browse the repository at this point in the history
… the paginator
  • Loading branch information
kevinrenskers committed Mar 4, 2021
1 parent 1ed1501 commit 4241299
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Saga/Writer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private extension Writer {
let ranges = items.chunked(into: perPage)
let numberOfPages = ranges.count

// First we write the first page to the "main" destination, for example /articles/index.html
if let firstItems = ranges.first {
let nextPage = Path(paginatedOutput.string.replacingOccurrences(of: "[page]", with: "2")).makeOutputPath(itemWriteMode: .keepAsFile)

Expand All @@ -143,6 +144,7 @@ private extension Writer {
try fileIO.write(outputRoot + outputPrefix + output, node)
}

// Then we write all the pages to their paginated paths, for example /articles/page/[page]/index.html
for (index, items) in ranges.enumerated() {
let currentPage = index + 1
let previousPage = Path(paginatedOutput.string.replacingOccurrences(of: "[page]", with: "\(currentPage - 1)")).makeOutputPath(itemWriteMode: .keepAsFile)
Expand Down

0 comments on commit 4241299

Please sign in to comment.