Embedding Discourse Comments via Javascript

embedding

(Павел Кульков) #255

Hi! Is it possible to add such feature in roadmap or by myself? Its realy usefull


#256

relevant question.


(Eric Potratz) #257

I thought ‘page comments’ were not possible with Discouse, but then I found this post.

I haven’t read all 167 posts yet. Can somebody breakdown the pros and cons of this “embedded” approach?

And has the original 2015 post been updated with the latest best practices for this approach?

Thanks,


(Quim Gil) #258

Hi, I don’t think it is a matter of pros and cons. If you have a self-hosted WordPress, use the WP-Discourse plugin. If you don’t, then this JS-based method is your next (and for many last) possibility to connect your website pages with Discourse discussions.


(Allen Lee) #259

We’d like to use Discourse for comments on various community-generated content and it’d be awesome if we could have it tied to the original user… I’d be happy to try contributing a PR for this if it’s not too complicated… Should I be looking at EmbedController and topic_embed.rb?

As a concrete example of what we’d like to accomplish, we’d like for Artificial Anasazi and Artificial Anasazi - Code - CoMSES Net to have the same submitter so comments on the topic would go to the user generating the content, not a black hole system user.


(Robin Ward) #260

Can you not use the embed_username_key_from_feed setting?

Otherwise you can use the discourseUserName when embedding.


(Andy at Focallocal) #261

there are an amazing number of people who want this.

as a plugin addition to the community i don’t think it has to draw people away from the forum, it’s just adding an extension of its functionality.


(Andy at Focallocal) #262

everyone seems to want this, perhaps we should all band together and build it?


Using Discourse to power comments in an event system or blog?
(Carlo) #263

Answered here :wink::


#264

Why is the mini profiler appearing in embedded comments while it’s disabled in the Discourse settings?


(Robin Ward) #265

That’s actually a good question for @sam


(Greg) #266

Is it possible to access sub-elements of the XML when parsing a feed for author usernames? I’m using jekyll-feed and given my current config, I’m getting XML like:

<author>
  <name>Greg Sutcliffe</name>
  <uri>gwmngilfen</uri>
</author>

jekyll-feed only passes a limited number of fields to the Atom XML, hence why I’m using “uri” as the place for the discourse username.

It’s not clear to me how to get the value of “uri” into Discourse. Is it just “uri”? or do I need some kind of namespace indicator like “author:uri”?


(Greg) #267

I’m also seeing a strange behaviour with some links. Compare this blog post with the imported version and look to the “Plugins” heading - in the original, there is a large collection of links to updated plugins, but in the imported version it’s been stripped.

This was imported via the feed parser, but I went back through some older posts and it was happening with the scraper too. I see other links in the post are getting imported, so what is different here?


(Christoph Holtermann) #268

Getting information about embedded discourses state has been implemented with pull requests #5276 and #6043.


#269

Hi folks,

I integrated discourse comments on a static website generated using Publii, you can check it with some dummy comments I just loaded at the following url :

Yeah I know, it’s not HTTPS for now but it’s on purpose. I’m hosting the site on AWS S3 and don’t want to use cloudfront. I’ll use another cheaper CDN I found with let’s encrypt on top of it. --> [edit] done.

I don’t have anything against disqus, however I think it will engage more people on the forum by using this integration (so big thank you guys for that !).

Regarding the integration, I used the following code :

    <div id='discourse-comments'></div>
<script type="text/javascript"> DiscourseEmbed = { discourseUrl: 'https://forum.hope4honor.com/', discourseEmbedUrl: window.location.href };
(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>

So I used window.location.href for the discourseEmbedUrl, as the comments will be embedded on every posts. I might work on an option in Publii to disable the comments on some posts.

I don’t think I saw anyone using the window.location here, I was wondering if there was any specific reason ? (as I’m a noob in JS, if I’m missing anything or if there was no need for it so far).
And 2nd, it takes a few seconds for the comments to load on the very first time “if” I do not refresh the page. I’m guessing this is the time for the 1st post to init in the forum by adding the topic content, but it seems to load much faster if I do refresh the page right after it has loaded (so I’m considering putting some auto-refresh) : any idea why this is ? (can dig more to check).


(Allen Lee) #270

Great to know, adding a discourseUserName property to the DiscourseEmbed object worked like a charm! It would be nice to have a short section describing what properties can be included in DiscourseEmbed


(Jhf2442) #271

Had some trouble getting the feature to work - turned out the docker container running discourse wanted to make a TCP connection to the domain serving the web page embedding the discussion. However, DNS prevented it from resolving the domain. From rails/production.log :

Job exception: Failed to open TCP connection to intranet.test.local:80 (getaddrinfo: Name or service not known)

-> what’s the purpose of the TCP connection to port 80 ?

Note : adding the domain to the /etc/hosts of the container helped solve the issue


(Jhf2442) #272

oh and BTW, the embedded discourse messages list doesn’t refresh at all - did I miss some configuration option ?


(Mehmet Dogan) #275

I will have svg graphics on my page, will they be extracted as well?

My second question is, if the contents of the page later updated, will discourse site be updated as well? if not automatically, is there a manual way updating it?

Thanks, and sorry if any of these questions are repetitive. I read about half of the thread… reading all 182 posts was quite a challenge for me. This also made me think, there needs to be a better way of grouping similar issues.


(technik) #276

Is it possible to embed to embed multiple topics in one page with different div class ids?
I am not able to integrate two at once in two boxes beneath each other, everything gets either not displayed, or all in one box…

Does anyone can think of a solution for this?
Thanks a lot :slight_smile: