Code Monkey home page Code Monkey logo

nodebb-plugin-blog-comments2's Introduction

This plugin is a folk from NodeBB Blog Comments, I just added some more features and fixed some bugs to it.

  • Support multiple blogs, use articleID and blogger to distinguish posts from different blogs, so this is kinda break change to the original nodebb-plugin-blog-comments.
  • Simple script for ghost, hugo, pelican etc, and a general script for any other blogs, just add a <script> node at any place of the page, will support more blog platforms later.
  • Use siteTitle instead of NodeBB in the comments.tpl.
  • Support social sites sharing plugin and upvote and bookmark actions.
  • Two css styles for comments.
  • Fixed some bugs, like escaped title and content problems, profile image display, etc.

The multiple blogs feature is great, you can see at here: https://v2mm.tech/category/46/blog There are already some blogs conntected with V2MM.

NodeBB Blog Comments

The original NodeBB Blog Comments lets NodeBB act as a comments engine/widget for your blog. It supports both Ghost and WordPress.

The comments are exposed to any plugin you have built into the core, so it is completely possible to have emoticons, embedded video, and/or whatever else you want in the comments section of your blog.

Articles are published to a forum category of your choice, and will gain a tag that links it back to the original article.

Screenshots

  • Style 1 style1

  • Style 2 style2

Installation

First install the plugin:

npm install nodebb-plugin-blog-comments2

Activate the plugin in the ACP and reboot NodeBB. Head over to the Blog Comments section in the ACP and select the Category ID you'd like to publish your blog content to (default is Category 1). Make sure you put the correct URL to your blog.

General Use

Put this script to anywhere in your blog's article page, either in head or body, fill the variables, see explanations below.

