Updated code for Twitter embed && Twitter hashtag search plugin
-
nodebb-plugin-twitter/library.js
(function(module) { "use strict"; var Twitter = {}, embed = '<blockquote class="content twitter-tweet" lang="en"><a href="https://twitter.com/$1/status/$2"></a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>'; Twitter.parse = function(data, callback) { var regularUrl = /<a href="(?:https?:\/\/)?(?:twitter\.com)\/([^\/"\s]*)\/statuse?s?\/([^\/"\s]*)(\/photo\/1|)">.+?<\/a>/g var postContent = data && data.postData && data.postData.content; if (postContent && postContent.match(regularUrl)) { data.postData.content = postContent.replace(regularUrl, embed); } callback(null, data); }; Twitter.init = { global: { addNavigation: function(custom_header, callback) { custom_header.navigation.push({ class: 'hidden', route: "", text: '<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>' }); callback(null, custom_header); } } }, module.exports = Twitter; }(module));
nodebb-plugin-twitter-hastag/index.js
'use strict'; (function(module) { var regex = /(?:\s|^)#(\w*[A-Za-z_]+\w*)\s?(?!\w\d\s)/gi; module.parse = function(data, callback) { if (!data || !data.postData || !data.postData.content) { return callback(null, data); } var matches = data.postData.content.match(regex); if(!matches || !matches.length) { return callback(null, data); } for(var i=0; i<matches.length; ++i) { var match = matches[i].replace('</p>', '').trim(); data.postData.content = data.postData.content.replace(match, '<a href="https://twitter.com/search?q=%23'+ match.slice(1) +'" target="_blank">' + match + '</a>'); } callback(null, data); }; }(module.exports));
Copyright © 2024 NodeBB | Contributors