添加评论区

This commit is contained in:
cxykevin 2024-09-17 09:23:06 +08:00
parent 5cc3235e5a
commit 1a269c120e
1 changed files with 27 additions and 1 deletions

View File

@ -56,6 +56,7 @@
<!-- 自定义字体 --> <!-- 自定义字体 -->
<link href="{{ ../path_to_root }}theme/css/font.css" rel="stylesheet"> <link href="{{ ../path_to_root }}theme/css/font.css" rel="stylesheet">
</head> </head>
<body style="margin:0;padding:0;"> <body style="margin:0;padding:0;">
@ -180,6 +181,13 @@
</div> </div>
</mdui-card> </mdui-card>
{{/next}} {{/next}}
</div>
<!-- 评论区插入点 -->
<div style="height:0.5em"></div>
<div style="width:90%;margin:auto;">
<div id="sacn_comments"></div>
</div> </div>
</mdui-layout-main> </mdui-layout-main>
@ -226,16 +234,34 @@
<!-- 留白 --> <!-- 留白 -->
<div style="height:2em"></div> <div style="height:2em"></div>
<!-- 评论区 -->
<script>
// 更新评论框高度
window.addEventListener('message', function (event) {
if (event.data.sacn_height) {
const iframe = document.getElementById('sacn_comments');
iframe.style.height = event.data.sacn_height + 'px';
}
});
// 加载评论区
function load_comments(route) {
var tmpl = `<iframe src="https://comments.study-area.org.cn` + route + `" frameborder="0" scrolling="no" width="100%" height="800px"
id="sacn_comments">Comments</iframe>`
document.getElementById('sacn_comments').outerHTML = tmpl;
}
</script>
<!-- 高亮 --> <!-- 高亮 -->
<script> <script>
window.addEventListener('load', function () { window.addEventListener('load', function () {
hljs.highlightAll(); hljs.highlightAll();
load_comments("/sacn" + window.location.pathname);
}); });
</script> </script>
<!-- 页面 JS --> <!-- 页面 JS -->
<script src="{{ ../path_to_root }}theme/js/page.js"></script> <script src="{{ ../path_to_root }}theme/js/page.js"></script>
</body> </body>
</html> </html>