Glanceway Glanceway
所有信息源

Hacker News

新闻 v1.0.0

Top stories from Hacker News

@codytseng #news #tech #programming

安装与配置方法

  1. 先在 Mac 上安装并打开 Glanceway,再使用上方的安装链接。
  2. 点击“安装到 Glanceway”。如果浏览器无法唤起应用,下载 .gwsrc 文件并在信息源管理中导入。
  3. 填写下列必填字段并保存,设置刷新间隔,等待首次成功获取。

配置检查

  • STORY_TYPE — 可选. Type of stories to display

没有显示内容时如何排查

  • 对照当前版本配置表核对字段、列表项和凭据。下方示例不包含可用的真实凭据。
  • 检查网络与上游服务状态。认证失败或速率限制可能导致刷新失败,应根据上游限制调整间隔。
  • 空列表也可能表示没有符合条件的条目。内容和更新时间取决于数据提供方及信息源实现。

配置项

名称 键 类型 必填 默认值 描述
Story Type STORY_TYPE select 否 top Type of stories to display
topnewbestaskshowjob

源代码

id: codytseng/hacker-news
version: 1.0.0
name: Hacker News
description: Top stories from Hacker News
author: codytseng
category: News
tags:
  - news
  - tech
  - programming

config:
  - key: STORY_TYPE
    name: Story Type
    type: select
    required: false
    default: top
    description: Type of stories to display
    options:
      - top
      - new
      - best
      - ask
      - show
      - job
module.exports = async (api) => {
  const storyType = api.config.get("STORY_TYPE") || "top";

  async function fetchData() {
    const endpoint = `https://hacker-news.firebaseio.com/v0/${storyType}stories.json`;
    const idsResponse = await api.fetch(endpoint);

    if (!idsResponse.ok || !idsResponse.json) {
      throw new Error(`Failed to fetch Hacker News story list (HTTP ${idsResponse.status})`);
    }

    const topIds = idsResponse.json.slice(0, 100);
    const items = [];

    await Promise.allSettled(
      topIds.map(async (id) => {
        const res = await api.fetch(
          `https://hacker-news.firebaseio.com/v0/item/${id}.json`,
        );
        if (res.json) {
          items.push(res.json);
          api.emit(
            items.map((item) => ({
              id: item.id.toString(),
              title: item.title,
              subtitle: `${item.score} points · ${item.descendants ?? 0} comments · by ${item.by}`,
              url: `https://news.ycombinator.com/item?id=${item.id}`,
              timestamp: item.time,
            })),
          );
        }
      }),
    );
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};

相关信息源