Files: 038a737d7b268452a2d1ca1cd1e3ade9b5e966ff / modules_basic / message-backlinks.js
889 bytesRaw
1 | var fs = require('fs') |
2 | var Path = require('path') |
3 | var h = require('../h') |
4 | |
5 | exports.gives = { |
6 | message_backlinks: true, |
7 | mcss: true |
8 | } |
9 | |
10 | exports.create = function (api) { |
11 | return { |
12 | message_backlinks, |
13 | mcss: () => fs.readFileSync(Path.join(__dirname, 'message-backlinks.mcss')) |
14 | } |
15 | |
16 | function message_backlinks (msg) { |
17 | var links = [] |
18 | for(var k in CACHE) { |
19 | var _msg = CACHE[k] |
20 | if(Array.isArray(_msg.content.mentions)) { |
21 | for(var i = 0; i < _msg.content.mentions.length; i++) |
22 | if(_msg.content.mentions[i].link == msg.key) |
23 | links.push(k) |
24 | } |
25 | } |
26 | |
27 | if (links.length === 0) return null |
28 | |
29 | return h('MessageBacklinks', [ |
30 | h('header', 'backlinks:'), |
31 | h('ul', links.map(function (link) { |
32 | return h('li', [ |
33 | h('a -backlink', { |
34 | href: `#${link}` |
35 | }, link) |
36 | ]) |
37 | })) |
38 | ]) |
39 | } |
40 | } |
41 |
Built with git-ssb-web