Embedding Discourse Comments via Javascript

embedding

(Jeff Atwood) #177

This is correct, the design assumes it is a blog and the first post is a duplicate (excerpt, technically) of the blog body. See my blog at https://blog.codinghorror.com for an example.


(Leandro) #181

How are the topics and blogs/urls linked?
Does discourse store the discourseEmbedUrl somewhere and uses only that value (literal) to fetch the topic?


(Robin Ward) #182

The embedUrl is passed to discourse, which then enqueues a job that will crawl and import the content of the page into a topic. Comments from that topic are then displayed via an iframe on the source page.


(Leandro) #183

Is it possible to embed a topic in a protected url?
To achieve this I’ve created those topics using a public atom feed (so discourse does not need to crawl and import the content). However; when I open any url it hangs on “Loading discussion…”. I was hoping that discourse would recognise the url and load the topic anyway (without crawling).
I know this is not the expected use case, but I was wondering if it possible.


#185

We have embedding working well, with one minor issue… Our forum is hosted in a subdirectory (sitename.com/forums). When viewing the embedded topic on the main site, the avatar images are not showing up (the urls do not include the /forums/ in the path). Oddly enough, all of the other urls in the embed are correct (the user details link, etc.)

When viewing the topic on the actual forum, the urls for the images DO correctly include the subdirectory.

I’m not seeing anything in the embed settings that would help. Any ideas?

Thanks!


(Robin Ward) #186

I couldn’t reproduce this. When I try locally with a relative_root set up for discourse, the embedded comments have the correct avatars, and I confirmed they have the correct path.

I reviewed the code path too and don’t see how the subdirectory could be missing - maybe it’s a plugin or something?


#187

Thanks for taking a look. I’ll dig in a bit more and see what I can find.


(Christoph) #188

I just tried inserting the following javascript code into one of my wordpress pages by using the Code Snippets plugin:

<script type="text/javascript">
DiscourseEmbed = { discourseUrl: 'https://forum.mydomain.net/',
                               topicId: 33 };
 (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>

and it went horribly wrong. It brought down my entire Wordpress site. I’m not kidding. Every single URL just produced a 404 error as soon as I had saved and activated the above code in the Code Snippets plugin. I hadn’t even placed it on any page yet.

So I guess you shouldn’t do that…

If the same happened to anyone else, here’s how I got WP going again: the trick is that the Code Snippets plugin has a safe-mode switch that you can add to any URL and it will deactivate all codesnippets while calling that page: it’s simply ?snippets-safe-mode=true That way I was able to navigate to the snippet and deactivate it in safe mode.


How to enable Discourse comments via JavaScript in Wordpress?
(Philip Finlay Bryan) #195

My embedding does not work am I doing something stupid Here’s the code I am trying to embed :slight_smile:

Use the following HTML code into your site to create and embed discourse topics. Replace REPLACE_ME with the canonical URL of the page you are embedding it on.

But it just doesn’t work HELP!


(Philip Finlay Bryan) #196

ok i fixed it there was a fault in the html it put in a paragraph tag so removed it and it now works. However I can’t get it to work on a wordpress.com site it just removes the java script when I paste it in


(Erlend Sogge Heggen) #197

On a WP site you should just use the official WordPress plugin instead:


(John Brandenburg) #199

Using this method, along with the Drupal module available here: https://www.drupal.org/project/discourse, whose embedding tool seems broken. I was only able to get a page with "redirected you too many times."

It seems to redirect back and forth between the test page I have the embed code on and my trydiscourse.com/session/sso URL. Any suggestions?


(Quintin Par) #203

Do you still have discourse commenting system turned one? Couldn’t find


(Robin Ward) #205

execution expired means that there is timeout while trying to reach your site from the discourse install. You should make sure that there’s nothing preventing your discourse forum from reaching your website where you’ve embedded it.


(Ben Porter) #206

Nah, I removed them. It all worked well though!


Embed Discourse comments with on-page commenting?
(Raphaël Jadot) #208

Hello,

I tried as much things as I could, but the comments are not displayed and I have these javascript errors:

La ressource à l’adresse « https://discourse-static.openmandriva.org/mini-profiler-resources/includes.js?v=52dc741c63ccbaf9d87102ee24033482 » a été bloquée en raison d’un type MIME incorrect (X-Content-Type-Options: nosniff).

Meaning that the include.js files with query are blocked because of an incorrect mime type, following the «X-Content-Type-Options: nosniff» rule.

How can I prevent these files to be blocked?


(Robin Ward) #209

Mini profiler should not be the real error here. In fact you can disable it by visiting your main site by adding ?pp=disable to the URL.

Is there another error in the log not related to mini profiler?


Embed Discourse comments with on-page commenting?
(Raphaël Jadot) #210

I’m sorry, in fact I fought with several issues (CORS, uncorrect javascript call) and the fact there was another reverse proxy based on nginx preventing CORS. I pointed out the wrong guilty.

I solved the problem and indeed, mini profiler is not a problem.

May I just ask: is it possible to force the language of texts on the fly (I mean to force to have «Continue discussion» for an English page, and «Continuer la discussion» for a French page)? I mean, for now it detects the parameters of the browser, but is it possible to force with a variable?


(r3d_f0x) #211

How do I embed the comments?

I made this code on Discourse:

<div id='discourse-comments'></div>

<script type="text/javascript">
  DiscourseEmbed = { discourseUrl: 'https://forum.r3df0x.com/',
                     discourseEmbedUrl: 'https://r3df0x.com<%= current_page.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);
  })();
</script>

The page is here: Sample Page – r3d_f0x

It says “loading discussion” but nothing appears.


(Robin Ward) #212

Do you have the set_locale_from_accept_language_header setting set? If so, disable it and it should use your default_locale setting.

You should follow the instructions in the first post of this topic and go from there.