Integration with Ghost

AI-generated summary

Integration with Ghost

The user, Zyniker, is attempting to integrate their Discourse-based forum with their Ghost-based test blog. They want to enable Discourse-based comments on all posts on their blog, with posts appearing in categories on Discourse based on the blog post’s tags.

Zyniker has encountered issues with the integration and has several questions, including:

  • How to handle posts with multiple categories that allow comments
  • Whether comments will show on the main/home page or only on specific endpoints
  • If a generic whitelist of /.* will enable comments on all posts

The user is using the following code to enable Discourse-based comments but is experiencing errors.

After seeking help on the Ghost forum, Zyniker managed to resolve the issue, discovering that the code section was commented out with {{!-- and --}}, which was not highlighted by their text editor.

I have a copy of this topic open over on the (naturally) powered-by-Discourse Ghost forum, but, in thinking about the issue, I realized I don’t actually know if the problem lies in my Ghost configuration or in my Discourse configuration. Consequently, I am opening this topic here to see if anyone is able to provide any insight.


I’ve been using WordPress for a long time and I am now considering moving some of those sites over to Ghost (yes, I’m sure this is a common story). As always, there’s a bit of a learning curve when switching from one software system to another. At present, I am attempting to integrate my Discourse-based forum with my Ghost-based test blog.

I admittedly do not (yet) have a firm grasp on all of the concepts in Ghost, which may explain (at least part of) why I am having trouble getting this embed to work. I would like to have Discourse-based comments available on all posts on my blog, but I would like to have posts on the blog appear in categories on Discourse based on the blog post’s tags (e.g., a post tagged “Philosophy” should appear in the “Philosophy” category on Discourse).

If I am not mistaken, this means that I will need a different embed/host configured for each category that will require comments. However, this raises additional questions. Here are my present questions/issues:

  1. How should posts with multiple categories, each of which allows comments, be handled? How would such a post be handled if multiple embeds/hosts apply to it?
  2. Will comments show on the main/home page or only when displayed via an endpoint (i.e., a whitelisted path in Discourse) for which comments are enabled (e.g., /philosophy/.* or /politics/.*)?
  3. Does a generic whitelist of /.* work? Would this effectively enable comment in all posts?
  4. I am currently using the following code on my blog in an attempt to enable Discourse-based comments:
<div id='discourse-comments'></div>

<script type="text/javascript">
	DiscourseEmbed = { discourseUrl: 'https://forum.coreyjmahler.com/',
		discourseEmbedUrl: '{{url absolute="true"}}' };

	(function() {
		var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
		d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
		(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
	})();
</script>

However, as can be seen from this test post, the code is clearly not working. Why?

Additional Information

  • I have already cleared all caches, and, in fact, had Cloudflare paused while I was working on this.
  • The following resource throws a 404 error in Safari:
    https://blog.coreyjmahler.com/assets/main/css/main.css.map/
    but there are no other errors reported.
  • The following error appears a number of times in the Ghost logs:
{"name":"Log","hostname":"blog-coreyjmahler-com","pid":2821,"level":50,"req":{"meta":{"requestId":"4cfbf860-0d7f-11e9-b0b9-a55cf68e3775","userId":null},"url":"/users/me/?include=roles","method":"GET","originalUrl":"/ghost/api/v2/admin/users/me/?include=roles","params":{},"headers":{"x-forwarded-for":"A.B.C.D","x-forwarded-proto":"https","x-real-ip":"A.B.C.D","host":"blog.coreyjmahler.com","connection":"close","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:64.0) Gecko/20100101 Firefox/64.0","accept":"application/json, text/javascript, */*; q=0.01","accept-language":"en-US,en;q=0.5","accept-encoding":"gzip, deflate, br","referer":"https://blog.coreyjmahler.com/ghost/","content-type":"application/json; charset=UTF-8","x-ghost-version":"2.9","app-pragma":"no-cache","x-requested-with":"XMLHttpRequest"},"body":{},"query":{"include":"roles"}},"res":{"_headers":{"x-powered-by":"Express","cache-control":"no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0","content-type":"application/json; charset=utf-8","content-length":"73","etag":"W/\"49-Htz2g1hjAoUvJ874WUMiMG0d3Z0\"","vary":"Accept-Encoding"},"statusCode":401,"responseTime":"16ms"},"err":{"id":"4cfdcd20-0d7f-11e9-b0b9-a55cf68e3775","domain":"https://blog.coreyjmahler.com","code":null,"name":"UnauthorizedError","statusCode":401,"level":"normal","message":"Access denied.","context":"empty","help":"empty","stack":"UnauthorizedError: Access denied.\n    at new UnauthorizedError (/var/www/ghost/versions/2.9.1/node_modules/ghost-ignition/lib/errors/index.js:101:23)\n    at ensureUser (/var/www/ghost/versions/2.9.1/core/server/services/auth/session/middleware.js:98:10)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/route.js:137:13)\n    at getUser (/var/www/ghost/versions/2.9.1/core/server/services/auth/session/middleware.js:82:16)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/route.js:137:13)\n    at cookieCsrfProtection (/var/www/ghost/versions/2.9.1/core/server/services/auth/session/middleware.js:107:16)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/route.js:137:13)\n    at session (/var/www/ghost/versions/2.9.1/node_modules/express-session/index.js:454:7)\n    at getSession (/var/www/ghost/versions/2.9.1/core/server/services/auth/session/middleware.js:48:12)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/route.js:137:13)\n    at Route.dispatch (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/route.js:112:3)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at /var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:281:22\n    at param (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:354:14)\n    at param (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:365:14)\n    at Function.process_params (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:410:3)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:275:10)\n    at Function.handle (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:174:3)\n    at router (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:47:12)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:317:13)\n    at /var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:335:12)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:275:10)\n    at cacheControlHeaders (/var/www/ghost/versions/2.9.1/core/server/web/shared/middlewares/cache-control.js:32:9)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:317:13)\n    at /var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:335:12)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:275:10)\n    at checkVersionMatch (/var/www/ghost/versions/2.9.1/core/server/web/shared/middlewares/api/version-match.js:23:5)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:317:13)\n    at /var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:335:12)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:275:10)\n    at maintenance (/var/www/ghost/versions/2.9.1/core/server/web/shared/middlewares/maintenance.js:18:5)\n    at Layer.handle [as handle_request] (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:317:13)\n    at /var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:284:7\n    at Function.process_params (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:335:12)\n    at next (/var/www/ghost/versions/2.9.1/node_modules/express/lib/router/index.js:275:10)","errorDetails":"empty"},"msg":"Access denied.","time":"2019-01-01T04:40:01.535Z","v":0}

(IP addresses masked to A.B.C.D.)


  • What’s your URL? https://blog.coreyjmahler.com/
  • What version of Ghost are you using? Current
  • What configuration? Ubuntu 18.04 and nginx
  • What browser? Firefox and Safari
  • What errors or information do you see in the console? None in the Discourse logs; one in Safari, supra; and one in the Ghost logs, supra.
  • What steps could someone else take to reproduce the issue you’re having? See above.

Managed to get this solved over on the Ghost forum. The issue was that the code section was commented out with {{!-- and --}} (which BBEdit did not highlight as it was treating the file as HTML).