<script type="text/javascript">
$(document).ready(function() {
   var nbb = window.nbb = {};
   nbb.url = '//yournodebb.com'; // your forum url.
   nbb.cid = 79;   // the category where to publish.
   nbb.blogger = 'yourname';   // the name to distingush with different blog, omit it to fallback to 'default'.
   nbb.commentsCSS = nbb.url + '/plugins/nodebb-plugin-blog-comments2/css/comments2.css'; // which style you prefer, omit it to fallback to the default comments.css
   nbb.articleID = <Function to get the unique article id>   // To get the unique article id, see explations below.
   nbb.articleTitle = document.title;                       // To get the article title, document.title is the default.
   nbb.commentElement = document.getElementById('nodebb-comments');  // Where you put the comments widget, "nodebb-comments" element is the default.

   nbb.articleContent = <Function to get the excerpt of the article> // Write a function to get the post content.

   nbb.script = document.createElement('script');
   nbb.script.type = 'text/javascript';
   nbb.script.async = true;
   nbb.script.src = nbb.url + '/plugins/nodebb-plugin-blog-comments2/lib/general.js';  // load general.js async.
   (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(nbb.script);
});
</script>

If you wish, you can create <a id="nodebb-comments"></a> to where you want to place the actual comments widget.

Also, there are some special scripts for some common blog platform. But in various blog themes, these scripts cannot guarantee to be true. For example, simple-wordpress.js can't be used on any wordpress websites. If you encounter any error, use general.js instead or put an issue to me.

Ghost Installation

Paste this any where in yourtheme/post.hbs, somewhere between {{#post}} and {{/post}}. All you have to edit is line 3 (nbb.url) - put the URL to your NodeBB forum's home page here.

<a id="nodebb-comments"></a>
<script type="text/javascript">
var nbb = {};
nbb.url = '//your.nodebb.com'; // EDIT THIS
nbb.cid = 1;	// OPTIONAL. Forces a Category ID in NodeBB.
nbb.blogger = 'blogger_name';	//  Omit it to fallback to 'default'.

(function() {
nbb.articleID = '{{../post.id}}';
nbb.tags = [{{#../post.tags}}"{{name}}",{{/../post.tags}}];
nbb.script = document.createElement('script'); nbb.script.type = 'text/javascript'; nbb.script.async = true;
nbb.script.src = nbb.url + '/plugins/nodebb-plugin-blog-comments2/lib/ghost.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(nbb.script);
})();
</script>
<span id="nbb-title" style="display:none">{{../post.title}}</span>
<span id="nbb-markdown" style="display:none">{{../post.markdown}}</span>
<noscript>Please enable JavaScript to view comments</noscript>

If you wish, you can move <a id="nodebb-comments"></a> to where you want to place the actual comments widget.

See demo at hgkat's blog, her blog is using this script to connect with V2MM.

Simple Ghost Installation

Since some blogs might installed with docker, couldn't change the theme file, I create this simple script which can be added at any place of the html.

Just add this any where on your blog's page:

<script id='nodebb-comments-script' ourl="//your.nodebb.com" ocid="1" blogger='name' src="//your.nodebb.com/plugins/nodebb-plugin-blog-comments2/lib/simple-ghost.js"></script>

Note: ocid is the category id in your NodeBB, blogger is set for distinguish posts from different blogs.

See demo at Wave's blog, his blog is using this script to connect with V2MM.

Simple Hugo Installation

<script id='nodebb-comments-script' ourl="//your.nodebb.com" ocid="1" blogger='name' src="//your.nodebb.com/plugins/nodebb-plugin-blog-comments2/lib/simple-hugo.js"></script>

See demo at Leyafo's blog, his blog is using this script to connect with V2MM.

Simple Pelican Installation

<script id='nodebb-comments-script' ourl="//your.nodebb.com" ocid="1" blogger='name' src="//your.nodebb.com/plugins/nodebb-plugin-blog-comments2/lib/simple-pelican.js"></script>

See demo at Cycleuser's blog, his blog is using this script to connect with V2MM.

Wordpress plugin and any other plugins in PHP, I haven't test them yet, as I don't have those blogs. If your blog is wordpress, and would like to connect with V2MM, I would be glad to set up this script for you.

Wordpress Installation

First, install the Wordpress JSON API plugin.

Replace the contents of /wp-content/themes/YOUR_THEME/comments.php with the following (back-up the old comments.php, just in case):

<?php
if ( post_password_required() )
	return;
?>

<a id="nodebb-comments"></a>
<script type="text/javascript">
var nodeBBURL = '//your.nodebb.com',
	wordpressURL = '<?php echo get_site_url(); ?>',
	articleID = '<?php echo the_ID(); ?>',
	blogger = 'name', //OPTIONAL. Assign an blogger name to disdinguish different blogger. Omit it to fallback to 'default'
	articleType = '<?php echo get_post_type() ?>',
	categoryID = -1; // If -1, will use category in NodeBB ACP.  Put in a category number to force that category.

(function() {
var nbb = document.createElement('script'); nbb.type = 'text/javascript'; nbb.async = true;
nbb.src = nodeBBURL + '/plugins/nodebb-plugin-blog-comments2/lib/wordpress.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(nbb);
})();
</script>
<noscript>Please enable JavaScript to view comments</noscript>

Comments Counter

You may optionally put a "# of comments" counter anywhere on the page with the following code:

<span id="nodebb-comments-count"></span> Comments

A mechanism to query the number of comments on another separate page will be available in a future release.

Author and Category information

To use NodeBB's category and author information (instead of using Ghost's user/tag system), there are two elements that this plugin searches for:

Published by <span id="nodebb-comments-author"></span> in <span id="nodebb-comments-category"></span>

Publishing

Head over to the article that you'd like to publish. The code will detect if you're both an administrator of your blog and NodeBB (so ensure that you're logged into both) and will display a publish button if so.

You may also create a publishers group in NodeBB to allow a group of regular users to have publish rights.

nodebb-plugin-blog-comments2's People

Contributors

fma965 avatar frandiox avatar fuzzmz avatar jshaffstall avatar julianlam avatar philskents avatar psychobunny avatar revir avatar sohrabafard avatar theunknownartisthour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nodebb-plugin-blog-comments2's Issues

Publishing to NodeBB from Wordpress only works for default post types

Line 157 of wordpress.js uses the Wordpress API to get the contents of a post:

adminXHR.open('GET', wordpressURL + '?json=get_post&post_id=' + articleID);

That only works for posts of the default 'post' type. Posts of different types return that the post could not be found.

It'd be nice if publishing could work with any post type, not just the default.

Compatibility with latest wordpress

Hi,
I'm trying to implement this to our wordpress based website and getting "commenting disabled" error. I did not install wordpress JSON API plugin, as it is not being maintained and may not be compatible with latest wordpress.
Besides, wordprss now has their own REST API. Can you update the plugin to reflect present changes?
Thanks in advance.

Ghost 1.3.0 + NodeBB 1.5.3 not working

Hi! Trying to use this plugin with the new Ghost and a new NodeBB versions. Doesn't seem to work for me.

I get the "Publish this article" button for the blog post, pressing it does create the topic in NodeBB but the "Publish this article" button remains - no thread is being displayed on the Ghost side. No errors nor warnings in the JavaScript console.

Existence of script kills social icons on Ghost

I originally thought this might be a conflict between my theme (curious) and the plug-in but the example linked in the readme is also affected.

The existence of "var nbb = {}; " prevents the Twitter and Facebook icons, rendered through fontawesome, from showing. Interestingly, the website link still works

These are the social links that are added through admin interface but my theme also uses them for sharing buttons elsewhere and they aren't displayed either.

I'm not a developer so please forgive me if this isn't due to your plug-in.

Module error with NodeBB 1.12.0

I got the following error in NodeBB log after activating the plugin and restarting the server. The plugin also does not show up in the ACP menu.

2019-03-09T14:13:08.152Z [6942/25931] - warn: [deprecated] requiring core modules with `module.parent.require('./database')` is deprecated. Please use `require.main.require("./src/<module_name>")` instead.
    at Object.<anonymous> (/home/nodebb/node_modules/nodebb-plugin-audio-embed/library.js:11:24)
2019-03-09T14:13:08.186Z [6942/25931] - warn: [deprecated] requiring core modules with `module.parent.require('../src/database.js')` is deprecated. Please use `require.main.require("./src/<module_name>")` instead.
    at /home/nodebb/node_modules/nodebb-plugin-blog-comments2/library.js:6:25
2019-03-09T14:13:08.187Z [6942/25931] - warn: [deprecated] requiring core modules with `module.parent.require('../../src/database.js')` is deprecated. Please use `require.main.require("./src/<module_name>")` instead.
    at /home/nodebb/node_modules/nodebb-plugin-blog-comments2/library.js:6:25
2019-03-09T14:13:08.187Z [6942/25931] - error: Error: Cannot find module '../../src/database.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at Module.module.require (/home/nodebb/src/plugins/index.js:55:26)
    at /home/nodebb/node_modules/nodebb-plugin-blog-comments2/library.js:6:25
    at Object.<anonymous> (/home/nodebb/node_modules/nodebb-plugin-blog-comments2/library.js:328:2)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
2019-03-09T14:13:08.189Z [6942/25931] - warn: [plugins] Unable to parse library for: nodebb-plugin-blog-comments2

Perhaps it can be fixed with psychobunny@41775e7 ? Please let me know if you want a pull request.

rror: ENOENT: no such file or directory

2018-03-02T23:44:23.085Z [3194] - �[31merror�[39m: /assets/templates/comments/admin.js
Error: ENOENT: no such file or directory, open '/var/www/NodeBB/build/public/templates/comments/admin.tpl'
at Error (native)

2018-03-02T23:44:13.044Z [3194] - �[31merror�[39m: /admin/blog-comments
Error: Failed to lookup view "comments/admin" in views directory "/var/www/NodeBB/build/public/templates"
at EventEmitter.render (/var/www/NodeBB/node_modules/express/lib/application.js:580:17)
at ServerResponse.render (/var/www/NodeBB/node_modules/express/lib/response.js:1008:7)
at content (/var/www/NodeBB/src/middleware/render.js:83:15)
at /var/www/NodeBB/node_modules/async/dist/async.js:3866:24
at replenish (/var/www/NodeBB/node_modules/async/dist/async.js:998:17)
at /var/www/NodeBB/node_modules/async/dist/async.js:1002:9
at eachOfLimit (/var/www/NodeBB/node_modules/async/dist/async.js:1027:24)
at /var/www/NodeBB/node_modules/async/dist/async.js:1032:16
at eachOf (/var/www/NodeBB/node_modules/async/dist/async.js:1103:5)
at _parallel (/var/www/NodeBB/node_modules/async/dist/async.js:3865:5)
at Object.parallelLimit [as parallel] (/var/www/NodeBB/node_modules/async/dist/async.js:3948:5)
at async.waterfall.str (/var/www/NodeBB/src/middleware/render.js:78:12)
at nextTask (/var/www/NodeBB/node_modules/async/dist/async.js:5310:14)
at next (/var/www/NodeBB/node_modules/async/dist/async.js:5317:9)
at /var/www/NodeBB/node_modules/async/dist/async.js:958:16
at /var/www/NodeBB/node_modules/async/dist/async.js:473:16

I used NodeBB v1.7.5.

XHR Send error 502

    function xget (xhr, path) {
        xhr.open('GET', path, true);
        xhr.withCredentials = true;
        xhr.send(); //right here not sending
        return xhr;
    }

Common.js line 26, Gateway 502 error Nodebb 1.5.3 got any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.