From 55a0ececb49c794273456b5e3bc4ab8f9eadcbb6 Mon Sep 17 00:00:00 2001
From: Hualiang <78242797+hualiong@users.noreply.github.com>
Date: Sat, 22 Jun 2024 03:12:17 +0800
Subject: [PATCH] feat(route): Add Kelowna Capital News (#15945)
* feat(route): Add Kelowna Capital News
* add news
* add more type
* add title
* update
* take all images
* add caption
* fix...
---
lib/routes/kelownacapnews/namespace.ts | 6 ++
lib/routes/kelownacapnews/news.ts | 93 ++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
create mode 100644 lib/routes/kelownacapnews/namespace.ts
create mode 100644 lib/routes/kelownacapnews/news.ts
diff --git a/lib/routes/kelownacapnews/namespace.ts b/lib/routes/kelownacapnews/namespace.ts
new file mode 100644
index 000000000..ef2039a96
--- /dev/null
+++ b/lib/routes/kelownacapnews/namespace.ts
@@ -0,0 +1,6 @@
+import type { Namespace } from '@/types';
+
+export const namespace: Namespace = {
+ name: 'Kelowna Capital News',
+ url: 'www.kelownacapnews.com',
+};
diff --git a/lib/routes/kelownacapnews/news.ts b/lib/routes/kelownacapnews/news.ts
new file mode 100644
index 000000000..71b1d680c
--- /dev/null
+++ b/lib/routes/kelownacapnews/news.ts
@@ -0,0 +1,93 @@
+import { DataItem, Route } from '@/types';
+import ofetch from '@/utils/ofetch';
+import { load } from 'cheerio';
+import cache from '@/utils/cache';
+import { parseDate } from '@/utils/parse-date';
+
+export const route: Route = {
+ path: '/:type',
+ categories: ['new-media'],
+ example: '/kelownacapnews/local-news',
+ parameters: { type: 'Type of news' },
+ features: {
+ requireConfig: false,
+ requirePuppeteer: false,
+ antiCrawler: false,
+ supportBT: false,
+ supportPodcast: false,
+ supportScihub: false,
+ },
+ radar: [
+ {
+ source: ['www.kelownacapnews.com/:type'],
+ target: '/:type',
+ },
+ ],
+ name: 'News',
+ maintainers: ['hualiong'],
+ url: 'www.kelownacapnews.com',
+ description: `\`type\` is as follows:
+
+| News type | Value | News type | Value |
+| ------------- | ------------- | ------------ | ------------ |
+| News | news | Sports | sports |
+| Local News | local-news | Business | business |
+| Canadian News | national-news | Trending Now | trending-now |
+| World News | world-news | Opinion | opinion |
+| Entertainment | entertainment | | |`,
+ handler: async (ctx) => {
+ const type = ctx.req.param('type');
+ const baseURL = 'https://www.kelownacapnews.com';
+
+ const response = await ofetch(`${baseURL}/${type}`);
+ const $ = load(response);
+
+ const list = $('.media')
+ .toArray()
+ .map((item): DataItem => {
+ const a = $(item);
+ return {
+ title: a.find('.media-heading').text(),
+ pubDate: parseDate(a.find('.media-links time').attr('datetime')!),
+ link: baseURL + a.attr('href'),
+ };
+ });
+
+ const items = await Promise.all(
+ list.map((item) =>
+ cache.tryGet(item.link!, async () => {
+ const response = await ofetch(item.link!);
+ const $ = load(response);
+
+ let image = $('.details-file')!;
+ if (!image.length) {
+ image = $('#sliderImgs .tablist-item .galleryWrap');
+ }
+ const byline = $('.details-byline');
+ const profileTitle = byline.find('.profile-title');
+ if (profileTitle.length) {
+ item.author = profileTitle.find('a').text();
+ }
+ let label = '';
+ if (image.length > 1) {
+ for (const e of image.toArray()) {
+ const img = $(e);
+ label += `
${img.attr('title')}`;
+ }
+ } else {
+ label = `${image.html()!}`;
+ }
+ item.description = label + $('.details-body').html()!;
+
+ return item;
+ })
+ )
+ );
+
+ return {
+ title: `${$('.body-title').text()} - Kelowna Capital News`,
+ link: `${baseURL}/${type}`,
+ item: items as DataItem[],
+ };
+ },
+};