Embedding Discourse Comments via Javascript


(Dean Peterson) #124

Is this still the only solution for the sameorigin issue: Same Origin Hack?

EDIT I am past the same origin part but now I am getting a 403 error. I am on the latest version of discourse. When I reload the page after loading the first time, it works but I can’t have new pages getting a 403 on topic creation. Do I need to set the DISCOURSE_ENABLE_CORS to true in my app.yml file?

(Dean Peterson) #125

I use angularjs. My page title doesn’t change when I move to a new route. I can use javascript in the controller to create a new discours embed url for the new route and topic but it will always have the same title since angularjs only injects new content inside the view portion past the title tag that always stays the same.

(Abbas Jaffar Ali) #126

Does discourse copy the contents of the blog post into its own topic? If yes, then couldn’t you be penalized for duplicate content in SEO?

(Robin Ward) #127

The title is retrieved when Discourse makes a call back to your application asynchronously. Does your application not respond to URLs with the correct page title even on first request?

I’ve not heard of being responsible for any penalization of SEO, but in theory it’s possible. I’d be curious to hear if anyone had that problem.

Open shortcuts from keyboard in Firefox 52.0.2
(Dean Peterson) #128

Since it is a single page app, the title always stays the same. I think I can work around it with an angularjs hack to modify the page title on route change though. My biggest problem is a 403 error right now.

(Mittineague) #130

There is no such thing as a "duplicate content penalty"
What happens, is one is “chosen” as the better and other(s) are excluded.
This gives some the idea that the other(s) are being penalized.

If there was a true penalty all would be excluded.

(Joseph Snell) #131



I’m running into a 403 error and have read everything i can find on solving the error and nothing seems to work.

I have triple checked my embedded hosts and everything should be working correctly.

I am trying to embed comments on a specific page that i am hosting in an s3 bucket. I have my subdomain pointed to the bucket with a cname and it resolves correctly. But on the page where the comments should be I get a flash of “loading comments” and the logo, and then it throws a 403.

I am running discourse through docker on a digital ocean droplet.

My Admin Panel (ignore the ip):

Here is my code:

Error messages:

Any suggestions?

(Robin Ward) #132

It looks set up correctly, although it’s a bit odd that the URL has a slash after read.html. You are accessing it at the same URL? http://staging.josephsnell.co/read.html – note the host has to be exactly the same.

(Robin Ward) #133

3 posts were merged into an existing topic: Discourse WordPress plugin version 0.6.6

UL class stripped in topic posts
(Joseph Snell) #135

So i switched some stuff up and tried to do it from scratch. I think that that was part of the issue with the trailing /.

But it still wasn’t working so I changed it to just point to a specific post id. And magically it worked.

So the issue is within the post url, so i will just try and work through that and see what the deal is. Either way it is working with specific topic ids.

(Nick Putman) #136

Could someone help me understand the pros/cons of this javascript method of embedding comments, versus using the wp-discourse method of syncing topic replies so that they show underneath the corresponding WP blog entry.

Also, using this javascript method, am I supposed to paste the embed code below the text for the blog entry? I have tried doing so, and WP is adding p tags, so I am getting errors on the page.

(Mittineague) #137

Sounds like wpautop at work

Deleting topics while maintaining links to WP blog article
(Nick Putman) #138

Thanks. I have this working now. I can see that, using this embed method I get a comment count and also detail of time since the posts were made. Are there any other advantages to using this method over the wp-discourse plugin?

(Nick Putman) #139

Also, I am wondering if it is somehow possible to get WP to recognise the number of replies on the associated discourse topic and set the number of comments for each entry on the main blog page on my site (as WP does by default with its own comments system)

(Nick Putman) #140

Further wonderings:

  • Can the ‘Start Discussion’ link point to the bottom of the article, so that the user can clearly see the reply button on loading the topic page?
  • And, optionally can the reply box automatically open?
  • Similarly can the reply box automatically open on page load when clicking ‘Continue Discussion’

These changes would I think make the integration with WP blog entries much smoother.

(James Morgan) #141

Hey guys,

Thanks for this awesome feature! :grinning:

I’m really struggling to get an embedded feed to create a new topic.

It works when the user is logged in to discourse, but I want it so that the user doesn’t have to be logged in to discourse to view the feed (with the button “Start the discussion”) …is that possible?

If not, then I suppose I’ll have to do a workaround to force them to go to discourse first, to log in?

I have a CMS (https://intranet.industry.nsw.gov.au/)
And a discourse instance (https://comments.industry.nsw.gov.au/)

I have a test page (https://intranet.industry.nsw.gov.au/_helper/testing-comments/discourse-embed-2)
…with the embedded code…

<div id='discourse-comments'></div>
<script type="text/javascript">
  DiscourseEmbed = { discourseUrl: 'https://comments.industry.nsw.gov.au/',
                     discourseEmbedUrl: 'https://intranet.industry.nsw.gov.au/_helper/testing-comments/discourse-embed-2' };

  (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);

But when I navigate to this page, I just get the “Loading Discussion…” text hanging.

And I eventually get those JS errors…

VM665 comments?embed_url=https%3A%2F%2Fintranet.industry.nsw.gov.au%2F_helper%2Ftesting-comments%2F…:75GET https://comments.industry.nsw.gov.au/embed/comments?embed_url=https%3A%2F%2…ranet.industry.nsw.gov.au%2F_helper%2Ftesting-comments%2Fdiscourse-embed-2 403 ()
(anonymous function) @ VM665 comments?embed_url=https%3A%2F%2Fintranet.industry.nsw.gov.au%2F_helper%2Ftesting-comments%2F…:75

Uncaught TypeError: Cannot read property ‘forEach’ of undefined
(anonymous function) @ comments?embed_url=https%3A%2F%2Fintranet.industry.nsw.gov.au%2F_helper%2Ftesting-comments%2Fdiscou…:205

Uncaught TypeError: Cannot read property ‘highlighted_languages’ of undefined

Thanks for any help in advance! :smiley:

(Robin Ward) #142

It should work out of the box this way. For example on my blog https://eviltrout.com you don’t need to be logged in to view the comments or click “Continue Discussion”.

Since it’s not working: do you have login_required or other privacy settings enabled on your forum? It needs the content to be publicly accessible.

(James Morgan) #143

Thanks for a quick reply! :smiley:

Are there any other settings in Discourse that might cause these 3 errors?

Thanks so much for your help!

(Robin Ward) #144

Unfortunately I can’t think of anything else to try. Are there any suspicious errors in /logs on your server after you request the content anonymously?

(Ringgit Malaysia) #145

I find it funny that after I embed Discourse into Blogger successfully, I see topics being created from blog-post I have created from years ago. There is no pattern, it can come from post created in 2013 or 2014 or current. It’s as though I have phantom readers who read my post and click Comment to say something - that or it’s some spam bots. Interesting though.