Add dynamic content to <head> - AMP - any tips?

Can anybody show me how to insert a piece of code into the header with dynamic content generated by POST ID!

I tried it but it was outside of head and body. Moreover, only render after the page is loaded, view-source is not displayed.

<script type="text/x-handlebars" data-template-name="/connectors/PLUGIN-OUTLET-NAME/UNIQUE-NAME">

I think a plugin is needed to do this!
It’s like \app\helpers\application_helper.rb

p/s: old posts

I used:

<script type="text/discourse-plugin" version="0.8">
    api.onPageChange((url, title) => {
        var res = url.match(/\/t\/(.*?)\/(\w+)/);
        if (res && res[2] > 0) {
            var amp = 'domain/amp/t/'+res[2];
            if (document.getElementById("amphtml")) document.getElementById("amphtml").href = amp;
                var link=document.createElement('link');

But when view source does not appear, it only shows when javascript executes.
So how to render from the beginning


I try to change by adding <xhtml:link rel="amphtml" href="" /> to Sitemap
Demo: GitHub - bcat95/discourse-sitemap: Generate XML sitemap for your Discourse forum.


It succeeds, google is starting to index AMP pages


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.