Consistent sorting of output
This commit is contained in:
@ -13,14 +13,17 @@ struct AudioPlayerScript: HtmlProducer {
|
||||
|
||||
let items: [AmplitudeSong]
|
||||
|
||||
private let encoder = JSONEncoder()
|
||||
|
||||
init(items: [AmplitudeSong]) {
|
||||
self.items = items
|
||||
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
|
||||
}
|
||||
|
||||
func populate(_ result: inout String) {
|
||||
result += "<script>\nwindow.onload = () => { "
|
||||
result += "Amplitude.init({ songs: "
|
||||
let songData = try! JSONEncoder().encode(items)
|
||||
let songData = try! encoder.encode(items)
|
||||
result += String(data: songData, encoding: .utf8)!
|
||||
result += "}); };\n" // Close Amplitude.init and window.onload
|
||||
result += "function playEntry(index) { Amplitude.playSongAtIndex(index) };"
|
||||
|
Reference in New Issue
Block a user