Configuring Discourse for Embedding (simple setup)
The following setup will embed a comment feed on a page on a fake blog URL of http://example.com/blog/entry-123.html
, from a discourse forum running at =DISCOURSE=
.
Domain for
Domain for
-
Visit Admin > Customize > Embedding on your Discourse install. https://=DISCOURSE=/admin/customize/embedding
-
Create at least one Embeddable Host. This should be the hostname (domain) where you want to embed your comments. In this case the host is
=BLOG=
– note the lack ofhttp://
and path.-
Path Allowlist allows you to specify the paths on the remote host that would accept your embed.
-
Post to Category - if you supply a category alongside the host you are entering, posts imported from that host will automatically end up in that category. Different hosts can post to different categories.
-
-
Fill in the name of a user on your discourse who will create topics in the
Username for topic creation
field below the HTML snippet. Let’s assume our discourse has a user called eviltrout, so the value iseviltrout
. -
Insert the following HTML on the web page at
http://=BLOG=/blog/entry-123.html
(Optional) Adding a Feed for Polling
As mentioned above, Discourse will automatically crawl any site it is embedded on. However, sometimes HTML can be hard to parse and it might not extract the contents of your posts correctly. Many blogs and web sites support RSS/Atom feeds for syndication, and Discourse can use this to extract the content of your blog posts more accurately.
If you have a RSS or Atom feed set up on the site you are embedding Discourse into, you can configure Discourse to extract the content of posts from there by installing the Discourse RSS Polling plugin and adding your feed’s URL to the plugin’s settings. Once the feed URL has been added, Discourse will parse the feed and publish its posts to the appropriate category based on the Allowed Hosts that you add to your Embedding settings.
(Alternate Configuration) Linking to existing topics
Some people prefer to not have Discourse create topics for them automatically on their forums. They’d like to create the topics themselves, then simply tell their embedding code what topic they want to associate with. You can do this by slightly changing your embedding code:
<div id='discourse-comments'></div>
<script type="text/javascript">
window.DiscourseEmbed = {
discourseUrl: 'https://=DISCOURSE=/',
topicId: 12345
};
(function() {
var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
d.src = window.DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
})();
</script>
This is also a showcase of Discourse 编辑器功能测试:变量赋值与使用