Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / handlers / social-metadata-generator.js
bloba801c97eb43fb6e9b388075bdc27f8a7077f4143
1 'use strict';
3 var env = require('gitter-web-env');
4 var nconf = env.config;
5 var avatars = require('gitter-web-avatars');
6 const truncateText = require('gitter-web-shared/truncate-text');
8 var facebookAppId = nconf.get('facebook:appId');
10 function getMetadata(options) {
11 var room = options && options.room;
13 var title = (room && room.uri) || 'Gitter';
14 var description = (room && room.topic) || 'Where developers come to talk.';
15 var imageUrl = (room && room.avatarUrl) || avatars.getDefault();
17 return {
18 'og:title': title,
19 'og:description': description,
20 'og:type': 'website',
21 'og:image': imageUrl,
22 'fb:app_id': facebookAppId,
23 'twitter:card': 'summary',
24 'twitter:site': '@gitchat',
25 'twitter:title': truncateText(title, 70),
26 'twitter:description': truncateText(description, 200),
27 'twitter:image': imageUrl
31 function getMetadataForChatPermalink(options) {
32 var room = options && options.room;
33 var chat = options && options.chat;
35 if (!chat || !chat.fromUser) return getMetadata(options);
37 var fromUser = chat.fromUser;
39 var title = (room && room.uri) || 'Gitter';
40 var description = '@' + fromUser.username + ': ' + chat.text;
41 var imageUrl = (room && room.avatarUrl) || avatars.getDefault();
43 return {
44 'og:title': title,
45 'og:description': description,
46 'og:type': 'website',
47 'og:image': imageUrl,
48 'fb:app_id': facebookAppId,
49 'twitter:card': 'summary',
50 'twitter:site': '@gitchat',
51 'twitter:title': truncateText(title, 70),
52 'twitter:description': truncateText(description, 200),
53 'twitter:image': imageUrl
57 module.exports = {
58 getMetadata: getMetadata,
59 getMetadataForChatPermalink: getMetadataForChatPermalink