git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: c18b233c6d62741496978cd8dc1f34a093946f8b

Files: c18b233c6d62741496978cd8dc1f34a093946f8b / message / html / backlinks.js

898 bytesRaw
1const fs = require('fs')
2const h = require('mutant/h')
3
4exports.needs = {
5 message_name: 'first'
6}
7
8exports.gives = 'message_backlinks'
9
10exports.create = function (api) {
11 return function (msg) {
12 var links = []
13 for (var k in CACHE) {
14 var _msg = CACHE[k]
15 var mentions = _msg.content.mentions
16
17 if (Array.isArray(mentions)) {
18 for (var i = 0; i < mentions.length; i++) {
19 if (mentions[i].link == msg.key) {
20 links.push(k)
21 }
22 }
23 }
24 }
25
26 if (links.length === 0) return null
27
28 var hrefList = h('ul')
29 links.forEach(link => {
30 api.message_name(link, (err, name) => {
31 if (err) throw err
32 hrefList.appendChild(h('li', [
33 h('a -backlink', { href: `#${link}` }, name)
34 ]))
35 })
36 })
37 return h('MessageBacklinks', [
38 h('header', 'backlinks:'),
39 hrefList
40 ])
41 }
42}
43

Built with git-ssb-web