Glanceway Glanceway
All sources

Qiita

Developer v1.0.0

日本最大の開発者向け技術記事プラットフォーム Qiita の人気記事

@codytseng #qiita #japanese #tech #articles

Configuration

Name Key Type Required Default Description
タグ TAG list No タグでフィルター(例:Python, JavaScript, React)。空欄の場合は全タグの人気記事を表示します。

Source Code

version: 1.0.0
name: Qiita
description: 日本最大の開発者向け技術記事プラットフォーム Qiita の人気記事
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
  - qiita
  - japanese
  - tech
  - articles

config:
  - key: TAG
    name: タグ
    type: list
    required: false
    description: タグでフィルター(例:Python, JavaScript, React)。空欄の場合は全タグの人気記事を表示します。
module.exports = async (api) => {
  const tags = api.config.get("TAG") ?? [];

  async function fetchData() {
    const toItems = (articles) =>
      articles.map((article) => ({
        id: article.id,
        title: article.title,
        subtitle:
          article.body?.slice(0, 120)?.replace(/\n/g, " ") ||
          `${article.likes_count} いいね · @${article.user.id}`,
        url: article.url,
        timestamp: article.created_at,
      }));

    if (tags.length > 0) {
      const perPage = Math.min(100, Math.floor(500 / tags.length));
      await Promise.allSettled(
        tags.map(async (tag) => {
          const res = await api.fetch(
            `https://qiita.com/api/v2/tags/${encodeURIComponent(tag)}/items?per_page=${perPage}&page=1`,
          );
          if (res.ok && res.json) {
            api.emit(toItems(res.json));
          }
        }),
      );
    } else {
      const res = await api.fetch(
        "https://qiita.com/api/v2/items?per_page=100&page=1",
      );
      if (!res.ok || !res.json) {
        throw new Error(`Failed to fetch Qiita articles (HTTP ${res.status})`);
      }
      api.emit(toItems(res.json));
    }
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};

Related Sources