Hi, I’m integrating Discourse with my Ghost blog so that new posts appear on my forum as topics: Official Ghost + Discourse Integration. 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.
1 Like
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.
5 Likes
Ahhh that’s a great solution. Thank you
Awesome @Stromfeldt! I was initially trying to find a Ghost post status filter to do this via handlebars, but this works a treat.
@DavidDarnes, or @Kym would you consider updating the Discourse + Ghost Integration documentation to include the conditional
if (window.location.pathname.indexOf('/p/') < 0) {
//discourse embed logic
}
to protect future users from auto generating discourse threads on draft views of an article.
Looks like it’s been a problem for at least 7 users (including me) and the code above fixes it in a jiff
PS Ghost IS AMAZING!!
2 Likes
Hey @zeluspudding, thanks for this suggestion. We’ve updated our integration page for Discourse if you want to check it out:
1 Like