Fixes quotes in progress and episode fields

This commit is contained in:
Óscar M. Lage 2024-12-12 13:19:38 +01:00
parent 9ba5647ddc
commit bd4b1c3059

View File

@ -106,16 +106,16 @@ func SaveUpdatedMarkdown(filepath string, frontmatter FrontMatter, content strin
fileContent := string(fileBytes)
fieldPatterns := map[string]string{
"progress": `(?m)^progress: "(.*)%"$`,
"episode": `(?m)^episode: "(.*)"$`,
"progress": `(?m)^progress: (.*)%$`,
"episode": `(?m)^episode: (.*)$`,
"date": `(?m)^date: (.*)$`,
"rate": `(?m)^rate: (\d+\.?\d*)$`,
}
// Fields replacement
fileContent = updateFieldInFrontmatter(fileContent, "progress", fmt.Sprintf("\"%s\"", frontmatter.Progress), fieldPatterns["progress"])
fileContent = updateFieldInFrontmatter(fileContent, "episode", fmt.Sprintf("\"%s\"", frontmatter.Episode), fieldPatterns["episode"])
fileContent = updateFieldInFrontmatter(fileContent, "date", fmt.Sprintf("\"%s\"", frontmatter.Date), fieldPatterns["date"])
fileContent = updateFieldInFrontmatter(fileContent, "progress", fmt.Sprintf("%s", frontmatter.Progress), fieldPatterns["progress"])
fileContent = updateFieldInFrontmatter(fileContent, "episode", fmt.Sprintf("%s", frontmatter.Episode), fieldPatterns["episode"])
fileContent = updateFieldInFrontmatter(fileContent, "date", fmt.Sprintf("%s", frontmatter.Date), fieldPatterns["date"])
fileContent = updateFieldInFrontmatterFloat(fileContent, "rate", frontmatter.Rate, fieldPatterns["rate"])
// Write the updated content back to the file