Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/routes/trendshift/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'TrendShift',
url: 'trendshift.io',
lang: 'en',
};
72 changes: 72 additions & 0 deletions lib/routes/trendshift/trending.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { Data, Route } from '@/types';
import got from '@/utils/got';
import { parseRelativeDate } from '@/utils/parse-date';

export const route: Route = {
path: '/trending/:language?',
categories: ['programming'],
example: '/trendshift/trending',
parameters: {
language: 'Programming language: javascript, typescript, python, etc., or default all languages',
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['trendshift.io/'],
},
],
name: 'Trending Repositories',
maintainers: ['Rjnishant530'],
handler,
url: 'trendshift.io/',
};

async function handler(ctx) {
const language = ctx.req.param('language') || 'all';
const date = parseRelativeDate('1 day ago');
const isoDate = new Date(date).toISOString().split('T')[0];
const nextAction = '7fcfa70a759dfb860300f6e58d2ba5a6e7d788cb13';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this hash changes across different build as it's 7f606d4702205bdec7f372cc3ca8fe5a382c132717 right now. You may look for script[src^="/_next/static/chunks/app/(site)/page-"] in head from the webpage and use regex like "([a-f\d]{42})" to parse it.

const url = 'https://trendshift.io';
const { data } = await got.post(url, {
json: [isoDate, language],
headers: { 'Content-Type': 'application/json', 'next-action': nextAction },
});

const jsonData = convertToJson(data);
const items = jsonData.map((item) => {
const { full_name, repository_stars, repository_forks, repository_language, repository_description } = item;
return {
title: full_name || 'Repository',
description: `${repository_description}\n\nStars: ${repository_stars}\nForks: ${repository_forks}\nLanguage: ${repository_language}`,
link: `https://github.com/${full_name}`,
category: [repository_language].filter(Boolean),
};
});

const languageText = language === 'all' ? 'All Languages' : language;

return {
title: `TrendShift - Daily repositories to explore ( ${languageText})`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: `TrendShift - Daily repositories to explore ( ${languageText})`,
title: `TrendShift - Daily repositories to explore (${languageText})`,

link: url,
item: items,
description: `An alternative to GitHub Trending, using a consistent scoring algorithm informed by daily engagement metrics`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: `An alternative to GitHub Trending, using a consistent scoring algorithm informed by daily engagement metrics`,
description: 'An alternative to GitHub Trending, using a consistent scoring algorithm informed by daily engagement metrics',

logo: 'https://trendshift.io/favicon.ico',
icon: 'https://trendshift.io/favicon.ico',
language: 'en-us',
} as Data;
}

function convertToJson(data: string): Array<any> {
const line = data.split('\n')[1];

const idx = line.indexOf(':');
const jsonpart = line.slice(idx + 1).trim();
return JSON.parse(jsonpart);
}