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 #1373 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
28 changed files
with
517 additions
and
123 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
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
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,5 +1,5 @@ | ||
{{ if videoInfo.mobileUrl }} | ||
<video controls poster="{{ videoInfo.bigPosterUrl }}" preload="none"> | ||
<video controls poster="{{ videoInfo.bigPosterUrl }}" preload="metadata"> | ||
<source src="{{ videoInfo.mobileUrl }}" type="video/mp4"> | ||
</video> | ||
{{ /if }} |
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,13 @@ | ||
{{ if images }} | ||
{{ each images image }} | ||
{{ if image?.src }} | ||
<figure> | ||
<img | ||
{{ if image.alt }} | ||
alt="{{ image.alt }}" | ||
{{ /if }} | ||
src="{{ image.src }}"> | ||
</figure> | ||
{{ /if }} | ||
{{ /each }} | ||
{{ /if }} |
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,88 +1,150 @@ | ||
import { Route } from '@/types'; | ||
import { getCurrentPath } from '@/utils/helpers'; | ||
const __dirname = getCurrentPath(import.meta.url); | ||
|
||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import timezone from '@/utils/timezone'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { art } from '@/utils/render'; | ||
import path from 'node:path'; | ||
|
||
export const route: Route = { | ||
path: '/zt/:id', | ||
categories: ['new-media'], | ||
example: '/ithome/zt/xijiayi', | ||
parameters: { id: '专题 id' }, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['ithome.com/zt/:id'], | ||
}, | ||
], | ||
name: '专题', | ||
maintainers: ['nczitzk'], | ||
handler, | ||
description: `所有专题请见[此处](https://www.ithome.com/zt)`, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const id = ctx.req.param('id'); | ||
export const handler = async (ctx) => { | ||
const { id = 'xijiayi' } = ctx.req.param(); | ||
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 50; | ||
|
||
const rootUrl = 'https://www.ithome.com'; | ||
const currentUrl = `${rootUrl}/zt/${id}`; | ||
const currentUrl = new URL(`zt/${id}`, rootUrl).href; | ||
|
||
const { data: response } = await got(currentUrl); | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
}); | ||
const $ = load(response); | ||
|
||
const $ = load(response.data); | ||
const author = 'IT之家'; | ||
const language = 'zh'; | ||
|
||
const list = $('.newsbody a') | ||
.map((_, item) => { | ||
let items = $('div.newsbody') | ||
.slice(0, limit) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
const title = item.find('h2').text(); | ||
const image = item.find('img').prop('data-original') ?? item.find('img').prop('src'); | ||
|
||
return { | ||
title: item.text(), | ||
link: item.attr('href'), | ||
title, | ||
pubDate: timezone( | ||
parseDate( | ||
item | ||
.find('span.time script') | ||
.text() | ||
.match(/'(.*?)'/) | ||
), | ||
+8 | ||
), | ||
link: item.find('a').first().prop('href'), | ||
author: item.find('div.editor').contents().first().text(), | ||
image, | ||
banner: image, | ||
language, | ||
}; | ||
}) | ||
.get(); | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
items = await Promise.all( | ||
items.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
const { data: detailResponse } = await got(item.link); | ||
|
||
const $$ = load(detailResponse); | ||
|
||
$$('p.ad-tips, a.topic-bar').remove(); | ||
|
||
const content = load(detailResponse.data); | ||
const post = content('.post_content'); | ||
$$('div#paragraph p img').each((_, el) => { | ||
el = $$(el); | ||
|
||
post.find('img[data-original]').each((_, ele) => { | ||
ele = $(ele); | ||
ele.attr('src', ele.attr('data-original')); | ||
ele.removeAttr('class'); | ||
ele.removeAttr('data-original'); | ||
const src = el.prop('data-original'); | ||
|
||
if (src) { | ||
el.replaceWith( | ||
art(path.join(__dirname, 'templates/description.art'), { | ||
images: [ | ||
{ | ||
src, | ||
alt: el.prop('alt'), | ||
}, | ||
], | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
item.description = post.html(); | ||
item.author = content('#author_baidu').text().replace('作者:', ''); | ||
item.pubDate = timezone(parseDate(content('#pubtime_baidu').text()), +8); | ||
const title = $$('h1').text(); | ||
const description = $$('div#paragraph').html(); | ||
const image = $$('div#paragraph img').first().prop('src'); | ||
|
||
item.title = title; | ||
item.description = description; | ||
item.pubDate = timezone(parseDate($$('span#pubtime_baidu').text()), +8); | ||
item.category = $$('div.cv a') | ||
.toArray() | ||
.map((c) => $$(c).text()) | ||
.slice(1); | ||
item.author = $$('span#author_baidu').contents().last().text() || $$('span#source_baidu').contents().last().text() || $$('span#editor_baidu').contents().last().text(); | ||
item.content = { | ||
html: description, | ||
text: $$('div#paragraph').text(), | ||
}; | ||
item.image = image; | ||
item.banner = image; | ||
item.language = language; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const image = new URL($('meta[property="og:image"]').prop('content'), rootUrl).href; | ||
|
||
return { | ||
title: `${$('title').text()} - IT之家`, | ||
title: `${author} - ${$('title').text()}`, | ||
description: $('meta[name="description"]').prop('content'), | ||
link: currentUrl, | ||
item: items, | ||
allowEmpty: true, | ||
image, | ||
author, | ||
language, | ||
}; | ||
} | ||
}; | ||
|
||
export const route: Route = { | ||
path: '/zt/:id?', | ||
name: '专题', | ||
url: 'ithome.com', | ||
maintainers: ['nczitzk'], | ||
handler, | ||
example: '/ithome/zt/xijiayi', | ||
parameters: { category: '专题 id,默认为 xijiayi,即 [喜加一](https://www.ithome.com/zt/xijiayi),可在对应专题页 URL 中找到' }, | ||
description: `:::tip | ||
更多专题请见 [IT之家专题](https://www.ithome.com/zt) | ||
:::`, | ||
categories: ['new-media'], | ||
|
||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportRadar: true, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['ithome.com/zt/:id'], | ||
target: '/zt/:id', | ||
}, | ||
], | ||
}; |
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
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,63 @@ | ||
import { Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import parser from '@/utils/rss-parser'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { load } from 'cheerio'; | ||
const host = 'https://www.magnumphotos.com'; | ||
export const route: Route = { | ||
path: '/magazine', | ||
categories: ['picture'], | ||
example: '/magnumphotos/magazine', | ||
parameters: {}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['magnumphotos.com/'], | ||
}, | ||
], | ||
name: 'Magazine', | ||
maintainers: ['EthanWng97'], | ||
handler, | ||
url: 'magnumphotos.com/', | ||
}; | ||
|
||
async function handler() { | ||
const rssUrl = `${host}/feed/`; | ||
const feed = await parser.parseURL(rssUrl); | ||
const items = await Promise.all( | ||
feed.items.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
if (!item.link) { | ||
return; | ||
} | ||
const data = await ofetch(item.link); | ||
const $ = load(data); | ||
const description = $('#content'); | ||
description.find('ul.share').remove(); | ||
description.find('h1').remove(); | ||
|
||
return { | ||
title: item.title, | ||
pubDate: item.pubDate, | ||
link: item.link, | ||
category: item.categories, | ||
description: description.html(), | ||
}; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: 'Magnum Photos', | ||
link: host, | ||
description: 'Magnum is a community of thought, a shared human quality, a curiosity about what is going on in the world, a respect for what is going on and a desire to transcribe it visually', | ||
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,6 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'Magnum Photos', | ||
url: 'magnumphotos.com', | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<video controls preload="none" poster="{{ poster }}"> | ||
<video controls preload="metadata" poster="{{ poster }}"> | ||
<source src="{{ video }}" type="{{ type }}"> | ||
</video> |
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
Oops, something went wrong.