梨尽兴 | Li's Blog

Back

an image targetting my articlean image targetting my article
机器人
Li's AI Summary
Li's AI
文章介绍了如何通过Waline API获取最新评论并显示在网站中。首先,浏览了Waline的官方接口文档,发现可以通过 /api/comment?type=recent 接口获取最新评论数据。然后,编写了一个适用于当前主题的评论展示组件。接下来,引入了代码片段Gist,并在src/plugins目录下新建了recentcomment.ts文件,并在src/assets/styles目录下新建了rc.css文件。最后,在src/components目录下新建了RecentComments.astro文件,并在Pure主题主页中使用了这个组件。
本摘要由AI生成,仅供参考,内容准确性请以原文为准

起因#

浏览 Waline的官方接口文档 时发现通过 /api/comment?type=recent 接口能返回网站最新评论数据,于是“奴役”AI给我写了一个适用当前主题的评论展示组件,目前没出啥大差错🤣

引入#

代码片段Gist开源地址:Recent Comments for Astro-Theme-Pure

rc.css文件#

src/assets/styles 目录下新建 rc.css 文件并填入以下内容:

RecentComments.astro文件#

  1. 在目录下 src/components 目录下新建 RecentComments.astro 文件并填入以下内容:

使用#

在Pure主题主页中使用#

增添 src/pages/index.astro 文件内容如下:

最小化使用#

---
import RecentComments from '@/components/RecentComments.astro'
---

<RecentComments />
astro
通过Waline API获取最新评论并显示
https://blog.ljx.icu/blog/show-recent-comments
Author Ljx
Published at November 2, 2025
Comment seems to stuck. Try to refresh?✨