Skip to content

Commit

Permalink
WIP: Update props for pagination (#103).
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Dec 31, 2020
1 parent db1c547 commit d6ad417
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/build/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,14 @@ func DataSource(buildPath string, siteConfig readers.SiteConfig, tempBuildDir st

createProps(currentContent, allContentStr, tempBuildDirSignature)

paginate(currentContent, contentJSPath)

createHTML(currentContent)

allPaginatedContent := paginate(currentContent, contentJSPath)
for _, paginatedContent := range allPaginatedContent {
createProps(paginatedContent, allContentStr, tempBuildDirSignature)
createHTML(paginatedContent)
}

}

// Complete the content.js file.
Expand Down Expand Up @@ -224,8 +228,9 @@ func createHTML(currentContent content) {
}
}

func paginate(currentContent content, contentJSPath string) {
func paginate(currentContent content, contentJSPath string) []content {
paginatedContent, rePaginate := getPagination()
allNewContent := []content{}
// Loop through all :paginate() replacements found in config file.
for _, pager := range paginatedContent {
// Check if the config file specifies pagination for this Type.
Expand All @@ -250,20 +255,21 @@ func paginate(currentContent content, contentJSPath string) {
newContent.contentDest = rePaginate.ReplaceAllString(currentContent.contentPagerDest, currentPageNumber)
// Add current page number to the content source so it can be pulled in as the current page.
newContent.contentDetails = "{\n" +
"\"pager\": \"" + currentPageNumber + "\",\n" +
"\"pager\": " + currentPageNumber + ",\n" +
"\"path\": \"" + newContent.contentPath + "\",\n" +
"\"type\": \"" + newContent.contentType + "\",\n" +
"\"filename\": \"" + newContent.contentFilename + "\",\n" +
"\"fields\": " + newContent.contentFields + "\n}"

// Add paginated entries to content.js file.
writeContentJS(contentJSPath, newContent.contentDetails+",")
// Create paginated static HTML fallbacks.
createHTML(newContent)
// Add to array of content for creating paginated static HTML fallbacks.
allNewContent = append(allNewContent, newContent)
}
}
}
}
return allNewContent
}

func writeContentJS(contentJSPath string, contentDetailsStr string) {
Expand Down

0 comments on commit d6ad417

Please sign in to comment.