diff --git a/cmd/build.go b/cmd/build.go index 7a727ee..10c641c 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -103,16 +103,21 @@ should be enough for the next successful build).`, attachmentsQuery := bibliographyNode.FindElements("[name()='link:link']") itemAttachments := zoteroUnion.CreateElement("attachments") + mimeTypeMap := make(map[string]bool) for _, attachment := range attachmentsQuery { attachmentID := attachment.SelectAttr("rdf:resource").Value zAttachment := root.FindElement(fmt.Sprintf("[@rdf:about='%s']", attachmentID)) mimeType := zAttachment.FindElement("[name()='link:type']").Text() if mimeType != "text/html" { - itemAttachment := itemAttachments.CreateElement("attachment") - attachmentsIDs[attachmentID] = true - filePath := zAttachment.FindElement("[name()='rdf:resource']").SelectAttr("rdf:resource").Value - itemAttachment.CreateElement("path").SetText(filePath) - itemAttachment.CreateElement("mimeType").SetText(mimeType) + if !mimeTypeMap[mimeType] { + attachmentsIDs[attachmentID] = true + filePath := zAttachment.FindElement("[name()='rdf:resource']").SelectAttr("rdf:resource").Value + itemAttachments.CreateElement("attachment").CreateElement("path").SetText(filePath) + itemAttachments.CreateElement("attachment").CreateElement("mimeType").SetText(mimeType) + mimeTypeMap[mimeType] = true + } else { + fmt.Println("DUPLICATE mimeType:", mimeType, attachmentID) + } } } @@ -206,8 +211,9 @@ should be enough for the next successful build).`, } zi, _ := xml.MarshalIndent(zoteroItem, " ", " ") - os.Stdout.Write(zi) - fmt.Println("\n~ ~ ~ ~ ~ ~") + _ = zi + // os.Stdout.Write(zi) + // fmt.Println("\n~+~ ~ ~ ~ ~") // fmt.Printf("\nZoteroItem: %#v\n", zoteroItem) bookOpf.Version = "2.0" @@ -227,8 +233,8 @@ should be enough for the next successful build).`, log.Fatalln(err) } _ = bookOpfOutput - //os.Stdout.Write(bookOpfOutput) - //fmt.Println("\n ~ ~ ~ ~ ~") + // os.Stdout.Write(bookOpfOutput) + // fmt.Println("\n ~ ~ ~ ~ ~") } calibre.RenderStandaloneApp(calibrePath, librarianName, libraryUUID, librarySecret, jsonPath) },