配置项
| 名称 | 键 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|---|
| Story Type | STORY_TYPE | select | 否 | top | Type of stories to display topnewbestaskshowjob |
源代码
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 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,
};
}; 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,
};
}; 相关信息源
Earthquake Alerts
新闻Recent significant earthquakes worldwide from USGS
#earthquake #alerts #science
Product Hunt
新闻Today's top products from Product Hunt
#producthunt #products #startups
PTT 热门文章
新闻台湾最大 BBS — PTT 的热门看板文章
#ptt #taiwan #chinese #bbs
Spaceflight News
新闻Latest space and spaceflight news articles from SNAPI
#space #science #spaceflight