Skip to content

Instantly share code, notes, and snippets.

View psychobunny's full-sized avatar
❤️
Making forums great again™

Andrew Rodrigues psychobunny

❤️
Making forums great again™
View GitHub Profile
@psychobunny
psychobunny / library.js
Last active April 24, 2016 10:30
NodeBB plugin - adding main post data to category view
var topics = module.parent.require('./topics'),
async = module.parent.require('async');
var plugin = {};
plugin.addPostData = function(data, uid, callback) {
async.map(data.topics, function(topic, next) {
topics.getMainPost(topic.tid, uid, function(err, mainPost) {
topic.mainPost = mainPost;
next(err, topic);
@psychobunny
psychobunny / mongo-ltrim.js
Created July 28, 2014 18:17
redis-like LTRIM for mongodb
module.listLTrim = function(key, start, stop, callback) {
module.getListRange(key, start, stop, function(err, value) {
if(err) {
if(typeof callback === 'function') {
return callback(err);
}
return;
}
db.collection('objects').update({_key: key }, {$set: value}, function(err, result) {
@psychobunny
psychobunny / comments.php
Created May 24, 2014 00:50
Wordpress integration with NodeBB
<?php
if ( post_password_required() )
return;
?>
<a id="nodebb/comments"></a>
<script type="text/javascript">
var nodeBBURL = 'http://forum.burnaftercompiling.com',
articleID = '<?php echo the_ID(); ?>';
{
"id": "nodebb-plugin-blog-comments",
"name": "NodeBB Blog Comments",
"description": "Lets NodeBB act as a comments engine/widget for your blog.",
"url": "https://github.com/psychobunny/nodebb-plugin-blog-comments",
"library": "./library.js",
"hooks": [
{
"hook": "filter:admin.header.build", "method": "addAdminLink"
},
{
"categories": [
{
"cid": "1",
"name": "Announcements",
"description": "Announcements regarding our community",
"icon": "fa-bullhorn",
"bgColor": "#0059B2",
"color": "#fff",
"slug": "1/announcements",
@psychobunny
psychobunny / plugin.js
Last active August 29, 2015 14:01
Plugin example: Custom API homepage for NodeBB, returns topics instead of posts per category
var async = require('async'),
categories = module.parent.require('./categories');
var Plugin = {};
function renderHomepage(req, res, next) {
var uid = req.user ? req.user.uid : 0;
/*
* For reference, this is taken straight from controllers/index.js (controllers.home)
@psychobunny
psychobunny / conversion.MD
Created May 3, 2014 21:00
Converting HBS to templates.js syntax

Use this in a text editor that supports regex search (like Sublime Text)

Find all

\{\{#if ([\S]*)\}\}([\s\S]*?)\{\{else\}\}([\s\S]*?)\{\{/if\}\}

Replace With

<!-- IF $1 -->$2<!-- ELSE -->$3<!-- ENDIF $1 -->
@psychobunny
psychobunny / index.html
Created April 1, 2014 21:28
[nodebb-script-category-dropdown] Category Dropdown Widget for NodeBB
<div id="category-selector" style="position: relative">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">Categories <span class="caret"></span></button>
<ul class="dropdown-menu" aria-labelledby="category-selector">
</ul>
</div>
<br />
<script>
// If you're using the custom homepage mod, switch the api call to /api/forum
$.get(RELATIVE_PATH + '/api/home', {}, function(data) {
@psychobunny
psychobunny / index.js
Created March 1, 2014 21:59
middleware/index.js
var templates = require('./../../public/src/templates'),
translator = require('./../../public/src/translator'),
middleware = require('./middleware'),
meta = require('./../meta'),
db = require('./../database'),
auth = require('./../routes/authentication'),
async = require('async'),
path = require('path'),
fs = require('fs'),
nconf = require('nconf'),
@psychobunny
psychobunny / webserver.js
Last active August 29, 2015 13:56
webserver.js middlewares
async.series({
currentThemeData: function(next) {
db.getObjectFields('config', ['theme:type', 'theme:id', 'theme:staticDir', 'theme:templates'], function(err, themeData) {
next(err, themeData);
});
},
themesData: function(next) {
meta.themes.get(function(err, themes) {
next(err, themes);
});