rsshub 1.0.0-master.f6cb490 → 1.0.0-master.f6f0273
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/index.ts +1 -6
- package/lib/routes/2048/index.ts +24 -23
- package/lib/routes/anthropic/news.ts +27 -13
- package/lib/routes/asianfanfics/namespace.ts +7 -0
- package/lib/routes/asianfanfics/tag.ts +89 -0
- package/lib/routes/asianfanfics/text-search.ts +68 -0
- package/lib/routes/blockworks/index.ts +128 -0
- package/lib/routes/blockworks/namespace.ts +7 -0
- package/lib/routes/cmu/andypavlo/blog.ts +55 -0
- package/lib/routes/cmu/namespace.ts +7 -0
- package/lib/routes/coindesk/{index.ts → consensus-magazine.ts} +17 -21
- package/lib/routes/coindesk/namespace.ts +2 -1
- package/lib/routes/coindesk/news.ts +47 -0
- package/lib/routes/coindesk/utils.ts +26 -0
- package/lib/routes/cointelegraph/index.ts +106 -0
- package/lib/routes/cointelegraph/namespace.ts +7 -0
- package/lib/routes/collabo-cafe/category.ts +37 -0
- package/lib/routes/collabo-cafe/index.ts +35 -0
- package/lib/routes/collabo-cafe/namespace.ts +9 -0
- package/lib/routes/collabo-cafe/parser.ts +29 -0
- package/lib/routes/collabo-cafe/tag.ts +37 -0
- package/lib/routes/cryptoslate/index.ts +98 -0
- package/lib/routes/cryptoslate/namespace.ts +7 -0
- package/lib/routes/decrypt/index.ts +115 -0
- package/lib/routes/decrypt/namespace.ts +7 -0
- package/lib/routes/discuz/discuz.ts +7 -9
- package/lib/routes/fangchan/list.ts +224 -0
- package/lib/routes/fangchan/namespace.ts +9 -0
- package/lib/routes/fangchan/templates/description.art +7 -0
- package/lib/routes/foreignaffairs/namespace.ts +7 -0
- package/lib/routes/foreignaffairs/rss.ts +55 -0
- package/lib/routes/forklog/index.ts +72 -0
- package/lib/routes/forklog/namespace.ts +7 -0
- package/lib/routes/gcores/categories.ts +129 -0
- package/lib/routes/gcores/collections.ts +129 -0
- package/lib/routes/gcores/topics.ts +63 -0
- package/lib/routes/gov/moa/gjs.ts +210 -0
- package/lib/routes/gov/tianjin/tjftz.ts +53 -0
- package/lib/routes/gov/tianjin/tjrcgzw.ts +51 -0
- package/lib/routes/grainoil/category.ts +207 -0
- package/lib/routes/grainoil/namespace.ts +9 -0
- package/lib/routes/huxiu/util.ts +11 -9
- package/lib/routes/ifanr/category.ts +7 -2
- package/lib/routes/ifanr/digest.ts +1 -1
- package/lib/routes/ifanr/index.ts +1 -1
- package/lib/routes/instructables/projects.ts +20 -15
- package/lib/routes/juejin/collections.ts +1 -1
- package/lib/routes/komiic/comic.ts +88 -0
- package/lib/routes/komiic/namespace.ts +7 -0
- package/lib/routes/leagueoflegends/namespace.ts +8 -0
- package/lib/routes/leagueoflegends/patch-notes.ts +76 -0
- package/lib/routes/likeshop/index.ts +43 -0
- package/lib/routes/likeshop/namespace.ts +7 -0
- package/lib/routes/ltaaa/article.ts +180 -0
- package/lib/routes/ltaaa/namespace.ts +9 -0
- package/lib/routes/ltaaa/templates/description.art +7 -0
- package/lib/routes/mashiro/index.ts +1 -0
- package/lib/routes/nhentai/util.ts +4 -1
- package/lib/routes/pinterest/user.ts +9 -0
- package/lib/routes/sohu/mp.ts +3 -2
- package/lib/routes/spotify/show.ts +1 -1
- package/lib/routes/stcn/index.ts +241 -136
- package/lib/routes/stcn/kx.ts +144 -0
- package/lib/routes/swjtu/namespace.ts +1 -1
- package/lib/routes/swjtu/{scai/bks.ts → scai.ts} +34 -20
- package/lib/routes/swjtu/sports.ts +77 -0
- package/lib/routes/theblock/index.ts +142 -0
- package/lib/routes/theblock/namespace.ts +7 -0
- package/lib/routes/theverge/index.ts +73 -62
- package/lib/routes/theverge/templates/header.art +19 -0
- package/lib/routes/threads/index.ts +73 -54
- package/lib/routes/threads/utils.ts +60 -78
- package/lib/routes/tmtpost/column.ts +298 -0
- package/lib/routes/tmtpost/new.ts +4 -199
- package/lib/routes/tmtpost/util.ts +207 -0
- package/lib/routes/toranoana/namespace.ts +7 -0
- package/lib/routes/toranoana/news.ts +110 -0
- package/lib/routes/wainao/templates/description.art +9 -0
- package/lib/routes/wainao/topics.ts +214 -0
- package/lib/routes/xiaoyuzhou/podcast.ts +27 -27
- package/lib/routes/xjtu/yz.ts +74 -0
- package/lib/routes/youmemark/index.ts +6 -6
- package/lib/routes/zaobao/util.ts +11 -3
- package/lib/routes/zhihu/answers.ts +26 -54
- package/package.json +36 -35
- package/lib/routes/gcores/category.ts +0 -171
- package/lib/routes/gcores/collection.ts +0 -161
- package/lib/routes-deprecated/ltaaa/index.js +0 -69
|
@@ -1,211 +1,16 @@
|
|
|
1
|
-
import { type Data, type
|
|
1
|
+
import { type Data, type Route, ViewType } from '@/types';
|
|
2
2
|
|
|
3
|
-
import { art } from '@/utils/render';
|
|
4
|
-
import cache from '@/utils/cache';
|
|
5
|
-
import { getCurrentPath } from '@/utils/helpers';
|
|
6
|
-
import ofetch from '@/utils/ofetch';
|
|
7
|
-
import { parseDate } from '@/utils/parse-date';
|
|
8
|
-
|
|
9
|
-
import { type CheerioAPI, load } from 'cheerio';
|
|
10
3
|
import { type Context } from 'hono';
|
|
11
|
-
import path from 'node:path';
|
|
12
4
|
|
|
13
|
-
|
|
5
|
+
import { baseUrl, apiBaseUrl, processItems } from './util';
|
|
14
6
|
|
|
15
7
|
export const handler = async (ctx: Context): Promise<Data> => {
|
|
16
|
-
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '
|
|
8
|
+
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '30', 10);
|
|
17
9
|
|
|
18
|
-
const baseUrl: string = 'https://www.tmtpost.com';
|
|
19
|
-
const apiBaseUrl: string = 'https://api.tmtpost.com';
|
|
20
10
|
const targetUrl: string = new URL('new', baseUrl).href;
|
|
21
11
|
const listApiUrl: string = new URL('v1/lists/new', apiBaseUrl).href;
|
|
22
|
-
const postApiUrl: string = new URL('v1/posts/', apiBaseUrl).href;
|
|
23
|
-
|
|
24
|
-
const headers = {
|
|
25
|
-
'app-version': 'web1.0',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const response = await ofetch(listApiUrl, {
|
|
29
|
-
query: {
|
|
30
|
-
limit,
|
|
31
|
-
},
|
|
32
|
-
headers,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const targetResponse = await ofetch(targetUrl);
|
|
36
|
-
const $: CheerioAPI = load(targetResponse);
|
|
37
|
-
const language = $('html').attr('lang') ?? 'zh-CN';
|
|
38
|
-
|
|
39
|
-
let items: DataItem[] = [];
|
|
40
|
-
|
|
41
|
-
items = response.data.slice(0, limit).map((item): DataItem => {
|
|
42
|
-
const title: string = item.title;
|
|
43
|
-
const description: string = art(path.join(__dirname, 'templates/description.art'), {
|
|
44
|
-
intro: item.summary,
|
|
45
|
-
});
|
|
46
|
-
const pubDate: number | string = item.time_published;
|
|
47
|
-
const linkUrl: string | undefined = item.share_link;
|
|
48
|
-
const guid: string = item.guid;
|
|
49
|
-
const image: string | undefined = item.thumb_image?.original?.url;
|
|
50
|
-
const updated: number | string = item.updated ?? pubDate;
|
|
51
|
-
|
|
52
|
-
const processedItem: DataItem = {
|
|
53
|
-
title,
|
|
54
|
-
description,
|
|
55
|
-
pubDate: pubDate ? parseDate(pubDate, 'X') : undefined,
|
|
56
|
-
link: linkUrl,
|
|
57
|
-
guid,
|
|
58
|
-
id: guid,
|
|
59
|
-
content: {
|
|
60
|
-
html: description,
|
|
61
|
-
text: item.content ?? description,
|
|
62
|
-
},
|
|
63
|
-
image,
|
|
64
|
-
banner: image,
|
|
65
|
-
updated: updated ? parseDate(updated, 'X') : undefined,
|
|
66
|
-
language,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return processedItem;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
items = (
|
|
73
|
-
await Promise.all(
|
|
74
|
-
items.map((item) => {
|
|
75
|
-
if (!item.link) {
|
|
76
|
-
return item;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return cache.tryGet(item.link, async (): Promise<DataItem> => {
|
|
80
|
-
const apiUrl: string = new URL(item.guid as string, postApiUrl).href;
|
|
81
|
-
|
|
82
|
-
const detailResponse = await ofetch(apiUrl, {
|
|
83
|
-
query: {
|
|
84
|
-
fields: ['authors', 'tags', 'featured_image', 'categories', 'stock_list', 'big_plate', 'concept_plate', 'plate', 'plate_list', 'share_link'].join(';'),
|
|
85
|
-
},
|
|
86
|
-
headers,
|
|
87
|
-
});
|
|
88
|
-
const data = detailResponse.data;
|
|
89
|
-
|
|
90
|
-
if (!data) {
|
|
91
|
-
return item;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const title: string = data.title;
|
|
95
|
-
const description: string = art(path.join(__dirname, 'templates/description.art'), {
|
|
96
|
-
intro: data.summary,
|
|
97
|
-
description: data.main,
|
|
98
|
-
});
|
|
99
|
-
const pubDate: number | string = data.time_published;
|
|
100
|
-
const linkUrl: string | undefined = data.share_link;
|
|
101
|
-
const categories: string[] = [
|
|
102
|
-
...new Set(
|
|
103
|
-
(
|
|
104
|
-
[...(data.categories ?? []), ...(data.stock_list ?? []), ...(data.big_plate ?? []), ...(data.concept_plate ?? []), ...(data.plate ?? []), ...(data.plate_list ?? []), ...(data.tags ?? [])].map(
|
|
105
|
-
(c) => c.title ?? c.name ?? c.tag
|
|
106
|
-
) as string[]
|
|
107
|
-
).filter(Boolean)
|
|
108
|
-
),
|
|
109
|
-
];
|
|
110
|
-
const authors: DataItem['author'] = data.authors?.map((author) => ({
|
|
111
|
-
name: author.username,
|
|
112
|
-
url: new URL(`user/${author.guid}`, baseUrl).href,
|
|
113
|
-
avatar: author.avatar,
|
|
114
|
-
}));
|
|
115
|
-
const guid: string = `tmtpost-${data.post_guid}`;
|
|
116
|
-
const image: string | undefined = data.images?.[0]?.url;
|
|
117
|
-
const updated: number | string = data.time_updated;
|
|
118
|
-
|
|
119
|
-
let processedItem: DataItem = {
|
|
120
|
-
title,
|
|
121
|
-
description,
|
|
122
|
-
pubDate: pubDate ? parseDate(pubDate, 'X') : undefined,
|
|
123
|
-
link: linkUrl ?? item.link,
|
|
124
|
-
category: categories,
|
|
125
|
-
author: authors,
|
|
126
|
-
guid,
|
|
127
|
-
id: guid,
|
|
128
|
-
content: {
|
|
129
|
-
html: description,
|
|
130
|
-
text: description,
|
|
131
|
-
},
|
|
132
|
-
image,
|
|
133
|
-
banner: image,
|
|
134
|
-
updated: updated ? parseDate(updated, 'X') : undefined,
|
|
135
|
-
language,
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const enclosureUrl: string | undefined = data.audio;
|
|
139
|
-
|
|
140
|
-
if (enclosureUrl) {
|
|
141
|
-
const enclosureType: string = `audio/${enclosureUrl.split(/\./).pop()}`;
|
|
142
|
-
const itunesDuration: string | number | undefined = data.duration;
|
|
143
|
-
|
|
144
|
-
processedItem = {
|
|
145
|
-
...processedItem,
|
|
146
|
-
enclosure_url: enclosureUrl,
|
|
147
|
-
enclosure_type: enclosureType,
|
|
148
|
-
enclosure_title: title,
|
|
149
|
-
enclosure_length: undefined,
|
|
150
|
-
itunes_duration: itunesDuration,
|
|
151
|
-
itunes_item_image: image,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const medias: Record<string, Record<string, string>> = {};
|
|
156
|
-
|
|
157
|
-
if (data.full_size_images ?? data.images) {
|
|
158
|
-
const images = data.full_size_images ?? data.images;
|
|
159
|
-
for (const media of images) {
|
|
160
|
-
const url: string | undefined = media.url ?? media;
|
|
161
|
-
|
|
162
|
-
if (!url) {
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const medium: string = 'image';
|
|
167
|
-
const count: number = Object.values(medias).filter((m) => m.medium === medium).length + 1;
|
|
168
|
-
const key: string = `${medium}${count}`;
|
|
169
|
-
|
|
170
|
-
medias[key] = {
|
|
171
|
-
url,
|
|
172
|
-
medium,
|
|
173
|
-
title,
|
|
174
|
-
thumbnail: media.thumbnail ?? url,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
processedItem = {
|
|
180
|
-
...processedItem,
|
|
181
|
-
media: medias,
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
...item,
|
|
186
|
-
...processedItem,
|
|
187
|
-
};
|
|
188
|
-
});
|
|
189
|
-
})
|
|
190
|
-
)
|
|
191
|
-
).filter((_): _ is DataItem => true);
|
|
192
|
-
|
|
193
|
-
const title: string = $('title').text();
|
|
194
|
-
const author: string | undefined = title.split(/-/).pop();
|
|
195
12
|
|
|
196
|
-
return {
|
|
197
|
-
title,
|
|
198
|
-
description: $('meta[property="og:description"]').attr('content'),
|
|
199
|
-
link: targetUrl,
|
|
200
|
-
item: items,
|
|
201
|
-
allowEmpty: true,
|
|
202
|
-
image: $('meta[property="og:image"]').attr('content'),
|
|
203
|
-
author: title.split(/-/).pop(),
|
|
204
|
-
language,
|
|
205
|
-
itunes_author: author,
|
|
206
|
-
itunes_category: 'Technology',
|
|
207
|
-
id: targetUrl,
|
|
208
|
-
};
|
|
13
|
+
return await processItems(limit, {}, listApiUrl, targetUrl);
|
|
209
14
|
};
|
|
210
15
|
|
|
211
16
|
export const route: Route = {
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { type Data, type DataItem } from '@/types';
|
|
2
|
+
|
|
3
|
+
import { art } from '@/utils/render';
|
|
4
|
+
import cache from '@/utils/cache';
|
|
5
|
+
import { getCurrentPath } from '@/utils/helpers';
|
|
6
|
+
import ofetch from '@/utils/ofetch';
|
|
7
|
+
import { parseDate } from '@/utils/parse-date';
|
|
8
|
+
|
|
9
|
+
import { type CheerioAPI, load } from 'cheerio';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
const __dirname = getCurrentPath(import.meta.url);
|
|
13
|
+
|
|
14
|
+
const baseUrl: string = 'https://www.tmtpost.com';
|
|
15
|
+
const apiBaseUrl: string = 'https://api.tmtpost.com';
|
|
16
|
+
const postApiUrl: string = new URL('v1/posts/', apiBaseUrl).href;
|
|
17
|
+
|
|
18
|
+
const headers = {
|
|
19
|
+
'app-version': 'web1.0',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const processItems = async (limit: number, query: Record<string, any>, apiUrl: string, targetUrl: string): Promise<Data> => {
|
|
23
|
+
const response = await ofetch(apiUrl, {
|
|
24
|
+
query: {
|
|
25
|
+
limit,
|
|
26
|
+
...query,
|
|
27
|
+
},
|
|
28
|
+
headers,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const targetResponse = await ofetch(targetUrl);
|
|
32
|
+
const $: CheerioAPI = load(targetResponse);
|
|
33
|
+
const language = $('html').attr('lang') ?? 'zh-CN';
|
|
34
|
+
|
|
35
|
+
let items: DataItem[] = [];
|
|
36
|
+
|
|
37
|
+
items = response.data.slice(0, limit).map((item): DataItem => {
|
|
38
|
+
const title: string = item.title;
|
|
39
|
+
const description: string = art(path.join(__dirname, 'templates/description.art'), {
|
|
40
|
+
intro: item.summary,
|
|
41
|
+
});
|
|
42
|
+
const pubDate: number | string = item.time_published;
|
|
43
|
+
const linkUrl: string | undefined = item.share_link;
|
|
44
|
+
const guid: string = item.guid;
|
|
45
|
+
const image: string | undefined = item.thumb_image?.original?.url;
|
|
46
|
+
const updated: number | string = item.updated ?? pubDate;
|
|
47
|
+
|
|
48
|
+
const processedItem: DataItem = {
|
|
49
|
+
title,
|
|
50
|
+
description,
|
|
51
|
+
pubDate: pubDate ? parseDate(pubDate, 'X') : undefined,
|
|
52
|
+
link: linkUrl,
|
|
53
|
+
guid,
|
|
54
|
+
id: guid,
|
|
55
|
+
content: {
|
|
56
|
+
html: description,
|
|
57
|
+
text: item.content ?? description,
|
|
58
|
+
},
|
|
59
|
+
image,
|
|
60
|
+
banner: image,
|
|
61
|
+
updated: updated ? parseDate(updated, 'X') : undefined,
|
|
62
|
+
language,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return processedItem;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
items = (
|
|
69
|
+
await Promise.all(
|
|
70
|
+
items.map((item) => {
|
|
71
|
+
if (!item.link) {
|
|
72
|
+
return item;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return cache.tryGet(item.link, async (): Promise<DataItem> => {
|
|
76
|
+
const detailApiUrl: string = new URL(item.guid as string, postApiUrl).href;
|
|
77
|
+
|
|
78
|
+
const detailResponse = await ofetch(detailApiUrl, {
|
|
79
|
+
query: {
|
|
80
|
+
fields: ['authors', 'tags', 'featured_image', 'categories', 'stock_list', 'big_plate', 'concept_plate', 'plate', 'plate_list', 'share_link'].join(';'),
|
|
81
|
+
},
|
|
82
|
+
headers,
|
|
83
|
+
});
|
|
84
|
+
const data = detailResponse.data;
|
|
85
|
+
|
|
86
|
+
if (!data) {
|
|
87
|
+
return item;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const title: string = data.title;
|
|
91
|
+
const description: string = art(path.join(__dirname, 'templates/description.art'), {
|
|
92
|
+
intro: data.summary,
|
|
93
|
+
description: data.main,
|
|
94
|
+
});
|
|
95
|
+
const pubDate: number | string = data.time_published;
|
|
96
|
+
const linkUrl: string | undefined = data.share_link;
|
|
97
|
+
const categories: string[] = [
|
|
98
|
+
...new Set(
|
|
99
|
+
(
|
|
100
|
+
[...(data.categories ?? []), ...(data.stock_list ?? []), ...(data.big_plate ?? []), ...(data.concept_plate ?? []), ...(data.plate ?? []), ...(data.plate_list ?? []), ...(data.tags ?? [])].map(
|
|
101
|
+
(c) => c.title ?? c.name ?? c.tag
|
|
102
|
+
) as string[]
|
|
103
|
+
).filter(Boolean)
|
|
104
|
+
),
|
|
105
|
+
];
|
|
106
|
+
const authors: DataItem['author'] = data.authors?.map((author) => ({
|
|
107
|
+
name: author.username,
|
|
108
|
+
url: new URL(`user/${author.guid}`, baseUrl).href,
|
|
109
|
+
avatar: author.avatar,
|
|
110
|
+
}));
|
|
111
|
+
const guid: string = `tmtpost-${data.post_guid}`;
|
|
112
|
+
const image: string | undefined = data.images?.[0]?.url;
|
|
113
|
+
const updated: number | string = data.time_updated;
|
|
114
|
+
|
|
115
|
+
let processedItem: DataItem = {
|
|
116
|
+
title,
|
|
117
|
+
description,
|
|
118
|
+
pubDate: pubDate ? parseDate(pubDate, 'X') : undefined,
|
|
119
|
+
link: linkUrl ?? item.link,
|
|
120
|
+
category: categories,
|
|
121
|
+
author: authors,
|
|
122
|
+
guid,
|
|
123
|
+
id: guid,
|
|
124
|
+
content: {
|
|
125
|
+
html: description,
|
|
126
|
+
text: description,
|
|
127
|
+
},
|
|
128
|
+
image,
|
|
129
|
+
banner: image,
|
|
130
|
+
updated: updated ? parseDate(updated, 'X') : undefined,
|
|
131
|
+
language,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const enclosureUrl: string | undefined = data.audio;
|
|
135
|
+
|
|
136
|
+
if (enclosureUrl) {
|
|
137
|
+
const enclosureType: string = `audio/${enclosureUrl.split(/\./).pop()}`;
|
|
138
|
+
const itunesDuration: string | number | undefined = data.duration;
|
|
139
|
+
|
|
140
|
+
processedItem = {
|
|
141
|
+
...processedItem,
|
|
142
|
+
enclosure_url: enclosureUrl,
|
|
143
|
+
enclosure_type: enclosureType,
|
|
144
|
+
enclosure_title: title,
|
|
145
|
+
enclosure_length: undefined,
|
|
146
|
+
itunes_duration: itunesDuration,
|
|
147
|
+
itunes_item_image: image,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const medias: Record<string, Record<string, string>> = {};
|
|
152
|
+
|
|
153
|
+
if (data.full_size_images ?? data.images) {
|
|
154
|
+
const images = data.full_size_images ?? data.images;
|
|
155
|
+
for (const media of images) {
|
|
156
|
+
const url: string | undefined = media.url ?? media;
|
|
157
|
+
|
|
158
|
+
if (!url) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const medium: string = 'image';
|
|
163
|
+
const count: number = Object.values(medias).filter((m) => m.medium === medium).length + 1;
|
|
164
|
+
const key: string = `${medium}${count}`;
|
|
165
|
+
|
|
166
|
+
medias[key] = {
|
|
167
|
+
url,
|
|
168
|
+
medium,
|
|
169
|
+
title,
|
|
170
|
+
thumbnail: media.thumbnail ?? url,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
processedItem = {
|
|
176
|
+
...processedItem,
|
|
177
|
+
media: medias,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
...item,
|
|
182
|
+
...processedItem,
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
})
|
|
186
|
+
)
|
|
187
|
+
).filter((_): _ is DataItem => true);
|
|
188
|
+
|
|
189
|
+
const title: string = $('title').text();
|
|
190
|
+
const author: string | undefined = title.split(/-/).pop();
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
title,
|
|
194
|
+
description: $('meta[property="og:description"]').attr('content'),
|
|
195
|
+
link: targetUrl,
|
|
196
|
+
item: items,
|
|
197
|
+
allowEmpty: true,
|
|
198
|
+
image: $('meta[property="og:image"]').attr('content'),
|
|
199
|
+
author: title.split(/-/).pop(),
|
|
200
|
+
language,
|
|
201
|
+
itunes_author: author,
|
|
202
|
+
itunes_category: 'Technology',
|
|
203
|
+
id: targetUrl,
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export { baseUrl, apiBaseUrl, processItems };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Route, Data, DataItem } from '@/types';
|
|
2
|
+
import ofetch from '@/utils/ofetch';
|
|
3
|
+
import { parseDate } from '@/utils/parse-date';
|
|
4
|
+
import { load } from 'cheerio';
|
|
5
|
+
|
|
6
|
+
export const route: Route = {
|
|
7
|
+
path: '/news/:category?',
|
|
8
|
+
categories: ['anime'],
|
|
9
|
+
example: '/toranoana/news/toragen',
|
|
10
|
+
parameters: { category: 'category' },
|
|
11
|
+
features: {
|
|
12
|
+
requireConfig: false,
|
|
13
|
+
requirePuppeteer: false,
|
|
14
|
+
antiCrawler: false,
|
|
15
|
+
supportBT: false,
|
|
16
|
+
supportPodcast: false,
|
|
17
|
+
supportScihub: false,
|
|
18
|
+
},
|
|
19
|
+
name: 'Category',
|
|
20
|
+
maintainers: ['Tsuyumi25'],
|
|
21
|
+
handler,
|
|
22
|
+
radar: [
|
|
23
|
+
{
|
|
24
|
+
title: '総合新着記事',
|
|
25
|
+
source: ['news.toranoana.jp'],
|
|
26
|
+
target: '/news',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
title: '女性向け',
|
|
30
|
+
source: ['news.toranoana.jp/joshi'],
|
|
31
|
+
target: '/news/joshi',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
title: 'イラスト展',
|
|
35
|
+
source: ['news.toranoana.jp/exhibitions'],
|
|
36
|
+
target: '/news/exhibition',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
source: ['news.toranoana.jp/category/:category'],
|
|
40
|
+
target: '/news/:category',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
description: `
|
|
44
|
+
::: warning TIP
|
|
45
|
+
[総合新着記事](https://news.toranoana.jp)→\`/toranoana/news\`
|
|
46
|
+
[女性向け](https://news.toranoana.jp/joshi)→\`/toranoana/news/joshi\`
|
|
47
|
+
[イラスト展](https://news.toranoana.jp/exhibitions)→\`/toranoana/news/exhibition\`
|
|
48
|
+
[\`https://news.toranoana.jp/category/media\`](https://news.toranoana.jp/category/media)→\`/toranoana/news/media\`
|
|
49
|
+
:::`,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
async function handler(ctx): Promise<Data> {
|
|
53
|
+
const { category = '' } = ctx.req.param();
|
|
54
|
+
let apiUrl = 'https://news.toranoana.jp/wp-json/wp/v2/posts';
|
|
55
|
+
|
|
56
|
+
if (category) {
|
|
57
|
+
const categoryResponse = await ofetch(`https://news.toranoana.jp/wp-json/wp/v2/categories?slug=${category}`);
|
|
58
|
+
if (categoryResponse && categoryResponse.length > 0) {
|
|
59
|
+
apiUrl += `?categories=${categoryResponse[0].id}`;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
// exclude category-joshi to get result of general
|
|
63
|
+
apiUrl += `?categories_exclude=1598`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const posts = await ofetch(apiUrl, {
|
|
67
|
+
query: {
|
|
68
|
+
per_page: 20,
|
|
69
|
+
_embed: 'wp:featuredmedia',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (!posts || !posts.length) {
|
|
74
|
+
throw new Error('No posts found');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const items = posts.map((post) => {
|
|
78
|
+
const $ = load(post.content.rendered);
|
|
79
|
+
|
|
80
|
+
// remove unnecessary title
|
|
81
|
+
$('h1').first().remove();
|
|
82
|
+
$('h2').first().remove();
|
|
83
|
+
|
|
84
|
+
let thumbnail = '';
|
|
85
|
+
if (post._embedded && post._embedded['wp:featuredmedia'][0].source_url) {
|
|
86
|
+
thumbnail = post._embedded['wp:featuredmedia'][0].source_url;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (thumbnail) {
|
|
90
|
+
$('body').prepend(`<img src="${thumbnail}" alt="${post.title.rendered}" />`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
title: post.title.rendered,
|
|
95
|
+
link: post.link,
|
|
96
|
+
description: $.html(),
|
|
97
|
+
pubDate: parseDate(post.date_gmt),
|
|
98
|
+
guid: post.link,
|
|
99
|
+
author: 'とらのあな',
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
title: category ? `とらのあな総合インフォメーション - ${category}` : 'とらのあな総合インフォメーション',
|
|
105
|
+
link: category ? `https://news.toranoana.jp/category/${category}` : 'https://news.toranoana.jp/',
|
|
106
|
+
description: 'とらのあなの最新情報をお届け!同人誌、書籍、コミック、店舗フェア、イラスト展、とらのあな限定版、キャンペーンなど…スペシャルでお得な情報をいち早くチェック!',
|
|
107
|
+
item: items.filter(Boolean) as DataItem[],
|
|
108
|
+
language: 'ja',
|
|
109
|
+
};
|
|
110
|
+
}
|