Glanceway Glanceway
सभी सोर्स

GitHub Trending

डेवलपर v1.0.0

Trending repositories on GitHub

@codytseng #github #trending #programming

कॉन्फ़िगरेशन

नाम कुंजी प्रकार आवश्यक डिफ़ॉल्ट विवरण
Language LANGUAGE string नहीं Filter by programming language (e.g., javascript, python). Leave empty for all languages.

सोर्स कोड

version: 1.0.0
name: GitHub Trending
description: Trending repositories on GitHub
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
  - github
  - trending
  - programming

config:
  - key: LANGUAGE
    name: Language
    type: string
    required: false
    description: Filter by programming language (e.g., javascript, python). Leave empty for all languages.
import type { GlancewayAPI, SourceMethods } from "../../types";

export default (api: GlancewayAPI): SourceMethods => {
  return {
    async refresh() {
      const language = api.config.get("LANGUAGE");

      const since = new Date();
      since.setDate(since.getDate() - 7);
      const sinceStr = since.toISOString().split("T")[0];

      let query = `created:>${sinceStr} stars:>5`;
      if (language) {
        query += ` language:${language}`;
      }

      const response = await api.fetch<{
        items: Array<{
          id: number;
          full_name: string;
          description: string | null;
          html_url: string;
          stargazers_count: number;
          language: string | null;
        }>;
      }>(
        `https://api.github.com/search/repositories?q=${encodeURIComponent(query)}&sort=stars&order=desc&per_page=30`,
      );

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

      api.emit(
        response.json.items.map((repo) => {
          return {
            id: repo.id.toString(),
            title: repo.full_name,
            subtitle: repo.description || `${repo.language ?? "Unknown"} · ${repo.stargazers_count} stars`,
            url: repo.html_url,
          };
        }),
      );
    },
  };
};