-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(route): student5 * docs: add docs * fix: timezone
- Loading branch information
Showing
11 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` : ''}`, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<img src="{{ section.content }}"> | ||
<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a href="https://rsshub.app/zuvio/student5/{{ id }}">{{ id }}</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |