Skip to content

Commit

Permalink
juejin module
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Apr 11, 2018
1 parent c950454 commit 6f4da7c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"no-useless-rename": 1,
"rest-spread-spacing": 1,
"no-trailing-spaces": 1,
"quotes": [1, "single"]
"quotes": [1, "single"],
"no-control-regex": 0
}
}
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ app.get('/bilibili/user/dynamic/:uid', require('./routes/bilibili/dynamic'));
app.get('/bilibili/partion/:tid', require('./routes/bilibili/partion'));
app.get('/bilibili/bangumi/:seasonid', require('./routes/bilibili/bangumi'));

// Weibo
// 微博
app.get('/weibo/user/:uid', require('./routes/weibo/user'));

// NetEaseCloudMusic
// 网易云音乐
app.get('/ncm/playlist/:id', require('./routes/ncm/playlist'));

// 掘金
app.get('/juejin/category/:category', require('./routes/juejin/category'));

app.listen(1200);
70 changes: 70 additions & 0 deletions routes/juejin/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const request = require('request');
const art = require('art-template');
const path = require('path');
const base = require('../base');
const mix = require('../../utils/mix');

module.exports = (req, res) => {
const category = req.params.category;

base({
req: req,
res: res,
getHTML: (callback) => {
request.get({
url: 'https://gold-tag-ms.juejin.im/v1/categories',
headers: {
'User-Agent': mix.ua,
'Referer': `https://juejin.im/welcome/${category}`,
'X-Juejin-Client': '',
'X-Juejin-Src': 'web',
'X-Juejin-Token': '',
'X-Juejin-Uid': ''
}
}, function (err, httpResponse, body) {
let data;
try {
data = JSON.parse(body);
}
catch (e) {
data = {};
}
const cat = data.d && data.d.categoryList && data.d.categoryList.filter((item) => item.title === category)[0];
if (cat && cat.id) {
request.get({
url: `https://timeline-merger-ms.juejin.im/v1/get_entry_by_timeline?src=web&limit=20&category=${cat.id}`,
headers: {
'User-Agent': mix.ua,
'Referer': `https://juejin.im/welcome/${category}`,
}
}, function (err, httpResponse, body) {
let data;
try {
data = JSON.parse(body);
}
catch (e) {
data = {};
}

const html = art(path.resolve(__dirname, '../../views/rss.art'), {
title: `掘金${cat.name}`,
link: `https://juejin.im/welcome/${category}`,
description: `掘金${cat.name}`,
lastBuildDate: new Date().toUTCString(),
item: data.d && data.d.entrylist && data.d.entrylist.map((item) => ({
title: item.title,
description: `${(item.content || item.summaryInfo || '无描述').replace(/[\x00-\x08\x0b-\x0c\x0e-\x1f\x7f]/g, '')}`,
pubDate: new Date(item.createdAt).toUTCString(),
link: item.originalUrl
})),
});
callback(html);
});
}
else {
callback('');
}
});
}
});
};

0 comments on commit 6f4da7c

Please sign in to comment.