Eu usei:
<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>
Mas ao visualizar a origem, ele não aparece; só é mostrado quando o JavaScript é executado.
Então, como renderizar desde o início?
13-03-20
Tentei mudar adicionando <xhtml:link rel="amphtml" href="" /> ao Sitemap.
Demo: GitHub - bcat95/discourse-sitemap: Generate XML sitemap for your Discourse forum. · GitHub
14-03-20
Sucesso: o Google começou a indexar as páginas AMP