From 5c6d0cd2014b82b7d408d72d746fd9dda14b3085 Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Mon, 27 Jun 2022 21:58:22 +0800
Subject: [PATCH] feat(route): add AppleInsider (#10040)
* feat(route): add AppleInsider
* fix: punctuation
---
docs/en/new-media.md | 12 +++++++
docs/new-media.md | 12 +++++++
lib/v2/appleinsider/index.js | 59 +++++++++++++++++++++++++++++++
lib/v2/appleinsider/maintainer.js | 3 ++
lib/v2/appleinsider/radar.js | 13 +++++++
lib/v2/appleinsider/router.js | 3 ++
6 files changed, 102 insertions(+)
create mode 100644 lib/v2/appleinsider/index.js
create mode 100644 lib/v2/appleinsider/maintainer.js
create mode 100644 lib/v2/appleinsider/radar.js
create mode 100644 lib/v2/appleinsider/router.js
diff --git a/docs/en/new-media.md b/docs/en/new-media.md
index d215209f1..a4ddea0f3 100644
--- a/docs/en/new-media.md
+++ b/docs/en/new-media.md
@@ -41,6 +41,18 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
+## AppleInsider
+
+### Category
+
+
+
+| News | Reviews | How-tos |
+| ---- | ------- | ------- |
+| | reviews | how-to |
+
+
+
## ASML Holding N.V.
### Press releases & announcements
diff --git a/docs/new-media.md b/docs/new-media.md
index abe5ba932..fc715f2ef 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -138,6 +138,18 @@ pageClass: routes
+## AppleInsider
+
+### 分类
+
+
+
+| News | Reviews | How-tos |
+| ---- | ------- | ------- |
+| | reviews | how-to |
+
+
+
## ASML 阿斯麦
### Press releases & announcements
diff --git a/lib/v2/appleinsider/index.js b/lib/v2/appleinsider/index.js
new file mode 100644
index 000000000..0f3812b48
--- /dev/null
+++ b/lib/v2/appleinsider/index.js
@@ -0,0 +1,59 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+
+module.exports = async (ctx) => {
+ const category = ctx.params.category ?? '';
+
+ const rootUrl = 'https://appleinsider.com';
+ const currentUrl = `${rootUrl}${category ? `/${category}` : ''}`;
+
+ const response = await got({
+ method: 'get',
+ url: currentUrl,
+ });
+
+ const $ = cheerio.load(response.data);
+
+ let items = $(`${category === '' ? '#news-river ' : ''}.river`)
+ .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 30)
+ .toArray()
+ .map((item) => {
+ item = $(item).find('a').first();
+
+ return {
+ title: item.text(),
+ link: item.attr('href'),
+ };
+ });
+
+ items = await Promise.all(
+ items.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got({
+ method: 'get',
+ url: item.link,
+ });
+
+ const content = cheerio.load(detailResponse.data);
+
+ content('#article-social').next().remove();
+ content('#article-hero, #article-social').remove();
+ content('.deals-widget').remove();
+
+ item.title = content('.h1-adjust').text();
+ item.author = content('.avatar-link a').attr('title');
+ item.pubDate = parseDate(content('time').first().attr('datetime'));
+ item.description = content('header').next('.row').html();
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: $('title').text(),
+ link: currentUrl,
+ item: items,
+ };
+};
diff --git a/lib/v2/appleinsider/maintainer.js b/lib/v2/appleinsider/maintainer.js
new file mode 100644
index 000000000..81eb78d73
--- /dev/null
+++ b/lib/v2/appleinsider/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/:category?': ['nczitzk'],
+};
diff --git a/lib/v2/appleinsider/radar.js b/lib/v2/appleinsider/radar.js
new file mode 100644
index 000000000..772734889
--- /dev/null
+++ b/lib/v2/appleinsider/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ 'appleinsider.com': {
+ _name: 'AppleInsider',
+ '.': [
+ {
+ title: '分类',
+ docs: 'https://docs.rsshub.app/new-media.html#appleinsider-fen-lei',
+ source: ['/:category', '/'],
+ target: '/appleinsider/:category',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/appleinsider/router.js b/lib/v2/appleinsider/router.js
new file mode 100644
index 000000000..cf781366f
--- /dev/null
+++ b/lib/v2/appleinsider/router.js
@@ -0,0 +1,3 @@
+module.exports = function (router) {
+ router.get('/:category?', require('./index'));
+};