Skip to content

Instantly share code, notes, and snippets.

@jchapuis
Created August 12, 2024 18:05
Show Gist options
  • Save jchapuis/057628d190d9d3db619334bee96efd8e to your computer and use it in GitHub Desktop.
Save jchapuis/057628d190d9d3db619334bee96efd8e to your computer and use it in GitHub Desktop.
Update index files
def updateIndexFiles(newFile: IndexPage.File) =
for {
_ <- logger.info("Retrieving index page")
files <- getIndexByNamePage.map(IndexPage.parseFiles)
_ <- logger.info(s"Retrieved index page with ${files.size} files")
_ <- uploadNewIndexFiles(files, newFile)
} yield ()
def uploadNewIndexFiles(files: List[IndexPage.File], newFile: IndexPage.File) = {
val newFiles = files.toSet + newFile
val newIndexByName = IndexPage.render(IndexPage.Sorting.Name, newFiles)
val newIndexByDescription = IndexPage.render(IndexPage.Sorting.Description, newFiles)
val newIndexByWordCount = IndexPage.render(IndexPage.Sorting.WordCount, newFiles)
val mimeType = "text/html"
(
uploadFileStream(newIndexByName, IndexPage.indexByNamePage, mimeType),
uploadFileStream(newIndexByDescription, IndexPage.indexByDescriptionPage, mimeType),
uploadFileStream(newIndexByWordCount, IndexPage.indexByWordCountPage, mimeType)
).parTupled.void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment