File size: 970 Bytes
faf4ba4
c32ec0d
5dd2af5
2f7798c
faf4ba4
2f7798c
c32ec0d
 
 
 
 
2f7798c
faf4ba4
2f7798c
c32ec0d
 
95a4e14
c32ec0d
 
95a4e14
 
 
c32ec0d
 
 
 
 
95a4e14
c32ec0d
2f7798c
c32ec0d
2f7798c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { GeneratedPanel } from "@/types"
import { cleanJson } from "./cleanJson"
import { parseBadJSON } from "./parseBadJSON"

export function dirtyGeneratedPanelsParser(input: string): GeneratedPanel[] {

  if (input.includes("```")) {
    input = input.split("```")[0]
  }
  // we only keep what's after the first [
  let jsonOrNot = cleanJson(input)

  const jsonData = parseBadJSON(jsonOrNot) as GeneratedPanel[]

  const results = jsonData.map((item, i) => {
    let panel = i
    let speech = item.speech ? item.speech.trim() : ''
    let caption = item.caption ? item.caption.trim() : ''
    let instructions = item.instructions ? item.instructions.trim() : ''
    if (!instructions && !caption && speech) {
      instructions = speech
    } else if (!instructions && caption) {
      instructions = caption
    } 
    if (!caption && instructions) {
      caption = instructions
    }
    return { panel, speech, caption, instructions }
  })

  return results
}