Recent comment Widget
小於 1 分鐘...
Waline supports displaying recent comments by widget, which is convenient for displaying the latest comments in the sidebar of the blog.
Component options
The latest comment widget is named RecentComments and contains three options:
el(optional): the element to be mountedserverURL: server linkcountThe number of recent comments needed to get
The data format returned by the component should be Promise<{ comment: WalineComment[], destroy: () => void }>.
commentproperty: an array of the most recent comments with exact number ofcountdestroymethod: a function which will destroy the widget
Basic usage
<div id="waline-recent"></div>
<script type="module">
import { RecentComments } from 'https://cdn.jsdelivr.net/npm/@waline/client/dist/waline.mjs';
RecentComments({
el: '#waline-recent',
serverURL: 'http://waline.vercel.app',
count: 10,
});
</script>提示
This will be rendered on #waline-recent using the default style.
Advanced usage
If you are not satisfied with the default output format, you can call the component by omitting the el option to get the data and render it yourself.
Example:
<div id="waline-recent"></div>
<script type="module">
import { RecentComments } from 'https://cdn.jsdelivr.net/npm/@waline/client/dist/waline.mjs';
RecentComments({
serverURL: 'http://waline.vercel.app',
count: 10,
}).then(({ comments }) => {
document.getElementById('waline-recent').innerHTML = comments.map(
(comment) => `${comment.nick}: ${comment.comment}`,
);
});
</script>TIPS: 評論區僅作評論展示,如有問題諮詢請去 Github Discussion 中提問。
