forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(routes/iplaysoft): use wp-api, add tag category routes (DIYgod#1…
…8332) * feat(routes/iplaysoft): use wp-api, add tag category routes * fix(routes/iplaysoft): change categories to 'program-update' * fix(routes/iplaysoft): fix index url * fix(routes/iplaysoft): use date_gmt ---------
- Loading branch information
Showing
5 changed files
with
160 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Data, DataItem, Route, ViewType } from '@/types'; | ||
import { fetchNewsItems, fetchCategory } from './utils'; | ||
|
||
export const handler = async (ctx): Promise<Data> => { | ||
const slug = ctx.req.param('slug'); | ||
|
||
const { id, name } = await fetchCategory(slug); | ||
|
||
const rootUrl = 'https://www.iplaysoft.com/'; | ||
const postApiUrl = `${rootUrl}wp-json/wp/v2/posts?_embed&categories=${id}`; | ||
|
||
const items: DataItem[] = await fetchNewsItems(postApiUrl); | ||
|
||
return { | ||
title: `${name} - 异次元软件世界`, | ||
description: '软件改变生活', | ||
language: 'zh-CN', | ||
link: `${rootUrl}category/${slug}`, | ||
item: items, | ||
}; | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/category/:slug', | ||
name: '分类', | ||
url: 'www.iplaysoft.com', | ||
maintainers: ['cscnk52'], | ||
handler, | ||
example: '/iplaysoft/category/system', | ||
parameters: { slug: '分类名称' }, | ||
description: undefined, | ||
categories: ['program-update'], | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportRadar: true, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.iplaysoft.com/category/:slug'], | ||
target: '/category/:slug', | ||
}, | ||
], | ||
view: ViewType.Articles, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,45 @@ | ||
import cache from '@/utils/cache'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { DataItem, Route } from '@/types'; | ||
import ofetch from '@/utils/ofetch'; | ||
import parser from '@/utils/rss-parser'; | ||
import { Data, DataItem, Route, ViewType } from '@/types'; | ||
import { fetchNewsItems } from './utils'; | ||
|
||
export const handler = async (): Promise<Data> => { | ||
const rootUrl = 'https://www.iplaysoft.com/'; | ||
const postApiUrl = `${rootUrl}wp-json/wp/v2/posts?_embed`; | ||
|
||
const items: DataItem[] = await fetchNewsItems(postApiUrl); | ||
|
||
return { | ||
title: '异次元软件世界', | ||
description: '软件改变生活', | ||
language: 'zh-CN', | ||
link: rootUrl, | ||
item: items, | ||
}; | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/', | ||
categories: ['program-update'], | ||
name: '首页', | ||
url: 'www.iplaysoft.com', | ||
maintainers: ['williamgateszhao', 'cscnk52'], | ||
handler, | ||
example: '/iplaysoft', | ||
parameters: {}, | ||
parameters: undefined, | ||
description: undefined, | ||
categories: ['program-update'], | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportRadar: true, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.iplaysoft.com'], | ||
target: '/', | ||
}, | ||
], | ||
name: '全部文章', | ||
maintainers: ['williamgateszhao'], | ||
handler, | ||
view: ViewType.Articles, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const feed = await parser.parseURL('https://www.iplaysoft.com/feed/atom'); | ||
const filteredItems = feed.items | ||
.filter((item) => item?.link && item?.pubDate && new URL(item.link).hostname.match(/.*\.iplaysoft\.com$/)) | ||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20) as DataItem[]; | ||
|
||
const items: DataItem[] = await Promise.all( | ||
filteredItems.map( | ||
(item) => | ||
cache.tryGet(item.link as string, async () => { | ||
const response = await ofetch(item.link as string); | ||
const $ = load(response); | ||
const content = $('.entry-content'); | ||
content | ||
.find('div') | ||
.filter((_index, element) => { | ||
const style = $(element).attr('style'); | ||
return style !== undefined && style.includes('overflow:hidden'); | ||
}) | ||
.remove(); | ||
return { | ||
title: item.title, | ||
description: content.html(), | ||
link: item.link, | ||
author: item.author, | ||
pubDate: parseDate(item.pubDate as string), | ||
} as DataItem; | ||
}) as Promise<DataItem> | ||
) | ||
); | ||
|
||
return { | ||
title: '异次元软件世界', | ||
link: 'https://www.iplaysoft.com', | ||
language: 'zh-CN', | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Data, DataItem, Route, ViewType } from '@/types'; | ||
import { fetchNewsItems, fetchTag } from './utils'; | ||
|
||
export const handler = async (ctx): Promise<Data> => { | ||
const slug = ctx.req.param('slug'); | ||
|
||
const { id, name } = await fetchTag(slug); | ||
|
||
const rootUrl = 'https://www.iplaysoft.com/'; | ||
const postApiUrl = `${rootUrl}wp-json/wp/v2/posts?_embed&tags=${id}`; | ||
|
||
const items: DataItem[] = await fetchNewsItems(postApiUrl); | ||
|
||
return { | ||
title: `${name} - 异次元软件世界`, | ||
description: '软件改变生活', | ||
language: 'zh-CN', | ||
link: `${rootUrl}tag/${slug}`, | ||
item: items, | ||
}; | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/tag/:slug', | ||
name: '标签', | ||
url: 'www.iplaysoft.com', | ||
maintainers: ['cscnk52'], | ||
handler, | ||
example: '/iplaysoft/tag/windows', | ||
parameters: { slug: '标签名称' }, | ||
description: undefined, | ||
categories: ['program-update'], | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportRadar: true, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.iplaysoft.com/tag/:slug'], | ||
target: '/tag/:slug', | ||
}, | ||
], | ||
view: ViewType.Articles, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ofetch from '@/utils/ofetch'; | ||
import cache from '@/utils/cache'; | ||
|
||
const rootUrl = 'https://www.iplaysoft.com/'; | ||
|
||
const fetchTaxonomy = async (slug: string, type: 'categories' | 'tags') => { | ||
const taxonomyUrl = `${rootUrl}wp-json/wp/v2/${type}?slug=${slug}`; | ||
const cachedTaxonomy = await cache.tryGet(taxonomyUrl, async () => { | ||
const taxonomyData = await ofetch(taxonomyUrl); | ||
if (!taxonomyData[0] || !taxonomyData[0].id || !taxonomyData[0].name) { | ||
throw new Error(`${type} ${slug} not found`); | ||
} | ||
return { id: taxonomyData[0].id, name: taxonomyData[0].name }; | ||
}); | ||
return cachedTaxonomy; | ||
}; | ||
|
||
const fetchCategory = async (categorySlug: string) => await fetchTaxonomy(categorySlug, 'categories'); | ||
const fetchTag = async (tagSlug: string) => await fetchTaxonomy(tagSlug, 'tags'); | ||
|
||
async function fetchNewsItems(apiUrl: string) { | ||
const data = await ofetch(apiUrl); | ||
|
||
return data.map((item) => ({ | ||
title: item.title.rendered, | ||
description: item.content.rendered, | ||
link: item.link, | ||
pubDate: new Date(item.date_gmt).toUTCString(), | ||
author: item._embedded.author[0].name, | ||
category: item._embedded['wp:term'].flat().map((term) => term.name), | ||
})); | ||
} | ||
|
||
export { fetchCategory, fetchTag, fetchNewsItems }; |