Skip to content

Commit

Permalink
fix(routes/whitehouse): new theme (#18185)
Browse files Browse the repository at this point in the history
* fix(routes/whitehouse): new theme

* fix(routes/whitehouse): remove OSTP
  • Loading branch information
hkamran80 authored Jan 24, 2025
1 parent ef06603 commit bb9c804
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 155 deletions.
79 changes: 0 additions & 79 deletions lib/routes/whitehouse/briefing-room.ts

This file was deleted.

82 changes: 82 additions & 0 deletions lib/routes/whitehouse/news.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/news/:category?',
categories: ['government'],
example: '/whitehouse/news',
parameters: { category: 'Category, see below, all by default' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['whitehouse.gov/:category', 'whitehouse.gov/'],
target: '/news/:category',
},
],
name: 'News',
maintainers: ['nczitzk', 'hkamran80'],
handler,
description: `| All | Articles | Briefings and Statements | Presidential Actions | Remarks |
| --- | -------- | ------------------------ | -------------------- | ------- |
| | articles | briefings-statements | presidential-actions | remarks |`,
};

async function handler(ctx) {
const category = ctx.req.param('category') ?? 'news';

const rootUrl = 'https://www.whitehouse.gov';
const currentUrl = `${rootUrl}/${category}/`;
const response = await got({
method: 'get',
url: currentUrl,
});

const $ = load(response.data);

const list = $('.post')
.toArray()
.map((item) => {
item = $(item);

const a = item.find('a').first();
return {
title: a.text(),
link: a.attr('href'),
pubDate: parseDate(item.find('time').attr('datetime')),
category: [item.find('a[rel^=tag]').first().text()],
};
});

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const response = await got({
method: 'get',
url: item.link,
});
const $ = load(response.data);

$('.wp-block-whitehouse-topper').remove();
item.description = $('.entry-content').html();

return item;
})
)
);

return {
title: $('title').text(),
link: currentUrl,
item: items,
};
}
76 changes: 0 additions & 76 deletions lib/routes/whitehouse/ostp.ts

This file was deleted.

0 comments on commit bb9c804

Please sign in to comment.