Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教下怎么在html文件中调用最新的几条评论 #742

Closed
koobai opened this issue Jan 11, 2024 · 2 comments
Closed

请教下怎么在html文件中调用最新的几条评论 #742

koobai opened this issue Jan 11, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@koobai
Copy link

koobai commented Jan 11, 2024

请教下怎么在html文件中调用最新的几条评论,看文档中没写,使用的hugo博客系统,感谢

@qwqcode
Copy link
Member

qwqcode commented Feb 1, 2024

可以请求这个接口:{你的Artalk地址}/api/v2/stats/latest_comments?site_name=站点名&limit=5 获取最新的 5 条评论

参考以下案例:

<!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,直接调用就能获取最新评论

@qwqcode qwqcode added the enhancement New feature or request label Feb 1, 2024
@koobai
Copy link
Author

koobai commented Feb 2, 2024

感谢,下个版本增加的时候,是否可以配置调用的时候,选择是否需要头像/用户名之类的,然后评论的跳转链接是不是可以加上~。还有能不能排除特定用户的评论,譬如排除掉管理员的评论~

@qwqcode qwqcode closed this as completed May 26, 2024
@ArtalkJS ArtalkJS locked and limited conversation to collaborators May 26, 2024
@qwqcode qwqcode converted this issue into discussion #887 May 26, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants