Glanceway Glanceway
Todas as fontes

Lobsters

Desenvolvimento v1.0.0

Hottest stories from Lobsters

@codytseng #news #tech #programming

Configuração

Nome Chave Tipo Obrigatório Padrão Descrição
Tag TAG string Não Filter by tag, comma-separated for multiple (e.g., programming,security,linux). Leave empty for all tags.

Código-fonte

version: 1.0.0
name: Lobsters
description: Hottest stories from Lobsters
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
  - news
  - tech
  - programming

config:
  - key: TAG
    name: Tag
    type: string
    required: false
    description: Filter by tag, comma-separated for multiple (e.g., programming,security,linux). Leave empty for all tags.
import type { GlancewayAPI, SourceMethods } from "../../types";

export default (api: GlancewayAPI): SourceMethods => {
  return {
    async refresh() {
      const tagConfig = api.config.get("TAG");
      const url = tagConfig
        ? `https://lobste.rs/t/${tagConfig.split(",").map((t) => t.trim()).filter(Boolean).join(",")}.json`
        : "https://lobste.rs/hottest.json";

      const response = await api.fetch<
        Array<{
          short_id: string;
          title: string;
          url: string;
          comments_url: string;
          score: number;
          comment_count: number;
          tags: string[];
          submitter_user: { username: string };
          created_at: string;
        }>
      >(url);

      if (!response.ok || !response.json) {
        return;
      }

      api.emit(
        response.json.slice(0, 30).map((story) => ({
          id: story.short_id,
          title: story.title,
          subtitle: story.description || `${story.score} points · ${story.comment_count} comments · ${story.tags.join(", ")}`,
          url: story.url || story.comments_url,
          timestamp: story.created_at,
        })),
      );
    },
  };
};