Bcat
(Bcat)
1
누군가 POST ID로 동적으로 생성된 콘텐츠를 헤더에 삽입하는 방법을 알려주실 수 있나요?
시해 보았지만 head와 body 밖에 위치해 있었습니다. 또한, 페이지가 로드된 후에만 렌더링되며 view-source에는 표시되지 않습니다.
<script type="text/x-handlebars" data-template-name="/connectors/PLUGIN-OUTLET-NAME/UNIQUE-NAME">
</script>
이것을 수행하려면 플러그인이 필요할 것 같습니다!
\app\helpers\application_helper.rb와 비슷합니다.
p/s: 이전 게시글 Add rel="amphtml" to head - any tips?
Bcat
(Bcat)
3
다음 코드를 사용했습니다:
<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>
하지만 소스를 보기(View Source)할 때는 나타나지 않고, JavaScript가 실행될 때만 표시됩니다.
처음부터 렌더링하는 방법은 무엇인가요?
2020-03-13
Sitemap에 <xhtml:link rel="amphtml" href="" />를 추가하여 변경해 보았습니다.
데모: GitHub - bcat95/discourse-sitemap: Generate XML sitemap for your Discourse forum. · GitHub
2020-03-14
성공적으로 해결되었으며, Google이 AMP 페이지를 색인화하기 시작했습니다.