From a954e22d3bc00027f67e273d50001c206b2792c2 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 31 Mar 2024 09:22:32 -0700 Subject: [PATCH] Story undupe --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 12a4270..76e7695 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,8 @@ func injectStories(table Table, path string, heisigIndex int) error { return err } + seenStories := make(map[string]bool) + for i, row := range table { for _, character := range characters { if character.Character != row[heisigIndex] { @@ -63,8 +65,13 @@ func injectStories(table Table, path string, heisigIndex int) error { var stories strings.Builder for _, story := range character.Stories { - content := strings.ReplaceAll(story.Content, "\n", " ") - stories.WriteString(wrapSpan(content, "rtk-story")) + storyNoBreaks := strings.ReplaceAll(story.Content, "\n", " ") + if seen, _ := seenStories[storyNoBreaks]; seen { + continue + } else { + stories.WriteString(wrapSpan(storyNoBreaks, "rtk-story")) + seenStories[storyNoBreaks] = true + } } row = append(row, stories.String())