Skip to content

Commit

Permalink
feat(route): add 虎嗅频道 & 源流 (DIYgod#13945)
Browse files Browse the repository at this point in the history
* feat(route): add 虎嗅频道 & 源流

* fix: limit to 20

* docs: remove rssbud
  • Loading branch information
nczitzk authored Dec 4, 2023
1 parent 242083e commit 804a4ab
Show file tree
Hide file tree
Showing 21 changed files with 745 additions and 426 deletions.
33 changes: 0 additions & 33 deletions lib/v2/huxiu/article.js

This file was deleted.

36 changes: 0 additions & 36 deletions lib/v2/huxiu/author.js

This file was deleted.

38 changes: 13 additions & 25 deletions lib/v2/huxiu/briefColumn.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { baseUrl, briefApi, ProcessFeed } = require('./utils');

const { apiBriefRootUrl, processItems, fetchBriefColumnData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const link = `${briefApi}/briefColumn/getContentListByCategoryId`;
const { data: response } = await got
.post(link, {
form: {
platform: 'www',
brief_column_id: id,
},
})
.json();
const {
data: { data: briefDetail },
} = await got.post(`${briefApi}/briefColumn/detail`, {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const apiUrl = new URL('briefColumn/getContentListByCategoryId', apiBriefRootUrl).href;

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
brief_column_id: id,
pagesize: limit,
},
});

const list = response.datalist.map((item) => ({
title: item.title,
link: `${baseUrl}/brief/${item.brief_id}`,
description: item.preface,
pubDate: parseDate(item.publish_time, 'X'),
}));
ctx.state.json = response.data.datalist;

const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

const items = await ProcessFeed(list, ctx.cache);
const data = await fetchBriefColumnData(id);

ctx.state.data = {
title: `虎嗅 - ${briefDetail.name}`,
description: briefDetail.summary,
image: briefDetail.head_img,
link: `${baseUrl}/briefColumn/${id}.html`,
item: items,
...data,
};
};
28 changes: 28 additions & 0 deletions lib/v2/huxiu/channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const got = require('@/utils/got');

const { rootUrl, apiArticleRootUrl, processItems, fetchData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const apiUrl = new URL(`web/${id ? 'channel' : 'article'}/articleList`, apiArticleRootUrl).href;
const currentUrl = new URL(id ? `channel/${id}.html` : 'article', rootUrl).href;

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
channel_id: id,
pagesize: limit,
},
});

const items = await processItems(response.data?.dataList ?? response.data.datalist, limit, ctx.cache.tryGet);

const data = await fetchData(currentUrl);

ctx.state.data = {
item: items,
...data,
};
};
30 changes: 30 additions & 0 deletions lib/v2/huxiu/club.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const got = require('@/utils/got');

const { apiBriefRootUrl, processItems, fetchClubData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const apiUrl = new URL('club/briefList', apiBriefRootUrl).href;

const { data, briefColumnId } = await fetchClubData(id);

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
club_id: id,
brief_column_id: briefColumnId,
pagesize: limit,
},
});

ctx.state.json = response.data.datalist;

const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

ctx.state.data = {
item: items,
...data,
};
};
40 changes: 14 additions & 26 deletions lib/v2/huxiu/collection.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
const { parseDate } = require('@/utils/parse-date');

const { rootUrl, apiArticleRootUrl, processItems, fetchData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const link = `${utils.baseUrl}/collection/${id}.html`;
const { data: response } = await got(link, {
https: {
rejectUnauthorized: false,
},
});
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;

const $ = cheerio.load(response);
const apiUrl = new URL('web/collection/articleList', apiArticleRootUrl).href;
const currentUrl = new URL(`collection/${id}.html`, rootUrl).href;

const initialState = utils.parseInitialState($);

const { collectionDetail } = initialState.collectionDetail;
const list = collectionDetail.article_list.datalist.map((e) => ({
title: e.title,
link: `${utils.baseUrl}/article/${e.aid}.html`,
description: e.summary,
pubDate: parseDate(e.dateline, 'X'),
author: e.user_info.username,
}));
const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
collection_id: id,
},
});

const items = await utils.ProcessFeed(list, ctx.cache);
const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

const info = `虎嗅 - ${collectionDetail.name}`;
const data = await fetchData(currentUrl);

ctx.state.data = {
title: info,
description: collectionDetail.summary,
image: collectionDetail.icon,
link,
item: items,
...data,
};
};
13 changes: 8 additions & 5 deletions lib/v2/huxiu/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
'/article': ['HenryQW'],
'/author/:id': ['HenryQW'],
'/collection/:id': ['AlexdanerZe'],
'/article': ['HenryQW', 'nczitzk'],
'/briefcolumn/:id': ['Fatpandac', 'nczitzk'],
'/channel/:id?': ['nczitzk'],
'/club/:id': ['nczitzk'],
'/collection/:id': ['AlexdanerZe', 'nczitzk'],
'/member/:id/:type?': ['HenryQW', 'nczitzk'],
'/moment': ['nczitzk'],
'/tag/:id': ['xyqfer', 'HenryQW'],
'/search/:keyword': ['xyqfer', 'HenryQW'],
'/search/:keyword': ['xyqfer', 'HenryQW', 'nczitzk'],
'/tag/:id': ['xyqfer', 'HenryQW', 'nczitzk'],
};
27 changes: 27 additions & 0 deletions lib/v2/huxiu/member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const got = require('@/utils/got');

const { rootUrl, apiMemberRootUrl, processItems, fetchData } = require('./util');

module.exports = async (ctx) => {
const { id, type = 'article' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;

const apiUrl = new URL(`web/${type}/${type}List`, apiMemberRootUrl).href;
const currentUrl = new URL(`member/${id}${type === 'article' ? '' : `/${type}`}.html`, rootUrl).href;

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
uid: id,
},
});

const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

const data = await fetchData(currentUrl);

ctx.state.data = {
item: items,
...data,
};
};
36 changes: 11 additions & 25 deletions lib/v2/huxiu/moment.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const { baseUrl: rootUrl, momentApi: apiRootUrl } = require('./utils');

const { rootUrl, apiMomentRootUrl, processItems, fetchData } = require('./util');

module.exports = async (ctx) => {
const currentUrl = `${rootUrl}/moment`;
const apiUrl = `${apiRootUrl}/web-v2/moment/feed`;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const apiUrl = new URL('web-v2/moment/feed', apiMomentRootUrl).href;
const currentUrl = new URL('moment', rootUrl).href;

const response = await got({
method: 'post',
url: apiUrl,
const { data: response } = await got.post(apiUrl, {
form: {
last_dateline: parseInt(new Date().getTime() / 1000),
platform: 'www',
is_ai: 0,
},
});

const items = response.data.data.moment_list.datalist[0].datalist.map((item) => ({
title: item.content,
link: item.share_url,
author: item.user_info.username,
pubDate: parseDate(item.publish_time * 1000),
description: art(path.join(__dirname, 'templates/moment.art'), {
description: item.content,
images: item.img_urls,
video: item.video,
comments: item.comment,
}),
}));
const items = await processItems(response.data.moment_list.datalist[0].datalist, limit, ctx.cache.tryGet);

const data = await fetchData(currentUrl);

ctx.state.data = {
title: '虎嗅 - 24小时',
link: currentUrl,
item: items,
...data,
};
};
Loading

0 comments on commit 804a4ab

Please sign in to comment.