Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates to get it working #92

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

theaustinhowe
Copy link

@theaustinhowe theaustinhowe commented Jan 10, 2022

When attempting to utilize the plugin ran into a few issues.

  1. When initially loading a blog; because the topic didn't exist - the response would not allow for displaying the template to admin/publishers.
    This was resolved by moving the topic-related content into a different promise group; and allowing the request to go through even if null.

  2. Template shows "Powered By" and original thread link; which we didn't want/need.
    This was resolved with a new setting to turn off that functionality blog-comments:show-branding

  3. Template was having issues with properly rendering (I'm not sure how anyone is using this now).
    This was resolved by pulling the latest version of the template.js parser and replacing it in general.js (this may require updating in other public JS libraries)

  4. Ability to change login / registration URLs
    This was resolved with 2 new settings to update the URL blog-comments:login-url and blog-comments:register-url

  5. Ability to redirect instead of modal for authentication purposes.
    This was resolved with a new setting: blog-comments:auth-behavior

  6. Ability to automatically create a topic.
    This was resolved with 2 new settings one to turn on the functionality blog-comments:autocreate and one for default user blog-comments:autocreate-user-id

  7. Ability to turn off profile links
    This was resolved with a new setting: blog-comments:profile-links

@julianlam
Copy link
Collaborator

Hm... are you using the latest version of... templates.js? or https://github.com/benchpressjs/benchpressjs ?

We'd really appreciate using the latter, since it is a rewrite of the former for speed and API conformability. It should be drop-in replaceable.

@julianlam
Copy link
Collaborator

I really appreciate the PR, thank you for contributing back 😄

@theaustinhowe
Copy link
Author

We'd really appreciate using the latter, since it is a rewrite of the former for speed and API conformability. It should be drop-in replaceable.

I went to the last version of template.js (before it converted to benchpressjs). I was considering moving to benchpressjs but wasn't sure about size issues of the compiled file - since it didn't appear that I could easily take out the parsing. But if you like, I can look at a client distro version and replace template.js and see what happens?

LMK your thoughts - I figured the prior implementation was stripping template as much as possible to keep it light. (Even in this pull from template.js I removed references to things like fs)

@theaustinhowe
Copy link
Author

@julianlam what exactly is the expectations with benchpressjs?
Looking at the implementation I'm seeing a couple things:

  1. This plugin works by having a tmpl file (as a string) included in the response.
  2. The basic distribution of benchpressjs, requires a loader to be registered.
    3A) Precompiling the tpl file in the response, would mean having to re-compile the code - which would be bad.
    3B) Including benchpressjs + compile-render; seems much heavier as a library.

Maybe there is a more client friendly version I'm missing? If benchpressjs has a version where we can .render I'm all for it; but I'm not finding it...

@julianlam
Copy link
Collaborator

Wow, so much work on this plugin 😄

We can stick with templates.js if you're not comfortable figuring it out, it was just a passing thought. If it works fine right now, there's no need to change it.

@julianlam
Copy link
Collaborator

I've pinged @pitaj for his thoughts on the tjs ➡️ bch migration.

@@ -16,17 +16,47 @@ const groups = require.main.require('./src/groups');

const Comments = module.exports;

// CORS Middleware
const CORSMiddleware = function (req, res, next) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining what the purpose of this is.

res.header('Access-Control-Allow-Origin', url);
} else {
winston.warn(`[nodebb-plugin-blog-comments] Origin (${req.get('origin')}) does not match hostUrls: ${hostUrls.join(', ')}`);
let postData = []; let categoryData = null; let
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be on separate lines.

document.getElementById('nodebb-comments').insertAdjacentHTML('beforebegin', '<div id="nodebb"></div>');
nodebbDiv = document.getElementById('nodebb');
const nodebbDiv = document.getElementById('nodebb');

function newXHR() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably switch to fetch here, but for now you can remove the extremely old ActiveX stuff and use XMLHttpRequest directly.

}
}, 500);
}
const XHR = newXHR(); let pagination = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put these on separate lines. We should add https://github.com/nodebb/eslint-config-nodebb to align with other plugins.

@pitaj
Copy link

pitaj commented Jan 14, 2022

As for tjs to benchpress, it should be possible. An alternative to registering a loader is directly setting the template in Benchpress.cache.

Benchpress.cache['comments'] = Promise.resolve(templateFunction);
Benchpress.render('comments', data, block).then(...);

I think the best approach would be to bundle general.js, benchpressjs/build/benchpress.js, and the built template comments.js into one minified file in a build step.

@waschinski
Copy link

I just tried setting up this plugin when I came across this PR and I can't believe these changes have not been merged yet. All these changes are either required or simply a great addition like the autocreate option.

To quote @theaustinhowe:

I'm not sure how anyone is using this now

Btw the General - PHP example in the README seems outdated as well.
nbb.src = nodeBBURL + '/plugins/nodebb-plugin-blog-comments/lib/generalphp.js';
should probably be
nbb.src = nodeBBURL + '/assets/plugins/nodebb-plugin-blog-comments/lib/general.js';

@julianlam
Copy link
Collaborator

@waschinski I pinged @pitaj for his feedback and I think we were waiting on @theaustinhowe to provide changes before merging 😄

@waschinski
Copy link

Thanks for the update, meanwhile I've been deciding not to use nodebb due to this and some other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants