Glanceway Glanceway
所有資料來源

Reddit

社群 v1.0.0

Hot posts from a subreddit

@codytseng #reddit #social

安裝與設定方式

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

設定檢查

  • SUBREDDIT — 必填. Subreddit name without r/ (e.g. programming, javascript) 每個值分別作為一個清單項目新增。
  • SORT — 選填. Sort order for posts

看板名稱不含 r/,每個看板作為獨立清單項目新增。公開端點是否可用取決於 Reddit 的存取規則。目前支援 hot、new、top、rising 排序。

設定範例

SUBREDDIT (list items):
  programming
  selfhosted
SORT: hot

沒有顯示內容時如何排查

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

設定項目

名稱 鍵 類型 必填 預設值 描述
Subreddit SUBREDDIT list 是 — Subreddit name without r/ (e.g. programming, javascript)
Sort SORT select 否 hot Sort order for posts
hotnewtoprising

原始碼

id: codytseng/reddit
version: 1.0.0
name: Reddit
description: Hot posts from a subreddit
author: codytseng
author_url: https://github.com/codytseng
category: Social
tags:
  - reddit
  - social

config:
  - key: SUBREDDIT
    name: Subreddit
    type: list
    required: true
    description: Subreddit name without r/ (e.g. programming, javascript)
  - key: SORT
    name: Sort
    type: select
    required: false
    default: hot
    description: Sort order for posts
    options:
      - hot
      - new
      - top
      - rising
module.exports = async (api) => {
  const subreddits = api.config.get("SUBREDDIT") ?? ["programming"];
  const subreddit = subreddits.join("+");
  const sort = api.config.get("SORT") || "hot";

  async function fetchData() {
    const response = await api.fetch(`https://www.reddit.com/r/${subreddit}/${sort}.json?limit=100&raw_json=1`, {
      headers: { "User-Agent": "Glanceway/1.0" },
    });

    if (!response.ok || !response.json) {
      throw new Error(`Failed to fetch Reddit posts from r/${subreddit} (HTTP ${response.status})`);
    }

    api.emit(
      response.json.data.children.map((child) => {
        const post = child.data;
        return {
          id: post.id,
          title: post.title,
          subtitle: post.selftext || `↑ ${post.score} · ${post.num_comments} comments · u/${post.author}`,
          url: post.url.startsWith("/")
            ? `https://www.reddit.com${post.url}`
            : post.url,
          timestamp: post.created_utc,
        };
      }),
    );
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};

相關資料來源