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.
Merge pull request #331 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
6 changed files
with
164 additions
and
13 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
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,71 @@ | ||
import { Route } from '@/types'; | ||
import got from '@/utils/got'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
|
||
const PATH_LIST = { | ||
早报: 'ifanrnews', | ||
评测: 'review', | ||
糖纸众测: 'tangzhi-evaluation', | ||
产品: 'product', | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/category/:name', | ||
categories: ['new-media'], | ||
example: '/ifanr/category/早报', | ||
parameters: { name: '分类名称' }, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: true, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.ifanr.com/category/:name'], | ||
}, | ||
], | ||
name: '分类', | ||
maintainers: ['donghongfei'], | ||
handler, | ||
description: `支持分类:早报、评测、糖纸众测、产品`, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const name = ctx.req.param('name'); | ||
const nameEncode = encodeURIComponent(decodeURIComponent(name)); | ||
const apiUrl = `https://sso.ifanr.com/api/v5/wp/article/?post_category=${nameEncode}&limit=20&offset=0`; | ||
const resp = await got({ | ||
method: 'get', | ||
url: apiUrl, | ||
}); | ||
const items = await Promise.all( | ||
resp.data.objects.map((item) => { | ||
let description = ''; | ||
|
||
const banner = item.post_cover_image; | ||
|
||
if (banner) { | ||
description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`; | ||
} | ||
description += item.post_content; | ||
|
||
return { | ||
title: item.post_title.trim(), | ||
description, | ||
link: item.post_url, | ||
pubDate: parseDate(item.published_at * 1000), | ||
author: item.created_by.name, | ||
}; | ||
}) | ||
); | ||
|
||
return { | ||
title: `#${name} - iFanr 爱范儿`, | ||
link: `https://www.ifanr.com/category/${PATH_LIST[name]}`, | ||
description: `${name} 更新推送`, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Route, ViewType } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
|
||
export const route: Route = { | ||
path: '/index', | ||
categories: ['new-media'], | ||
view: ViewType.Articles, | ||
example: '/ifanr/index', | ||
parameters: {}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['www.ifanr.com/index'], | ||
}, | ||
], | ||
name: '首页', | ||
maintainers: ['donghongfei'], | ||
handler, | ||
url: 'www.ifanr.com/index', | ||
}; | ||
|
||
async function handler() { | ||
const apiUrl = 'https://sso.ifanr.com/api/v5/wp/web-feed/?limit=20&offset=0'; | ||
const resp = await got({ | ||
method: 'get', | ||
url: apiUrl, | ||
}); | ||
const items = await Promise.all( | ||
resp.data.objects.map((item) => { | ||
const link = `https://sso.ifanr.com/api/v5/wp/article/?post_id=${item.post_id}`; | ||
let description = ''; | ||
|
||
const key = `ifanr:${item.id}`; | ||
|
||
return cache.tryGet(key, async () => { | ||
const response = await got({ method: 'get', url: link }); | ||
const articleData = response.data.objects[0]; | ||
const banner = articleData.post_cover_image; | ||
if (banner) { | ||
description = `<img src="${banner}" alt="Article Cover Image" style="display: block; margin: 0 auto;"><br>`; | ||
} | ||
description += articleData.post_content; | ||
|
||
return { | ||
title: item.post_title.trim(), | ||
description, | ||
link: item.post_url, | ||
pubDate: parseDate(item.created_at * 1000), | ||
author: item.created_by.name, | ||
}; | ||
}); | ||
}) | ||
); | ||
|
||
return { | ||
title: '爱范儿', | ||
link: 'https://www.ifanr.com', | ||
description: '爱范儿首页', | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: '爱范儿', | ||
url: 'www.ifanr.com', | ||
description: '', | ||
lang: 'zh-CN', | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.