Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions lib/routes/thinkingmachines/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Thinking Machines Lab',
url: 'thinkingmachines.ai',
};
84 changes: 84 additions & 0 deletions lib/routes/thinkingmachines/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import type { Route } from '@/types';

Check failure

Code scanning / oxlint

simple-import-sort(imports) Error

Run autofix to sort these imports!

import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import { load } from 'cheerio';

export const route: Route = {
path: '/news',
name: 'News',
url: 'thinkingmachines.ai/news',
maintainers: ['w3nhao'],
example: '/thinkingmachines/news',
categories: ['programming'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
},
radar: [
{
source: ['thinkingmachines.ai/news', 'thinkingmachines.ai/news/'],
target: '/news',
},
],
handler,
};

async function handler() {
const baseUrl = 'https://thinkingmachines.ai';
const listUrl = `${baseUrl}/news/`;

const response = await ofetch(listUrl);
const $ = load(response);

const items = $('main li a')
.toArray()
.map((el) => {
const $el = $(el);
const title = $el.find('.post-title').text().trim();
const dateStr = $el.find('time.desktop-time').text().trim();
const href = $el.attr('href') || '';
const link = href.startsWith('http') ? href : `${baseUrl}${href}`;

return { title, dateStr, link };
})
.filter((item) => item.title && item.link);

const fullItems = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
try {
const articleResponse = await ofetch(item.link);
const $article = load(articleResponse);

// Remove nav, footer, and other non-content elements
$article('nav, footer, header, script, style').remove();

const description = $article('main').html()?.trim() || $article('article').html()?.trim() || '';

return {
title: item.title,
link: item.link,
pubDate: parseDate(item.dateStr, 'MMM D, YYYY'),
description,
};
} catch {
return {
title: item.title,
link: item.link,
pubDate: parseDate(item.dateStr, 'MMM D, YYYY'),
description: '',
};
}
})
)
);

return {
title: 'Thinking Machines Lab - News',
link: listUrl,
item: fullItems,
};
}
Loading