ユーザーランキング/ユーザーウォールウィジェット
1分以内...
Waline はウィジェットでユーザーランキングやユーザーウォールを表示できます。ブログのサイドバーにコメントしたユーザーの情報を表示するのに便利です。
コンポーネントのオプション
ユーザーランキング/ユーザーウォールウィジェットの名前は UserList で、6 つのオプションがあります:
el(任意):マウント先の要素serverURL:サーバーのリンクcount取得するユーザー数mode:listはユーザーランキング、wallはユーザーウォールを意味しますlang:i18n 対応。詳しくは i18n を参照してくださいlocale:言語をカスタマイズします。詳しくは i18n を参照してください
このコンポーネントが返すデータ形式は Promise<{ users: WalineUser[], destroy: () => void }> です。
usersプロパティ:countと同数のユーザー一覧の配列destroyメソッド:ウィジェットを破棄する関数
基本的な使い方
ユーザーランキング
<div id="waline-users"></div>
<script type="module">
import { UserList } from 'https://cdn.jsdelivr.net/npm/@waline/client@v3/dist/waline.js';
UserList({
el: '#waline-users',
serverURL: 'http://waline.vercel.app',
count: 10,
});
</script>ユーザーウォール
<div id="waline-users"></div>
<script type="module">
import { UserList } from 'https://cdn.jsdelivr.net/npm/@waline/client@v3/dist/waline.js';
UserList({
el: '#waline-users',
serverURL: 'http://waline.vercel.app',
count: 50,
mode: 'wall',
});
</script>応用的な使い方
デフォルトの出力形式が気に入らない場合は、el オプションを省略してコンポーネントを呼び出し、データを取得して自分でレンダリングできます。
例:
<div id="waline-users"></div>
<script type="module">
import { UserList } from 'https://cdn.jsdelivr.net/npm/@waline/client@v3/dist/waline.js';
UserList({ serverURL: 'http://waline.vercel.app', count: 10 }).then(({ users }) => {
document.getElementById('waline-users').innerHTML = users.map(
(user) => `<a href="${user.link}">${user.nick}</a>`,
);
});
</script>TIPS: コメントエリアはデモ用です。質問がある場合は、Github Discussion で質問してください。
