fix(route): ollama library (#16002)

This commit is contained in:
gavrilov 2024-06-26 07:29:59 -07:00 committed by GitHub
parent 59f8bd4324
commit 9efe96bc88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseRelativeDate } from '@/utils/parse-date';
export const route: Route = {
path: '/library',
@ -12,23 +13,25 @@ export const route: Route = {
},
],
name: 'Models',
maintainers: ['Nick22nd'],
maintainers: ['Nick22nd', 'gavrilov'],
handler,
};
async function handler() {
const response = await ofetch('https://ollama.com/library');
const response = await ofetch('https://ollama.com/library?sort=newest');
const $ = load(response);
const items = $('#repo > ul > li > a')
.toArray()
.map((item) => {
const name = $(item).children('h2').first();
const name = $(item).find('h2 span').first();
const link = $(item).attr('href');
const description = $(item).children('p').first();
const description = $(item).find('div p.break-words').first();
const pubDate = $(item).find('span:contains("Updated")').first();
return {
title: name.text(),
link,
description: description.text(),
pubDate: parseRelativeDate(pubDate.text()),
};
});
return {