|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var truncate = require('./truncate'); |
|
|
var striptags = require('striptags'); |
|
|
var toPlainText = require('./clients/draft-js/utils/plaintext').toPlainText; |
|
|
|
|
|
var DEFAULT_META = { |
|
|
title: 'Spectrum', |
|
|
description: 'Where communities live.', |
|
|
}; |
|
|
|
|
|
var HIDE_FROM_CRAWLERS = '<meta name="robots" content="noindex, nofollow">'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setDefault(input ) { |
|
|
var title = input.title || DEFAULT_META.title; |
|
|
var description = input.description || DEFAULT_META.description; |
|
|
|
|
|
|
|
|
|
|
|
if (input.title && !input.description) { |
|
|
description = 'on Spectrum, ' + DEFAULT_META.description.toLowerCase(); |
|
|
} |
|
|
return { |
|
|
title: title, |
|
|
description: cleanDescription(description), |
|
|
extra: input.extra || '', |
|
|
}; |
|
|
} |
|
|
|
|
|
function cleanDescription(input ) { |
|
|
return truncate(striptags(input), 160); |
|
|
} |
|
|
|
|
|
function generateMetaInfo(input ) { |
|
|
var exists = input || {}; |
|
|
var type = exists.type; |
|
|
var data = exists.data; |
|
|
switch (type) { |
|
|
case 'explore': { |
|
|
return { |
|
|
title: 'Explore', |
|
|
description: 'Explore some of the communities on Spectrum', |
|
|
}; |
|
|
} |
|
|
case 'thread': { |
|
|
if (data.privateChannel) |
|
|
return setDefault({ |
|
|
extra: HIDE_FROM_CRAWLERS, |
|
|
}); |
|
|
|
|
|
var body = |
|
|
data && |
|
|
data.body && |
|
|
(data.type === 'DRAFTJS' |
|
|
? toPlainText(JSON.parse(data.body)) |
|
|
: data.body); |
|
|
return setDefault({ |
|
|
title: data && data.title + ' 路 ' + data.communityName, |
|
|
description: body, |
|
|
}); |
|
|
} |
|
|
case 'user': { |
|
|
return setDefault({ |
|
|
title: data && data.name + ' 路 @' + data.username, |
|
|
description: data && data.description, |
|
|
}); |
|
|
} |
|
|
case 'channel': { |
|
|
if (data.private) |
|
|
return setDefault({ |
|
|
extra: HIDE_FROM_CRAWLERS, |
|
|
}); |
|
|
return setDefault({ |
|
|
title: data && data.communityName + ' 路 ' + data.name, |
|
|
description: data && data.description, |
|
|
}); |
|
|
} |
|
|
case 'community': { |
|
|
return setDefault({ |
|
|
title: data && data.name, |
|
|
description: data && data.description, |
|
|
}); |
|
|
} |
|
|
case 'directMessage': { |
|
|
return setDefault({ |
|
|
title: data && data.title, |
|
|
description: data && data.description, |
|
|
}); |
|
|
} |
|
|
case 'notifications': { |
|
|
return setDefault({ |
|
|
title: 'Notifications', |
|
|
description: 'Notifications on Spectrum', |
|
|
}); |
|
|
} |
|
|
default: { |
|
|
return DEFAULT_META; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
module.exports = generateMetaInfo; |
|
|
|