Discourse Comment Embed to Support Google AMP?

I’m not using Wordpress for this but I did look over that plugin for ideas. Cool that you got it working on your site @simon !

@sam I just got the embed working by bypassing the javascripts/embed.js logic completely. I still need to handle the iframe sizing issue but all of the functionality seems to be good. Basically I used the output from javascripts/embed.js with some additional sandbox settings.

<iframe id="discourse-embed-frame"
        height="200"
        width="300"
        src="discourseurl.tld/embed/comments?embed_url={{canonical}}&discourse_username={{username}}"
        frameborder="0"
        sandbox="allow-scripts allow-same-origin allow-popups"
        scrolling="no"
        layout="responsive">
</iframe>

I just swap this out with amp-iframe for amp pages.

The main question in my mind is “Should I be doing this?” Looking over javascripts/embed.js again, I am mostly missing out on the iframe sizing and url normalization, but if that script changes I’ll be none the wiser.

3 Likes