Skip to content

Commit

Permalink
feat(route): zuvio (#10529)
Browse files Browse the repository at this point in the history
* feat(route): student5

* docs: add docs

* fix: timezone
  • Loading branch information
TonyRL authored Aug 18, 2022
1 parent 1c11475 commit 78ccdc7
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/bbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,16 @@ pageClass: routes

<Route author="liyefox" example="/v2ex/tab/hot" path="/v2ex/tab/:tabid" :paramsDesc="['tab标签ID,在 URL 可以找到']"/>

## Zuvio

### 校園話題

<Route author="TonyRL" example="/zuvio/student5/34" path="/zuvio/student5/:board?" :paramsDesc="['看板 ID,空为全站文章,可在看板 URL 或下方路由找到']" radar="1" rssbud="1"/>

### 看板列表

<Route author="TonyRL" example="/zuvio/student5/boards" path="/zuvio/student5/boards" />

## 巴哈姆特電玩資訊站

### 熱門推薦
Expand Down
14 changes: 14 additions & 0 deletions lib/v2/zuvio/boards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { getBoards, rootUrl } = require('./utils');

module.exports = async (ctx) => {
const items = await getBoards(ctx.cache.tryGet);

ctx.state.data = {
title: 'Zuvio 校園話題列表 - 大學生論壇',
description: 'Zuvio 校園話題,Zuvio 校園話題千種動物頭像交流心得。最萌的匿名論壇,上千種逗趣動物頭像隨你變換,點頭像立即私訊功能,讓你找到共同話題的小夥伴!多人分享配對心得、聊天交友心情在此,快加入17分享!',
image: 'https://s3.hicloud.net.tw/zuvio.public/public/system/images/irs_v4/chicken/shared/webshare.png',
link: `${rootUrl}/articles`,
item: items,
language: 'zh-Hant',
};
};
13 changes: 13 additions & 0 deletions lib/v2/zuvio/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'zuvio.com.tw': {
_name: 'Zuvio',
irs: [
{
title: '校園話題',
docs: 'https://docs.rsshub.app/bbs.html#zuvio',
source: ['/student5/chickenM/articles/:board', '/student5/chickenM/articles'],
target: (params) => `/zuvio/student5${params.board ? `/${params.board}` : ''}`,
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/zuvio/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/student5/boards', require('./boards'));
router.get('/student5/:board?', require('./student5'));
};
58 changes: 58 additions & 0 deletions lib/v2/zuvio/student5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const { token, apiUrl, rootUrl, renderDesc, getBoards } = require('./utils');

module.exports = async (ctx) => {
const { board = '' } = ctx.params;
const title = board ? (await getBoards(ctx.cache.tryGet)).find((i) => i.boardId === board).title : '全部';

const { data } = await got(`${apiUrl}/article`, {
searchParams: {
api_token: token,
user_id: '0',
board_id: board,
sort: 'time',
page: '1',
device: 'web',
my_school_opinion: '1',
},
});

const items = data.articles.map((item) => ({
title: item.title,
description: item.abstract,
pubDate: timezone(parseDate(item.created_at), +8),
link: `${rootUrl}/article/${item.id}`,
api: `${apiUrl}/article/${item.id}`,
author: `${item.university} ${item.user_name}`,
category: item.board_name,
}));

await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data } = await got(item.api, {
searchParams: {
api_token: token,
user_id: '0',
device: 'web',
ref: '',
},
});
item.description = renderDesc(data);
delete item.api;
return item;
})
)
);

ctx.state.data = {
title: `Zuvio 校園${title}話題 - 大學生論壇`,
description: 'Zuvio 校園話題千種動物頭像交流心得。最萌的匿名論壇,上千種逗趣動物頭像隨你變換,點頭像立即私訊功能,讓你找到共同話題的小夥伴!多人分享配對心得、聊天交友心情在此,快加入17分享!',
image: 'https://s3.hicloud.net.tw/zuvio.public/public/system/images/irs_v4/chicken/shared/webshare.png',
link: `${rootUrl}/articles`,
item: items,
language: 'zh-Hant',
};
};
2 changes: 2 additions & 0 deletions lib/v2/zuvio/templates/img.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<img src="{{ section.content }}">
<br>
7 changes: 7 additions & 0 deletions lib/v2/zuvio/templates/link.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>
<a href="{{ section.content }}">
<img src="{{ section.icon }}">
<div>{{ section.title}}</div>
<div>{{ section.description}}</div>
</a>
</p>
8 changes: 8 additions & 0 deletions lib/v2/zuvio/templates/ref_article.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
引用自:
<a href="{{ ref_article.id }}">
<img src="{{ ref_article.user_icon }}">
<div>{{ ref_article.university }} {{ ref_article.user_name }} {{ ref_article.board_name }}</div>
<div>{{ ref_article.title }}</div>
<div>{{ ref_article.abstract }}</div>
</a>
<hr>
1 change: 1 addition & 0 deletions lib/v2/zuvio/templates/rss.art
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="https://rsshub.app/zuvio/student5/{{ id }}">{{ id }}</a>
2 changes: 2 additions & 0 deletions lib/v2/zuvio/templates/youtube.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<iframe width="672" height="377" src="https://www.youtube-nocookie.com/embed/{{ section.youtube_id }}" frameborder="0" allowfullscreen></iframe>
<br>
61 changes: 61 additions & 0 deletions lib/v2/zuvio/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { art } = require('@/utils/render');
const path = require('path');
const got = require('@/utils/got');

const token =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0OTcyMzI1MjMsInN5c3RlbV9uYW1lIjoiZm9ydW0iLCJ6dXZpb19pZCI6LTk5OSwiZW1haWwiOm51bGwsIm5hbWUiOm51bGwsInVuaXZlcnNpdHlfaWQiOm51bGwsInVuaXZlcnNpdHlfbmFtZSI6bnVsbH0.0KoJiSnyazsJxLCNEnqnuNUdKsJFhBdCn3R2BJpoUtk';
const apiUrl = 'https://forum.zuvio.com.tw/api';
const rootUrl = 'https://irs.zuvio.com.tw/student5/chickenM';

const renderDesc = (data) => {
let output = '';
if (data.ref_article) {
output += art(path.join(__dirname, 'templates/ref_article.art'), {
ref_article: data.ref_article,
});
}
output += renderSections(data.sections);
return output;
};

const renderSections = (sections) => {
let output = '';
for (const section of sections) {
if (section.type === 'text') {
output += section.content.replace(/\n/g, '<br>');
} else if (section.type === 'img') {
output += art(path.join(__dirname, 'templates/img.art'), { section });
} else if (section.type === 'youtube') {
output += art(path.join(__dirname, 'templates/youtube.art'), { section });
} else if (section.type === 'link') {
output += art(path.join(__dirname, 'templates/link.art'), { section });
}
}
return output;
};

const getBoards = (tryGet) =>
tryGet('zuvio:boards', async () => {
const { data } = await got(`${apiUrl}/board`, {
searchParams: {
api_token: token,
user_id: '0',
},
});

return data.map((item) => ({
title: item.name,
description: art(path.join(__dirname, 'templates/rss.art'), { id: item.id }),
boardId: item.id,
link: `${rootUrl}/articles/${item.id}`,
}));
});

module.exports = {
token,
apiUrl,
rootUrl,
renderDesc,
renderSections,
getBoards,
};

0 comments on commit 78ccdc7

Please sign in to comment.