Integrating Discourse: Draft Post Issues

Hi, I’m integrating Discourse with my Ghost blog so that new posts appear on my forum as topics: https://ghost.org/integrations/discourse/. The topic is created on Discourse after the first page view.

I’m running into a problem though where a new topic is created when a post is in draft mode. Is there any way I can display the JS embed code only if a post is published? Is there some kind of ‘draft’ tag I can use in an #has statement?

Cheers.

I had this same problem occur upon updating to Ghost 2.0. Somebody who knows more about this stuff fixed it for me. If you’re using the same Discourse embed code as I am, and looking at my theme’s GitHub repo, you’ll want to replace this portion of the code:

          DiscourseEmbed = { discourseUrl: 'https://discourse.yourdomain.com/',
                             discourseEmbedUrl: '{{@blog.url}}{{url}}' };
          (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);
          })();

with this:

            if (window.location.pathname.indexOf('/p/') < 0) {
                DiscourseEmbed = { discourseUrl: 'https://discourse.yourdomain.com/',
                                  discourseEmbedUrl: '{{@blog.url}}{{url}}' };
                (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);
                })();
            }

I hope that fixes things for you. :slightly_smiling_face:

3 Likes

Ahhh that’s a great solution. Thank you :slight_smile: