mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-30 16:55:08 +08:00
+1
-1
@@ -33,7 +33,7 @@ pageClass: routes
|
||||
|
||||
### 更换和维修扩展计划
|
||||
|
||||
<Route author="metowolf HenryQW" example="/apple/exchange_repair" path="/apple/exchange_repair/:country?" :paramsDesc="['苹果官网 URL 中的国家代码, 默认中国 `cn`']"/>
|
||||
<Route author="metowolf HenryQW kt286" example="/apple/exchange_repair/zh-cn" path="/apple/exchange_repair/:country?" :paramsDesc="['苹果官网 URL 中的国家代码, 默认美国 ,中国 `zh-cn`']"/>
|
||||
|
||||
### App Store/Mac App Store
|
||||
|
||||
|
||||
@@ -2,59 +2,36 @@ const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
|
||||
const host = 'https://www.apple.com/';
|
||||
const host = 'https://support.apple.com/';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let link;
|
||||
|
||||
if (!ctx.params.country) {
|
||||
ctx.params.country = 'cn';
|
||||
}
|
||||
|
||||
ctx.params.country === 'us' ? (link = url.resolve(host, '/support/exchange_repair/')) : (link = url.resolve(host, `${ctx.params.country}/support/exchange_repair/`));
|
||||
const country = ctx.params.country || '';
|
||||
const link = url.resolve(host, `${country}/exchange_repair/`);
|
||||
|
||||
const response = await got.get(link);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('tr td a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
|
||||
const titlelist = $('tr td a')
|
||||
.map((i, e) => $(e).text())
|
||||
.get();
|
||||
|
||||
// const datelist = $('tr td p')
|
||||
// .map((i, e) =>
|
||||
// $(e)
|
||||
// .text()
|
||||
// .trim()
|
||||
// )
|
||||
// .get();
|
||||
const list = $('section.as-columns').get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (itemUrl, index) => {
|
||||
itemUrl = url.resolve(host, itemUrl);
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
const $a = $('.icon-chevronright').parent();
|
||||
const itemUrl = url.resolve(host, $a.attr('href'));
|
||||
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got.get(itemUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const description = $('#welcome').html()
|
||||
? $('#welcome')
|
||||
.html()
|
||||
.replace(/src="\//g, `src="${url.resolve(host, '.')}`)
|
||||
: null;
|
||||
const $$ = cheerio.load(response.data);
|
||||
const description = $$('.main').html();
|
||||
|
||||
const single = {
|
||||
title: titlelist[index],
|
||||
title: $a.text(),
|
||||
link: itemUrl,
|
||||
author: 'Apple Inc.',
|
||||
description: description,
|
||||
// pubDate: new Date(datelist[index].replace(/(\d+) 年 (\d+) 月 (\d+) 日/, '$1-$2-$3')).toISOString(),
|
||||
};
|
||||
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single));
|
||||
@@ -62,10 +39,8 @@ module.exports = async (ctx) => {
|
||||
})
|
||||
);
|
||||
|
||||
const title = ctx.params.country === 'cn' ? 'Apple 支持 -- 更换和维修扩展计划' : `Apple ${ctx.params.country.toUpperCase()} Support -- Exchange and Repair Extension Programs`;
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
title: `Apple --- ${$('.main>.richText h1').text()}`,
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user