From d6ad417fde0f52023681ef23efd6d9e5973dbbe6 Mon Sep 17 00:00:00 2001 From: jimafisk Date: Wed, 30 Dec 2020 22:29:36 -0500 Subject: [PATCH] WIP: Update props for pagination (#103). --- cmd/build/data_source.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/build/data_source.go b/cmd/build/data_source.go index 448d1dd0..55fa6b56 100644 --- a/cmd/build/data_source.go +++ b/cmd/build/data_source.go @@ -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. @@ -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. @@ -250,7 +255,7 @@ 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" + @@ -258,12 +263,13 @@ func paginate(currentContent content, contentJSPath string) { // 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) {