-
请教下怎么在html文件中调用最新的几条评论,看文档中没写,使用的hugo博客系统,感谢 |
Beta Was this translation helpful? Give feedback.
Answered by
qwqcode
Feb 1, 2024
Replies: 2 comments
-
可以请求这个接口: 参考以下案例: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Latest Comments</title>
</head>
<body>
<h1>Latest Comments</h1>
<ul id="commentsList"></ul>
<script>
// 构造请求的URL
const apiUrl = "{你的Artalk地址}/api/v2/stats/latest_comments?site_name=站点名&limit=5";
// 发起GET请求
fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
// 处理响应数据
const comments = data.data;
const commentsList = document.getElementById('commentsList');
// 遍历评论并添加到页面中
comments.forEach(comment => {
const li = document.createElement('li');
li.textContent = comment.content;
commentsList.appendChild(li);
});
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
</script>
</body>
</html> 可参考 HTTP 文档:https://artalk.js.org/http-api#tag/Statistic/operation/GetStats 有点麻烦,下一个版本我打算加一个函数到 Artalk,直接调用就能获取最新评论 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
qwqcode
-
感谢,下个版本增加的时候,是否可以配置调用的时候,选择是否需要头像/用户名之类的,然后评论的跳转链接是不是可以加上~。还有能不能排除特定用户的评论,譬如排除掉管理员的评论~ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以请求这个接口:
{你的Artalk地址}/api/v2/stats/latest_comments?site_name=站点名&limit=5
获取最新的 5 条评论参考以下案例: