Añadir contenido dinámico a <head> - AMP - ¿alguna sugerencia?

Usé:

<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;
            else{
                var link=document.createElement('link');
                link.id='amphtml';
                link.rel='amphtml';
                link.href=amp;
                document.getElementsByTagName('head')[0].appendChild(link);
            }
        }
    });
</script>

Pero al ver el código fuente no aparece; solo se muestra cuando se ejecuta JavaScript.
Entonces, ¿cómo puedo renderizarlo desde el principio?


13-03-20

Intenté cambiarlo añadiendo <xhtml:link rel="amphtml" href="" /> al Sitemap.
Demo: GitHub - bcat95/discourse-sitemap: Generate XML sitemap for your Discourse forum. · GitHub

14-03-20

Funciona, Google ya está indexando las páginas AMP