newAttachableDocuments scans every document and refuses what no upload can fix, so that nothing uploads for a set of documents that cannot take it.
(docs []Document, assets []UserAsset)
| 159 | // newAttachableDocuments scans every document and refuses what no upload can |
| 160 | // fix, so that nothing uploads for a set of documents that cannot take it. |
| 161 | func newAttachableDocuments(docs []Document, assets []UserAsset) ([]attachableDocument, error) { |
| 162 | out := make([]attachableDocument, len(docs)) |
| 163 | referenced := make([]bool, len(assets)) |
| 164 | for i, doc := range docs { |
| 165 | args := newAttachmentArgs(assets) |
| 166 | md, err := newAttachableMarkdown(doc.Markdown, doc.Dir, args) |
| 167 | if err != nil { |
| 168 | return nil, err |
| 169 | } |
| 170 | isAttachment := make([]bool, len(assets)) |
| 171 | for _, r := range md.refs { |
| 172 | isAttachment[r.attachmentArg] = true |
| 173 | referenced[r.attachmentArg] = true |
| 174 | } |
| 175 | out[i] = attachableDocument{md: md, args: args, isAttachment: isAttachment} |
| 176 | } |
| 177 | |
| 178 | if len(docs) == 1 { |
| 179 | // The only document is where every file goes, so the files it does |
| 180 | // not reference are appended to it. |
| 181 | for i := range out[0].isAttachment { |
| 182 | out[0].isAttachment[i] = true |
| 183 | } |
| 184 | return out, nil |
| 185 | } |
| 186 | |
| 187 | var unreferenced []string |
| 188 | for i, a := range assets { |
| 189 | if !referenced[i] { |
| 190 | unreferenced = append(unreferenced, a.Path()) |
| 191 | } |
| 192 | } |
| 193 | if len(unreferenced) > 0 { |
| 194 | return nil, &UnreferencedError{Paths: unreferenced} |
| 195 | } |
| 196 | return out, nil |
| 197 | } |
| 198 | |
| 199 | // newAttachmentArgs describes each asset for the markdown half of the |
| 200 | // package, without a URL, since nothing has uploaded yet. |
no test coverage detected