Glanceway Glanceway
所有資料來源

StackOverflow Hot

開發者 v1.0.0

Hot questions from StackOverflow

@codytseng #stackoverflow #programming #qa

安裝與設定方式

  1. 先在 Mac 上安裝並開啟 Glanceway,再使用上方的安裝連結。
  2. 點選「安裝到 Glanceway」。若瀏覽器無法開啟應用程式,下載 .gwsrc 檔案並在資訊源管理中匯入。
  3. 填寫以下必填欄位並儲存,設定更新間隔,等待首次成功取得內容。

設定檢查

  • TAG — 選填. Filter by tag (e.g. javascript, python, react). Leave empty for all tags. 每個值分別作為一個清單項目新增。
  • SORT — 選填. Sort order for questions

沒有顯示內容時如何排查

  • 對照目前版本設定表檢查欄位、清單項目與憑證。下方範例不包含可用的真實憑證。
  • 檢查網路及上游服務狀態。認證失敗或速率限制可能使更新失敗,請依上游限制調整間隔。
  • 空清單也可能代表沒有符合條件的條目。內容與更新時間取決於資料提供方及資訊源實作。

設定項目

名稱 鍵 類型 必填 預設值 描述
Tag TAG list 否 — Filter by tag (e.g. javascript, python, react). Leave empty for all tags.
Sort SORT select 否 hot Sort order for questions
hotactivityvotescreationweekmonth

原始碼

id: codytseng/stackoverflow-hot
version: 1.0.0
name: StackOverflow Hot
description: Hot questions from StackOverflow
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
  - stackoverflow
  - programming
  - qa

config:
  - key: TAG
    name: Tag
    type: list
    required: false
    description: Filter by tag (e.g. javascript, python, react). Leave empty for all tags.
  - key: SORT
    name: Sort
    type: select
    required: false
    default: hot
    description: Sort order for questions
    options:
      - hot
      - activity
      - votes
      - creation
      - week
      - month
module.exports = async (api) => {
  const tags = api.config.get("TAG") ?? [];
  const sort = api.config.get("SORT") || "hot";

  async function fetchData() {
    const toItems = (questions) =>
      questions.map((q) => ({
        id: q.question_id.toString(),
        title: q.title,
        subtitle: `${q.score} votes · ${q.answer_count} answers · ${q.tags.slice(0, 3).join(", ")}`,
        url: q.link,
        timestamp: q.creation_date,
      }));

    if (tags.length > 0) {
      const pageSize = Math.min(100, Math.floor(500 / tags.length));
      await Promise.allSettled(
        tags.map(async (tag) => {
          const res = await api.fetch(
            `https://api.stackexchange.com/2.3/questions?order=desc&sort=${sort}&site=stackoverflow&pagesize=${pageSize}&tagged=${encodeURIComponent(tag)}`,
          );
          if (res.ok && res.json) {
            api.emit(toItems(res.json.items));
          }
        }),
      );
    } else {
      const res = await api.fetch(
        `https://api.stackexchange.com/2.3/questions?order=desc&sort=${sort}&site=stackoverflow&pagesize=100`,
      );
      if (!res.ok || !res.json) {
        throw new Error(`Failed to fetch Stack Overflow questions (HTTP ${res.status})`);
      }
      api.emit(toItems(res.json.items));
    }
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};

相關資料來源