@@ -9,27 +9,30 @@ const Wiki = sites => {
99 const authors = new Set()
1010 const terms = new Set()
1111
12− const storeEntry = (author, url, parent, cat, entry) => {
13− if (!(parent in entries)) {
14− entries[parent] = {}
15− entries[parent][cat] = [{ entry, author, url }]
16− } else if (!(cat in entries[parent])) {
17− entries[parent][cat] = [{ entry, author, url }]
12+ const storeEntry = (author, url, category, term, entry) => {
13+ if (!(category in entries)) {
14+ entries[category] = {}
15+ entries[category][term] = [{ entry, authors: [{ author, url }] }]
16+ } else if (!(term in entries[category])) {
17+ entries[category][term] = [{ entry, authors: [{ author, url }] }]
1818 } else {
19− entries[parent][cat].push({ entry, author, url })
19+ const possibleIndex = entries[category][term].findIndex(existing => existing.entry === entry)
20+ possibleIndex > -1
21+ ? entries[category][term][possibleIndex].authors.push({ author, url })
22+ : entries[category][term].push({ entry, authors: [{ author, url }] })
2023 }
21− terms.add(cat)
24+ terms.add(term)
2225 authors.add(author)
2326 }
2427
25− const storeEntries = (author, url, parent, entries) => {
28+ const storeEntries = (author, url, category, entries) => {
2629 Array.isArray(entries)
27− ? storeEntry(author, url, parent, 'list-definitions', entries)
28− : Object.keys(entries).forEach(entry => storeEntry(author, url, parent, entry, entries[entry]))
30+ ? storeEntry(author, url, category, 'list-definitions', entries)
31+ : Object.keys(entries).forEach(entry => storeEntry(author, url, category, entry, entries[entry]))
2932 }
3033
3134 const transform = (author, url, ndtl) => {
32− Object.keys(ndtl).forEach(cat => storeEntries(author, url, cat, ndtl[cat]))
35+ Object.keys(ndtl).forEach(category => storeEntries(author, url, category, ndtl[category]))
3336 }
3437
3538 const parse = (site, content) => {
@@ -60,15 +63,19 @@ const Wiki = sites => {
6063 '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>'
6164 )
6265
66+ const formatAuthor = (authors, author) => {
67+ return `${authors}<a class='author' target='_blank' href='${author.url}'> @${author.author}</a>`
68+ }
69+
6370 const formatEntry = (definitions, definition) => {
6471 const formatEntryList = entryList => entryList.reduce((items, item) => `${items}<li>${formatLinks(item)}</li>`, '')
6572
6673 const newHtml = typeof definition.entry === 'string'
6774 ? `<li>${formatLinks(definition.entry)}
68− - <a class='author' target='_blank' href='${definition.url}'> @${definition.author}</a>
75+ - ${definition.authors.reduce(formatAuthor, '')}
6976 </li>`
7077 : `<li><ul>${formatEntryList(definition.entry)}
71− <a class='author' target='_blank' href='${definition.url}'> — @${definition.author}</a>
78+ - ${definition.authors.reduce(formatAuthor, '')}
7279 </ul></li>`
7380
7481 return `${definitions}${newHtml}`