Including SVG graphics in posts

I have a host site, and a discourse site; each is hosted on a AWS EC2 unit. The host site is a data dashboard for schools, and I want to use the discourse site for discussing the data. For example, a user will click on a data visualization (f.e. a pie chart) on the host site, and start a conversation. This will create the topic on the host site and the discourse site, and embed comments from the discourse site on the host site. The reason for having the topic on the host site as well is that the visualisations could change over time and the user should be able to update their posts on the discourse site. Once the visualizations become stable, this feature might be redundant.

Being about data, the topics will include svg graphics (generated by d3.js on the client side of the host site). If discourse topic is created by the crawler, it will wipe out the svg. Thus I need to create the discourse topics via API. Another requirement is that users from a school should only see their schools topics.

Here is a possible scenario:

  • user signs on to host site, clicks on a visualization to create a topic
  • client side sends svg to server side, and creates a topic
  • server side sends API request(s) to discourse site to:
    – create subcategory for the school (if missing)
    – create group for the school (if missing)
    – adjust subcategory settings so the school group only have access
    – create the topic in the subcategory (including the svg)
    – get the link to the topic, so it can be used for comments embedding on the host site
  • send user’s school group to discourse during SSO
  • finally I will have to create a custom theme to include the css file with the styles needed for the svg

is this possible as far as the discourse is concerned?

do you think this is a solid architecture, if not what are the weaknesses?

I manually pasted svg elements in a post, and they got wiped out as well :frowning:

Which version of Discourse are you running? There was an issue with SVG which was recently fixed.

Are SVGs an allowed file type on your site?

I believe there are security risks involved with allowing SVG to be posted inline, we do allow SVG uploaded as an image though β€” is it possible to produce a .svg file instead?

1 Like

2.2.0.beta3; I already initiated the upgrade to the most recent version (beta4). Will post if that would take svg elements in a post.

There is no involvement of SVG files on our site. It is the svg elements generated by d3.js on the client side I was talking about.

Thank you for the reply. Generating .svg file from the svg elements might be a possibility. Never have done such a thing, will have to research.

Seems it is technically possible. Here is a related StackOverflow question.

If I saved the .svg file on my host site, then I would not need embedding of discourse comments back on the host site. Everything would be on the discourse site, except the .svg file.