在GitHub Pages的post.html中添加Disqus导致页面内容消失的解决方法
解决Jekyll添加Disqus后网站内容消失的问题
你这问题大概率是自定义post.html布局时漏掉了Jekyll核心的渲染逻辑,导致页面结构和文章内容都没被正确输出。按下面的步骤调整就能搞定:
先让自定义布局继承基础页面结构
Jekyll的布局是分层继承的,你新建的post.html得先对接网站的基础布局(一般是default.html或者base.html),这样才会包含页面的头部导航、页脚这些必要结构。在post.html的最顶部加上这段YAML前置声明:--- layout: default ---要是你的基础布局文件名不是
default.html,记得改成你实际用的名字(比如base.html)。添加文章内容的渲染标签
Jekyll靠{{ content }}这个变量来渲染文章的正文内容,你只放了Disqus的代码,没加这个标签,文章内容自然不会显示。把{{ content }}放在Disqus代码的前面,这样正文会先展示,之后才是评论区。
调整后的完整post.html应该是这样的:
--- layout: default --- {{ content }} <div id="disqus_thread"></div> <script> /** * RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS. * LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/ /* var disqus_config = function () { this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable }; */ (function() { // DON'T EDIT BELOW THIS LINE var d = document, s = d.createElement('script'); s.src = 'https://https-diyago-github-io.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })(); </script> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
- 最后确认文章的前置声明
确保你所有的文章(.md格式的文件)顶部的YAML声明里,都指定了使用这个post布局:--- layout: post title: "你的文章标题" date: 2024-05-20 10:00:00 ---
这么调整之后,网站的基础结构、文章内容和Disqus评论区就都能正常显示啦!
内容的提问来源于stack exchange,提问作者Rocketq
相关产品推荐
相关产品推荐

