Files
RSSHub/lib/routes/google/developers.ts
T
Tony 5527d18de9 refactor: remove unnecessary trim/first/last (#22837)
* refactor: remove unnecessary trim/first/last

* refactor(types): allow null in DataItem.description

* refactor: remove unnecessary fallback

* refactor(types): allow null in Data.description

* refactor: remove unnecessary fallback

* refactor: remove .clone()

* refactor: refine json content text

* fIx: cognition

* fix: more fixes

* fix(route/jiemian): use api

* fix(route/jandan): housekeeping

add back maintainers from #8904

* fix(route/kcna/news): update source and target mappings

* fix(route/jandan): sanitize HTML content in titles

* refactor: remove unnecessary referer

* fix(route/jinse): regex
2026-07-27 22:23:57 +08:00

73 lines
2.2 KiB
TypeScript

import { load } from 'cheerio';
import type { Context } from 'hono';
import type { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
const baseUrl = 'https://developers.googleblog.com';
export const route: Route = {
path: '/developers/:locale?',
name: 'Developers Blog',
url: 'developers.googleblog.com',
maintainers: ['Loongphy'],
handler,
example: '/google/developers/en',
parameters: {
locale: {
description: 'language',
default: 'en',
options: [
{ value: 'en', label: 'English' },
{ value: 'es', label: 'Español (Latam)' },
{ value: 'id', label: 'Bahasa Indonesia' },
{ value: 'ja', label: '日本語' },
{ value: 'ko', label: '한국어' },
{ value: 'pt-br', label: 'Português (Brasil)' },
{ value: 'zh-hans', label: '简体中文' },
],
},
},
description: 'Google Developers Blog',
categories: ['blog'],
radar: [
{
source: ['developers.googleblog.com'],
},
],
};
async function handler(ctx: Context) {
const locale = ctx.req.param('locale') ?? 'en';
const response = await ofetch(`${baseUrl}/${locale}/search`);
const $ = load(response);
const items = $('.search-result')
.toArray()
.map((element) => {
const dateCategory = $(element).find('.search-result__eyebrow').text();
const [date, category] = dateCategory.split(' / ', 2);
const titleElement = $(element).find('.search-result__title a');
const title = titleElement.text();
const link = titleElement.attr('href');
const summary = $(element).find('.search-result__summary').text();
return {
title,
link: `${baseUrl}${link}`,
pubDate: parseDate(date),
description: summary,
author: 'Google',
category: [category],
};
});
return {
title: 'Google Developers Blog',
link: baseUrl,
item: items,
};
}