Added --update param to games
This commit is contained in:
parent
c9a30a3767
commit
2ec7e6cd85
@ -25,12 +25,29 @@ func LoadGames() ([]Game, error) {
|
||||
return games, nil
|
||||
}
|
||||
|
||||
func ProcessGames(games []Game) error {
|
||||
func ProcessGames(games []Game, update bool) error {
|
||||
fmt.Printf(" G A M E S\n")
|
||||
utils.Sep()
|
||||
for _, game := range games {
|
||||
fmt.Printf("Title: %s\n", game.Title)
|
||||
|
||||
// If we're updating, the process is a bit different
|
||||
if update {
|
||||
outputDir := os.Getenv("MARKDOWN_OUTPUT_GAMES_DIR")
|
||||
mdFilePath := filepath.Join(outputDir, fmt.Sprintf("%s.md", utils.Sluggify(game.Title)))
|
||||
frontmatter, content, err := utils.LoadMarkdown(mdFilePath)
|
||||
if err != nil {
|
||||
fmt.Printf(" ! Error loading markdown frontmatter for game %s: %v\n", game.Title, err)
|
||||
continue
|
||||
}
|
||||
updatedFrontmatter := updateFrontmatterWithYAML(frontmatter, game)
|
||||
err = utils.SaveUpdatedMarkdown(mdFilePath, updatedFrontmatter, content)
|
||||
if err != nil {
|
||||
fmt.Printf(" ! Error saving updated markdown for game %s: %v\n", game.Title, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// If we dont have ID, search movie by Title and get the ID
|
||||
if game.ID == 0 {
|
||||
err := SearchGameByTitle(game.Title, &game)
|
||||
@ -102,3 +119,11 @@ func generateGameMarkdown(game Game) error {
|
||||
|
||||
return utils.GenerateMarkdown(templatePath, outputPath, data)
|
||||
}
|
||||
|
||||
// Helper function to update only YAML fields that exist in both the frontmatter and YAML data
|
||||
func updateFrontmatterWithYAML(frontmatter utils.FrontMatter, game Game) utils.FrontMatter {
|
||||
frontmatter.Progress = game.Progress
|
||||
frontmatter.Date = game.Date
|
||||
frontmatter.Rate = game.Rate
|
||||
return frontmatter
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user