Glanceway Glanceway
所有信息源

Wikipedia On This Day

其他 v1.0.0

Historical events that happened on today's date from Wikipedia

@codytseng #wikipedia #history #today

安装与配置方法

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

配置检查

  • LANGUAGE — 可选. Wikipedia language edition

没有显示内容时如何排查

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

配置项

名称 键 类型 必填 默认值 描述
Language LANGUAGE select 否 en Wikipedia language edition
enzhjadefres

源代码

id: codytseng/wikipedia-on-this-day
version: 1.0.0
name: Wikipedia On This Day
description: Historical events that happened on today's date from Wikipedia
author: codytseng
author_url: https://github.com/codytseng
category: Other
tags:
  - wikipedia
  - history
  - today

config:
  - key: LANGUAGE
    name: Language
    type: select
    required: false
    default: en
    description: Wikipedia language edition
    options:
      - en
      - zh
      - ja
      - de
      - fr
      - es
module.exports = async (api) => {
  const language = api.config.get("LANGUAGE") || "en";

  async function fetchData() {
    const now = new Date();
    const mm = String(now.getMonth() + 1).padStart(2, "0");
    const dd = String(now.getDate()).padStart(2, "0");

    const url = `https://api.wikimedia.org/feed/v1/wikipedia/${language}/onthisday/all/${mm}/${dd}`;

    const response = await api.fetch(url);

    if (!response.ok || !response.json) {
      throw new Error(
        `Failed to fetch Wikipedia On This Day (HTTP ${response.status})`,
      );
    }

    const events = [
      ...(response.json.selected || []),
      ...(response.json.events || []),
    ];

    const seen = new Set();
    const items = [];

    for (const item of events) {
      const page = item.pages?.[0];
      const id = `${item.year}-${page?.title || item.text.slice(0, 50)}`;

      if (seen.has(id)) continue;
      seen.add(id);

      items.push({
        id,
        title: `${item.year} \u2014 ${item.text}`,
        subtitle: page?.extract,
        url: page?.content_urls?.desktop?.page,
      });

      if (items.length >= 200) break;
    }

    api.emit(items);
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};