Embedding Discourse Comments via Javascript

embedding

(Ringgit Malaysia) #146

Have anyone attempted to embed Discourse into the main page of a blog which have multiple posts? This is what happens to my main page when there are 4 posts:


If I hover my house over “Start Discussion”, the URL that is showing on the status bar is the Discourse topics of the 4th post in the page. All four “Start Discussion” shows the same URL of the 4th post.

It’s as though the code looked at all the elements on the page and find 4 post elements and proceed to create 4 embedded entries.

The way I overcome this is to count number of post in page. If it is more than 1, then I hide the embedded Discourse and just shows “Comments” using kcoop’s code.


(Robin Ward) #147

There’s no way to embed comments on multiple posts on the same page. You can, however, use an index view with counts. This is what I do on https://eviltrout.com - you can see the source code for my blog here.


(Ringgit Malaysia) #148

I decide to hide it using

<b:if cond='data:numPosts == 1'> and then use @kcoop Blogger plugin to count the comment, similar to your codes. Thanks @eviltrout


(@SenpaiMass) #149

is it possible that discourse imports the username (creator of the thread as well) from ghost blogging platform?

Some of my community members use the blog to get articles but the imports is done only via one username which is specified.


(Robin Ward) #150

Unfortunately there’s no way to do this at this time.


(Sukima) #154

This how to provides almost all the info I need except one key question: Can you have more then one embeded topic on a single page?

Clarification, I have a single page application which displays several cards of content. Specifically I’m using http://tiddlywiki.com. Since this is a wiki in a single page app each card would have its own topic and attempt to embed a unique script tag which means displaying 3 cards would result in three DiscourseEmbed.topicId configurations on one HTML page. And this number would be dynamic as the card DOM elements were added and removed.

I noticed that topicId (and discourseEmbedUrl) properties are never used in constructing the <script> tag which means the code in http://discourse.example.com/javascripts/embed.js is looking for a global window.DiscourseEmbed object. Is this really the case where the embed code relies polluting the global name space? Is there a way to pass these configurations into the script src? Or provide the src url with a callback function name much like JSONP?

Thanks for any clarification.


(Robin Ward) #155

Unfortunately not. In theory it would be possible to offer a more robust client side embed library to support this, though.


(Stefano Maffulli) #156

I am investigating this as an option to add comments to documentation pages. The main issue I have is that I don’t want to have the content of the page copied in the new topic, I only want the title and maybe the first 20 characters. The reason is that documentation may get updated and I don’t want the content of an old page to be kept lingering on domains that I control.

Is there a way to avoid copying the content of a page over to the new topic?


(Thebravoman) #157

Had some problems with the “in a frame because it set ‘X-Frame-Options’ to ‘SAMEORIGIN’.”

I had to change the domain from example.com to www.example.com -> including the www. infront.
Only after that it started working.


(Jeff Atwood) #158

24 posts were split to a new topic: Embed Discourse as comments with on-page commenting?


Embed Discourse comments with on-page commenting?
(Lucas) #167

@eviltrout is possible to embed nested replies to a comment? Screen Shot 2016-12-29 at 23.14.04 - Jumpshare. Thanks in advance.


(Robin Ward) #168

Unfortunately no, there is no way to do that.


(Orion Burt) #169

Is there any way to open the reply editor on page load after coming from the “Continue Discussion” link in the embed or more generally via a URL/GET/POST parameter that can be added to the topic/post URL?

I understand the hesitation towards enabling too many comment system bad habits, but if this is at all possible I think it would help solve a lot of people’s issues with using Discourse for commenting without compromising the separate forum community that you are trying to encourage in the first place.

  • Grey reply links could be appended to each post in the embed that could link to Discourse with the “Reply to Post” editor open and scrolled to the corresponding post.
  • The blue Continue Discussion link could link to Discourse with the “Reply to Topic” editor open and scrolled to the last post.
  • If necessary, this could be an “enable at your own risk” feature that you have to opt in to in the Discourse Customize > Embedding settings.
  • If user is not logged in already on Discourse, then you simply skip the open the reply editor step (but keep it scrolled to the corresponding or last post).

This could also bolster the response notification emails. As it currently stands (or last I received one) the options are “Visit Topic or reply to this email to respond”. If the reply to post editor could be opened on page load, you could expand this to “Visit Topic, Reply at Forum, or reply to this email to respond” which people would appreciate if they are planning on using the very nice Discourse reply editor anyway.


(Davidweisss) #170

Can there be a wildcard to match several subfolders?

Use case:
https://your-site.com/an-user/great-new-feature-under-development

I would like all users to be aware of the discussion about, and be able to comment on, this great new feature.

Can there be something like
https://your-site.com/(wildcard-character)/great-new-feature-under-development

Thanks would be really really cool.


(Robin Ward) #171

If you’re talking about Discourse on a subfolder, we only allow you to use one subfolder per install. (I mention this because the post you reply to was talking about that case.)

If you’re talking about embedding for multiple folders on the site you’re embedding it on, sure. You can use a regular expression in the path whitelist. For example /blog/.*


(Davidweisss) #172

Neat!

Was indeed talking about embedding, sorry for the confusion.

Will try it out.


(Mudedla Panduranga Rao ) #173

Nice feature. I’m having problem when embedding discourse comments when using discourseEmbedUrl, but this is working fine when i embedded with topic id. I’m getting ‘Loading Discourse’ when i embedded with discourseEmbedUrl. Some one please help me to resolve this.


(Joe Buhlig) #174

I just ran into what I think is a bug with this. I switched my blog over to https from http. So technically speaking, Discourse sees these as new posts. Which means I’m now being inundated with new posts that are duplicates.

Is it possible to prevent this and have it check for either protocol before creating new?


Embed creating duplicate http / https topics
(Robin Ward) #175

This has come up before a couple of times (including @codinghorror’s forum) and I don’t think it’s been successfully fixed. We should probably investigate into a way of having it consider both URLs the same.

In the meantime, the solution is unfortunately to update your topic_embed table manually.


(Cassie S) #176

Hello! I actually have 2 things.

First, I can get the plugin to work on a static site (on github pages), if I use the TopicId option. However, only the comments are loading. The initial topic post is not. Is this by design, or is there a bug here?

Second, I am having problems using the standard url to create a new topic, like @mrrao. I am working on a local host, though, and some of the comments above implied that might be part of the problem? Is there any way for someone to confirm this?

(EDIT: we now have the url option working. It was apparently an issue with the configuration of our local network. It is suffering from the same problem as the TopicID, however (the initial post in the thread is not shown)

Thanks!