This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
76 lines (62 loc) · 1.76 KB
/
library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
const meta = require.main.require('./src/meta');
const routesHelpers = require.main.require('./src/routes/helpers');
let app;
const Widget = {
settings: {},
};
const SUPPORTED_PLATFORMS = ['discord', 'tiktok', 'youtube', 'vk', 'instagram', 'twitter', 'twitch'];
/**
* Called on `static:app.load`
*/
Widget.init = async function (params) {
app = params.app;
const renderAdmin = async (req, res) => {
res.render(`admin/plugins/social-links`);
};
routesHelpers.setupAdminPageRoute(params.router, `/admin/plugins/social-links`, params.middleware, [], renderAdmin);
Widget.settings = await meta.settings.get('social-links');
};
/**
* Called on `filter:admin.header.build`
*/
Widget.adminMenu = async function (header) {
header.plugins.push({
route: `/plugins/social-links`,
name: 'Social Links',
});
return header;
};
/**
* Called on `filter:widgets.getWidgets`
*/
Widget.defineWidgets = async function (widgets) {
return widgets.concat([
{
widget: 'aa_social-links_line',
name: 'Social Links - Line',
description: 'Display random social link as a line',
content: await app.renderAsync('admin/widgets/social-links_line', {}),
},
]);
};
/**
* Called on `filter:widget.render:aa_social-links_line`
*/
Widget.renderSocialLinksLineWidget = async function (widget) {
const items = [];
for (const PLATFORM of SUPPORTED_PLATFORMS) {
const value = widget.data[`${PLATFORM}_link`] || Widget.settings[`${PLATFORM}_link`];
if (value) {
items.push({ type: PLATFORM, link: value });
}
}
if (!items.length) {
widget.html = '';
return widget;
}
const randomLink = items[Math.floor(Math.random() * items.length)];
widget.html = await app.renderAsync('widgets/social-links_line', randomLink);
return widget;
};
module.exports = Widget;