I’m afraid didn’t have much luck with your code
[BTW you’ve missed the closing quote off "Article Title
]
I kept getting an error about the markDownContent
line:
TypeError: ({title_plain:"Article Title", url:"https://www.example.com/test.html", markDownContent:"<p>Excerpt</p>"}) is not a function
.
However by hitting the original Ghost code repeatedly with blunt ignorance, until it stopped screaming, I managed to get that working in a very rudimentary fashion. Here’s what I’ve come up with so far. As you can see, I’ve had to hard-wire a few things in, obliterate a few anonymous function wrappers [?terminology] and also redeclare some vars, as the Ghost code seems to name them differently to what the general.js
plugin script is expecting:
{{"<!-- begin nodeBB comments partial //-->" | safeHTML}}
HERE BE COMMENTS ===>
<a id="nodebb-comments"></a>
<script type="text/javascript">
var nbb = {}; //init empty object
console.log("DEBUG: nbb ===> "+nbb);
nbb.url = 'http://localhost:4567'; //nodebb install
console.log("DEBUG: nbb.url ===> "+nbb.url);
nbb.cid = 1; // OPTIONAL. Forces a Category ID in NodeBB.
// Omit it to fallback to specified IDs in the admin panel.
console.log("DEBUG: nbb.cid ===> "+nbb.cid);
nbb.articleID = '{{title .Title}}'; //does Hugo do article IDs? Use title as [hopefully] unique
console.log("DEBUG: nbb.articleID ===> "+nbb.articleID);
nbb.title = '{{title .Title }}';
console.log("DEBUG: nbb.title ===> "+nbb.title);
nbb.tags = []; //array to hold keywords
{{if isset .Params "tags" }}
{{ range .Params.tags }}
nbb.tags.push("{{ lower . }}");
{{ end }}
{{ end }}
console.log("DEBUG: nbb.tags ===> "+nbb.tags);
var articleData = JSON.stringify(nbb); //convert to JSON [even though it doesn't seem to get used in this mess!
//renamed from nbb to nbbjs, as original object is called 'nbb'
var nbbjs = document.createElement('script'); nbbjs.type = 'text/javascript'; nbbjs.async = true;
nbbjs.src = nbb.url + '/plugins/nodebb-plugin-blog-comments/lib/general.js';
console.log("DEBUG: nbbjs.src ===> "+nbbjs.src);
//have to define these again, as they're differently named in general.js
nodeBBURL = nbb.url;
articleID = nbb.articleID;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(nbbjs);
</script>
<===== OR NOT, AS THE CASE MAY BE
<noscript>Please enable JavaScript to view comments</noscript>
{{"<!-- end nodeBB comments partial //-->" | safeHTML}}
That mess of spaghetti gave me the following:
…and the test comment did get placed in the nodeBB forum. Although the thread title and summary post came through as “undefined”. Obviously more var names out of sync between the sample code and the general.js
file:
[Oh yes and the CSS got lost too. Hence the ugly black text on black at the top of the posts]
One other problem I ran into was the dreaded CORS error, as Hugo’s server and nodeBB’s are running on different ports:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:4567/comments/get/BBC%20Radio%20On%20Linux/0. (Reason: CORS header 'Access-Control-Allow-Origin' does not match 'undefined').
I got around that by installing the CORS Everywhere plugin in Firefox.
Well, that’s the state of play so far, from this end. The quest continues!