multiple attachments in attachments zoteroItem

This commit is contained in:
Marcell Mars 2022-04-28 13:36:05 +02:00
parent 3a505ce022
commit 55777c078a
1 changed files with 15 additions and 9 deletions

View File

@ -103,16 +103,21 @@ should be enough for the next successful build).`,
attachmentsQuery := bibliographyNode.FindElements("[name()='link:link']") attachmentsQuery := bibliographyNode.FindElements("[name()='link:link']")
itemAttachments := zoteroUnion.CreateElement("attachments") itemAttachments := zoteroUnion.CreateElement("attachments")
mimeTypeMap := make(map[string]bool)
for _, attachment := range attachmentsQuery { for _, attachment := range attachmentsQuery {
attachmentID := attachment.SelectAttr("rdf:resource").Value attachmentID := attachment.SelectAttr("rdf:resource").Value
zAttachment := root.FindElement(fmt.Sprintf("[@rdf:about='%s']", attachmentID)) zAttachment := root.FindElement(fmt.Sprintf("[@rdf:about='%s']", attachmentID))
mimeType := zAttachment.FindElement("[name()='link:type']").Text() mimeType := zAttachment.FindElement("[name()='link:type']").Text()
if mimeType != "text/html" { if mimeType != "text/html" {
itemAttachment := itemAttachments.CreateElement("attachment") if !mimeTypeMap[mimeType] {
attachmentsIDs[attachmentID] = true attachmentsIDs[attachmentID] = true
filePath := zAttachment.FindElement("[name()='rdf:resource']").SelectAttr("rdf:resource").Value filePath := zAttachment.FindElement("[name()='rdf:resource']").SelectAttr("rdf:resource").Value
itemAttachment.CreateElement("path").SetText(filePath) itemAttachments.CreateElement("attachment").CreateElement("path").SetText(filePath)
itemAttachment.CreateElement("mimeType").SetText(mimeType) 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, " ", " ") zi, _ := xml.MarshalIndent(zoteroItem, " ", " ")
os.Stdout.Write(zi) _ = zi
fmt.Println("\n~ ~ ~ ~ ~ ~") // os.Stdout.Write(zi)
// fmt.Println("\n~+~ ~ ~ ~ ~")
// fmt.Printf("\nZoteroItem: %#v\n", zoteroItem) // fmt.Printf("\nZoteroItem: %#v\n", zoteroItem)
bookOpf.Version = "2.0" bookOpf.Version = "2.0"