generate template after filter for a better performance

This commit is contained in:
DIYgod 2018-05-11 18:50:41 +08:00
parent 4776fa6aba
commit 1fb172045c
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
54 changed files with 126 additions and 192 deletions

View File

@ -9,6 +9,7 @@ const utf8 = require('./middleware/utf8');
const memoryCache = require('./middleware/cache.js');
const redisCache = require('koa-redis-cache');
const filter = require('./middleware/filter.js');
const template = require('./middleware/template.js');
const router = require('./router');
@ -29,6 +30,10 @@ app.use(header);
// fix incorrect `utf-8` characters
app.use(utf8);
// generate body
app.use(template);
// filter content
app.use(filter);
// cache

View File

@ -88,7 +88,11 @@ module.exports = function (options = {}) {
if (Buffer.isBuffer(type)) {type = type.toString();}
ctx.response.set('X-Koa-Memory-Cache', 'true');
ctx.response.type = type;
ctx.response.body = value;
try {
ctx.state.data = JSON.parse(value);
} catch (e) {
ctx.state.data = {};
}
ok = true;
}
@ -99,34 +103,16 @@ module.exports = function (options = {}) {
* setCache
*/
async function setCache (ctx, key, tkey) {
let body = ctx.response.body;
ctx.state.data.lastBuildDate = new Date().toUTCString();
const body = JSON.stringify(ctx.state.data);
if (ctx.request.method !== 'GET' || ctx.response.status !== 200 || !body) {
if (ctx.request.method !== 'GET' || !body) {
return;
}
if (typeof body === 'string') {
// string
if (Buffer.byteLength(body) > maxLength) {return;}
memoryCache.set(key, body);
} else if (Buffer.isBuffer(body)) {
// buffer
if (body.length > maxLength) {return;}
memoryCache.set(key, body);
} else if (typeof body === 'object' && ctx.response.type === 'application/json') {
// json
body = JSON.stringify(body);
if (Buffer.byteLength(body) > maxLength) {return;}
memoryCache.set(key, body);
} else if (typeof body.pipe === 'function') {
// stream
body = await read(body);
ctx.response.body = body;
if (Buffer.byteLength(body) > maxLength) {return;}
memoryCache.set(key, body);
} else {
if (Buffer.byteLength(body) > maxLength) {
return;
}
memoryCache.set(key, body);
await cacheType(ctx, tkey);
}

View File

@ -1,20 +1,13 @@
const cheerio = require('cheerio');
module.exports = async (ctx, next) => {
await next();
if (ctx.body && ctx.query && (ctx.query.filter || ctx.query.filter_title || ctx.query.filter_description)) {
const $ = cheerio.load(ctx.body, {
xmlMode: true
});
$('item').filter((index, item) => {
const title = $(item).find('title').text();
const description = $(item).find('description').text();
return ctx.query.filter && !title.match(ctx.query.filter) && !description.match(ctx.query.filter)
if (ctx.state.data && ctx.query && (ctx.query.filter || ctx.query.filter_title || ctx.query.filter_description)) {
ctx.state.data.item = ctx.state.data.item.filter((item) => {
const title = item.title;
const description = item.description;
return !(ctx.query.filter && !title.match(ctx.query.filter) && !description.match(ctx.query.filter)
|| ctx.query.filter_title && !title.match(ctx.query.filter_title)
|| ctx.query.filter_description && !description.match(ctx.query.filter_description);
}).remove();
ctx.body = $.xml();
|| ctx.query.filter_description && !description.match(ctx.query.filter_description));
});
}
};

View File

@ -2,10 +2,11 @@ const art = require('art-template');
const path = require('path');
const config = require('../config');
module.exports = function (options) {
return art(path.resolve(__dirname, '../views/rss.art'), {
module.exports = async (ctx, next) => {
await next();
ctx.body = art(path.resolve(__dirname, '../views/rss.art'), {
lastBuildDate: new Date().toUTCString(),
ttl: config.cacheExpire,
...options,
...ctx.state.data,
});
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -16,7 +15,7 @@ module.exports = async (ctx) => {
const data = JSON.parse(response.data.match(/^seasonListCallback\((.*)\);$/)[1]).result || {};
ctx.body = template({
ctx.state.data = {
title: data.title,
link: `https://bangumi.bilibili.com/anime/${seasonid}/`,
description: data.evaluate,
@ -26,5 +25,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.update_time).toUTCString(),
link: item.webplay_url
})),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -30,7 +29,7 @@ module.exports = async (ctx) => {
});
const data = response.data;
ctx.body = template({
ctx.state.data = {
title: `${name} 的 bilibili 投币视频`,
link: `https://space.bilibili.com/${uid}`,
description: `${name} 的 bilibili 投币视频`,
@ -39,5 +38,5 @@ module.exports = async (ctx) => {
description: `${item.title}<br><img referrerpolicy="no-referrer" src="${item.pic}">`,
link: `https://www.bilibili.com/video/av${item.stat.aid}`
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const JSONbig = require('json-bigint');
const config = require('../../config');
@ -16,7 +15,7 @@ module.exports = async (ctx) => {
});
const data = response.data.data.cards;
ctx.body = template({
ctx.state.data = {
title: `${data[0].desc.user_profile.info.uname} 的 bilibili 动态`,
link: `https://space.bilibili.com/${uid}/#/dynamic`,
description: `${data[0].desc.user_profile.info.uname} 的 bilibili 动态`,
@ -54,5 +53,5 @@ module.exports = async (ctx) => {
link: link
};
}),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -30,7 +29,7 @@ module.exports = async (ctx) => {
});
const data = response.data;
ctx.body = template({
ctx.state.data = {
title: `${name} 的 bilibili 收藏夹`,
link: `https://space.bilibili.com/${uid}/#/favlist`,
description: `${name} 的 bilibili 收藏夹`,
@ -41,5 +40,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.fav_at * 1000).toUTCString(),
link: `https://www.bilibili.com/video/av${item.aid}`
})),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -40,7 +39,7 @@ module.exports = async (ctx) => {
});
const data = response.data.data.list;
ctx.body = template({
ctx.state.data = {
title: `${name} 的 bilibili 粉丝`,
link: `https://space.bilibili.com/${uid}/#/fans/fans`,
description: `${name} 的 bilibili 粉丝`,
@ -50,5 +49,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.mtime * 1000).toUTCString(),
link: `https://space.bilibili.com/${item.mid}`
})),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -40,7 +39,7 @@ module.exports = async (ctx) => {
});
const data = response.data.data.list;
ctx.body = template({
ctx.state.data = {
title: `${name} 的 bilibili 关注`,
link: `https://space.bilibili.com/${uid}/#/fans/follow`,
description: `${name} 的 bilibili 关注`,
@ -50,5 +49,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.mtime * 1000).toUTCString(),
link: `https://space.bilibili.com/${item.mid}`
})),
});
};
};

View File

@ -1,6 +1,4 @@
const axios = require('axios');
const art = require('art-template');
const path = require('path');
const config = require('../../config');
module.exports = async (ctx) => {
@ -31,7 +29,7 @@ module.exports = async (ctx) => {
});
const data = response.data.data.items;
ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), {
ctx.state.data = {
title: `bilibili ${productTitle}公告`,
link: `https://link.bilibili.com/p/eden/news#/?tab=${product}&tag=all&page_no=1`,
description: `bilibili ${productTitle}公告`,
@ -42,5 +40,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.ctime.replace(' ', 'T') + "+08:00").toUTCString(),
link: item.announce_link ? item.announce_link : `https://link.bilibili.com/p/eden/news#/newsdetail?id=${item.id}`
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -20,7 +19,7 @@ module.exports = async (ctx) => {
name = list[0].tname;
}
ctx.body = template({
ctx.state.data = {
title: `bilibili ${name}分区`,
link: 'https://www.bilibili.com',
description: `bilibili ${name}分区`,
@ -30,5 +29,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.pubdate * 1000).toUTCString(),
link: `https://www.bilibili.com/video/av${item.aid}`
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
@ -31,7 +30,7 @@ module.exports = async (ctx) => {
const data = response.data.data.replies;
ctx.body = template({
ctx.state.data = {
title: `${name} 的 评论`,
link: `https://www.bilibili.com/video/av${aid}`,
description: `${name} 的评论`,
@ -41,5 +40,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.ctime * 1000).toUTCString(),
link: `https://www.bilibili.com/video/av${aid}/#reply${item.rpid}`
})),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -30,7 +29,7 @@ module.exports = async (ctx) => {
});
const data = response.data;
ctx.body = template({
ctx.state.data = {
title: `${name} 的 bilibili 空间`,
link: `https://space.bilibili.com/${uid}`,
description: `${name} 的 bilibili 空间`,
@ -40,5 +39,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.created * 1000).toUTCString(),
link: `https://www.bilibili.com/video/av${item.aid}`
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
const iconv = require('iconv-lite');
@ -37,11 +36,11 @@ module.exports = async (ctx) => {
chapter_item.push(item);
}
// console.log('chapter_item',chapter_item)
ctx.body = template({
ctx.state.data = {
title: `笔趣阁 ${title}`,
link: `${baseUrl}${id}/`,
image: cover_url,
description: description,
item: chapter_item,
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
const iconv = require('iconv-lite');
@ -46,10 +45,10 @@ module.exports = async (ctx) => {
result_item.push(item)
}
ctx.body = template({
ctx.state.data = {
title: `喷嚏图卦`,
link: `https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=70`,
description: `喷嚏图卦`,
item: result_item,
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -36,7 +35,7 @@ module.exports = async (ctx) => {
const threads = responseThreads.data.response;
ctx.body = template({
ctx.state.data = {
title: `${forum} 的评论`,
link: `https://disqus.com/home/forums/${forum}`,
description: `${forum} 的 disqus 评论`,
@ -49,5 +48,5 @@ module.exports = async (ctx) => {
link: `${thread.link}/#comment-${item.id}`
};
}),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -26,7 +25,7 @@ module.exports = async (ctx) => {
const list = $('ul.i.issues>li');
ctx.body = template({
ctx.state.data = {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
@ -38,5 +37,5 @@ module.exports = async (ctx) => {
link:`${baseUrl}${item.find('a').attr('href')}`
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
module.exports = async (ctx) => {
const response = await axios({
@ -8,7 +7,7 @@ module.exports = async (ctx) => {
});
const movieList = response.data.subjects;
ctx.body = template({
ctx.state.data = {
title: '即将上映的电影',
link: 'https://movie.douban.com/cinema/later/',
item: movieList.map((item) => ({
@ -16,5 +15,5 @@ module.exports = async (ctx) => {
description: `标题:${item.title}<br> 影片类型:${item.genres.join(' | ')} <br>评分:${item.rating.stars === '00' ? '无' : item.rating.average} <br/> <img referrerpolicy="no-referrer" src="${item.images.large}">`,
link: item.alt
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
module.exports = async (ctx) => {
const city = ctx.params.city;
@ -11,7 +10,7 @@ module.exports = async (ctx) => {
});
const movieList = score ? response.data.subjects.filter((item) => item.rating.average >= score) : response.data.subjects;
ctx.body = template({
ctx.state.data = {
title: `${city ? city : ''}正在上映的${score ? `超过 ${score} 分的` : ''}电影`,
link: 'https://movie.douban.com/cinema/nowplaying/',
item: movieList.map((item) => ({
@ -19,5 +18,5 @@ module.exports = async (ctx) => {
description: `标题:${item.title}<br> 影片类型:${item.genres.join(' | ')} <br>评分:${item.rating.average} <br/> <img referrerpolicy="no-referrer" src="${item.images.large}">`,
link: item.alt
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
module.exports = async (ctx) => {
const response = await axios({
@ -8,7 +7,7 @@ module.exports = async (ctx) => {
});
const movieList = response.data.subjects;
ctx.body = template({
ctx.state.data = {
title: '豆瓣电影北美票房榜',
link: 'https://movie.douban.com/chart',
item: movieList.map((item) => {
@ -19,5 +18,5 @@ module.exports = async (ctx) => {
link: item.alt
};
}),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -17,7 +16,7 @@ module.exports = async (ctx) => {
const data = response.data.data;
ctx.body = template({
ctx.state.data = {
title: `快递 ${company}-${number}`,
link: 'https://www.kuaidi100.com',
description: `快递 ${company}-${number}`,
@ -27,5 +26,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.time || item.ftime).toUTCString(),
link: item.context
})),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const cheerio = require('cheerio');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -21,7 +20,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
ctx.body = template({
ctx.state.data = {
title: `${name}(@${id}) 的 Instagram`,
link: `https://www.instagram.com/${id}/`,
description: $('meta[name="description"]').attr('content'),
@ -46,5 +45,5 @@ module.exports = async (ctx) => {
link: `https://www.instagram.com/p/${item.shortcode}/`
};
}),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const crypto = require('crypto');
const config = require('../../config');
@ -121,10 +120,10 @@ module.exports = async (ctx) => {
});
});
ctx.body = template({
ctx.state.data = {
title: '煎蛋无聊图',
link: 'http://jandan.net/pic',
description: '煎蛋官方无聊图,无限活力的热门图区。',
item: items
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -20,7 +19,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('.note-list li');
ctx.body = template({
ctx.state.data = {
title: $('title').text(),
link: `https://www.jianshu.com/c/${id}`,
description: $('meta[name="description"]').attr('content') || $('title').text(),
@ -33,5 +32,5 @@ module.exports = async (ctx) => {
link: `https://www.jianshu.com${item.find('.title').attr('href')}`
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -18,7 +17,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('.note-list li');
ctx.body = template({
ctx.state.data = {
title: '简书首页',
link: 'https://www.jianshu.com',
description: $('meta[name="description"]').attr('content'),
@ -31,5 +30,5 @@ module.exports = async (ctx) => {
link: `https://www.jianshu.com${item.find('.title').attr('href')}`
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -18,7 +17,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('.note-list li');
ctx.body = template({
ctx.state.data = {
title: '简书 30 日热门',
link: 'https://www.jianshu.com/trending/monthly',
description: '简书 30 日热门',
@ -31,5 +30,5 @@ module.exports = async (ctx) => {
link: `https://www.jianshu.com${item.find('.title').attr('href')}`
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -20,7 +19,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('.note-list li');
ctx.body = template({
ctx.state.data = {
title: $('title').text(),
link: `https://www.jianshu.com/u/${id}`,
description: $('meta[name="description"]').attr('content') || $('title').text(),
@ -33,5 +32,5 @@ module.exports = async (ctx) => {
link: `https://www.jianshu.com${item.find('.title').attr('href')}`
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -18,7 +17,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('.note-list li');
ctx.body = template({
ctx.state.data = {
title: '简书 7 日热门',
link: 'https://www.jianshu.com/trending/weekly',
description: '简书 7 日热门',
@ -31,5 +30,5 @@ module.exports = async (ctx) => {
link: `https://www.jianshu.com${item.find('.title').attr('href')}`
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -32,7 +31,7 @@ module.exports = async (ctx) => {
const data = response.data;
ctx.body = template({
ctx.state.data = {
title: `掘金${cat.name}`,
link: `https://juejin.im/welcome/${category}`,
description: `掘金${cat.name}`,
@ -42,5 +41,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.createdAt).toUTCString(),
link: item.originalUrl
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -23,7 +22,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('#pins li');
ctx.body = template({
ctx.state.data = {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
@ -38,5 +37,5 @@ module.exports = async (ctx) => {
link: linkA.attr('href')
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -49,7 +48,7 @@ module.exports = async (ctx) => {
const reg = /[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d/;
ctx.body = template({
ctx.state.data = {
title: title,
link: url,
description: $('meta[name="description"]').attr('content') || title,
@ -67,5 +66,5 @@ module.exports = async (ctx) => {
link: item.url
};
})
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -22,7 +21,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('#pins li');
ctx.body = template({
ctx.state.data = {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
@ -37,5 +36,5 @@ module.exports = async (ctx) => {
link: linkA.attr('href')
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -20,7 +19,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('.main-content > div.postlist > dl > dd');
ctx.body = template({
ctx.state.data = {
title: $('title').text(),
link: url,
description: $('meta[name="description"]').attr('content') || $('title').text(),
@ -35,5 +34,5 @@ module.exports = async (ctx) => {
link: linkA.attr('href')
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -16,7 +15,7 @@ module.exports = async (ctx) => {
const data = response.data;
ctx.body = template({
ctx.state.data = {
title: data.artist.name,
link: `https://music.163.com/#/artist/album?id=${id}`,
description: `网易云音乐歌手专辑 - ${data.artist.name}`,
@ -28,5 +27,5 @@ module.exports = async (ctx) => {
link: `https://music.163.com/#/album?id=${item.id}`
};
}),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -21,7 +20,7 @@ module.exports = async (ctx) => {
const data = response.data.playlist;
ctx.body = template({
ctx.state.data = {
title: data.name,
link: `https://music.163.com/#/playlist?id=${id}`,
description: `网易云音乐歌单 - ${data.name}`,
@ -33,5 +32,5 @@ module.exports = async (ctx) => {
link: `https://music.163.com/#/song?id=${item.id}`
};
}),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -27,7 +26,7 @@ module.exports = async (ctx) => {
const { nickname, signature } = creator;
ctx.body = template({
ctx.state.data = {
title: `${nickname} 的所有歌单`,
link: `http://music.163.com/user/home?id=${uid}`,
description: signature,
@ -37,5 +36,5 @@ module.exports = async (ctx) => {
pubDate: new Date(pl.createTime).toUTCString(),
link: `http://music.163.com/playlist?id=${pl.id}`
}))
});
};
};

View File

@ -7,7 +7,6 @@ if (!pixivConfig) {
return;
}
const template = require('../../utils/template');
const getToken = require('./token');
const getBookmarks = require('./api/getBookmarks');
const getUserDetail = require('./api/getUserDetail');
@ -28,7 +27,7 @@ module.exports = async (ctx) => {
const illusts = bookmarksResponse.data.illusts;
const username = userDetailResponse.data.user.name
ctx.body = template({
ctx.state.data = {
title: `${username} 的收藏`,
link: `https://www.pixiv.net/bookmark.php?id=${id}`,
description: `${username} 的 pixiv 最新收藏`,
@ -47,5 +46,5 @@ module.exports = async (ctx) => {
link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`
};
})
});
};
};

View File

@ -8,7 +8,6 @@ if (!pixivConfig) {
return;
}
const template = require('../../utils/template');
const getToken = require('./token');
const getRanking = require('./api/getRanking');
@ -57,7 +56,7 @@ module.exports = async (ctx) => {
const dateStr = `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`;
ctx.body = template({
ctx.state.data = {
title: (ctx.params.date ? dateStr : '') + titles[mode],
link: links[mode],
description: dateStr + titles[mode],
@ -76,5 +75,5 @@ module.exports = async (ctx) => {
link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`
};
})
});
};
};

View File

@ -8,7 +8,6 @@ if (!pixivConfig) {
return;
}
const template = require('../../utils/template');
const getToken = require('./token');
const getIllusts = require('./api/getIllusts');
@ -25,7 +24,7 @@ module.exports = async (ctx) => {
const illusts = response.data.illusts;
const username = illusts[0].user.name
ctx.body = template({
ctx.state.data = {
title: `${username} 的 pixiv 动态`,
link: `https://www.pixiv.net/member.php?id=${id}`,
description: `${username} 的 pixiv 最新动态`,
@ -44,5 +43,5 @@ module.exports = async (ctx) => {
link: `https://www.pixiv.net/member_illust.php?mode=medium&illust_id=${illust.id}`
};
})
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -54,7 +53,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(threadListHTML);
const list = $('#thread_list > .j_thread_list[data-field]');
ctx.body = template({
ctx.state.data = {
title: `${kw}`,
link: `https://tieba.baidu.com/f?kw=${encodeURIComponent(kw)}`,
item:
@ -83,5 +82,5 @@ module.exports = async (ctx) => {
};
}).
get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -27,9 +26,9 @@ module.exports = async (ctx)=>{
};
article_item.push(item);
};
ctx.body = template({
ctx.state.data = {
title: '开发者头条:' + title,
link: baseUrl,
item: article_item,
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -32,11 +31,11 @@ module.exports = async (ctx)=>{
};
article_item.push(item);
};
ctx.body = template({
ctx.state.data = {
title: '开发者头条独家号:'+title,
description:description,
image: image,
link: baseUrl,
item: article_item,
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
const md5 = require('../../utils/md5');
@ -19,7 +18,7 @@ module.exports = async (ctx) => {
});
const data = response.data.data;
ctx.body = template({
ctx.state.data = {
title: `${projectID} 的 吐个槽新帖`,
link: `https://support.qq.com/product/${projectID}`,
description: `${projectID} 的 吐个槽新帖`,
@ -38,5 +37,5 @@ module.exports = async (ctx) => {
link: `https://support.qq.com/products/${projectID}`
};
}),
});
};
};

View File

@ -1,4 +1,3 @@
const template = require('../../utils/template');
const Twit = require('twit');
const config = require('../../config');
@ -13,7 +12,7 @@ module.exports = async (ctx) => {
const data = result.data;
ctx.body = template({
ctx.state.data = {
title: `${data[0].user.name} 的 Twitter`,
link: `https://twitter.com/${id}/`,
description: data[0].user.description,
@ -23,5 +22,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.createdTime).toUTCString(),
link: `https://twitter.com/${id}/status/${item.id_str}`
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
const weiboUtils = require('./utils');
@ -16,7 +15,7 @@ module.exports = async (ctx) => {
});
const data = response.data.data.cards[0].card_group;
ctx.body = template({
ctx.state.data = {
title: `又有人在微博提到${keyword}`,
link: `http://s.weibo.com/weibo/${encodeURIComponent(keyword)}&b=1&nodup=1`,
description: `又有人在微博提到${keyword}`,
@ -29,5 +28,5 @@ module.exports = async (ctx) => {
link: `https://weibo.com/${item.mblog.user.id}/${item.mblog.bid}`
};
}),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
const weiboUtils = require('./utils');
@ -26,7 +25,7 @@ module.exports = async (ctx) => {
}
});
ctx.body = template({
ctx.state.data = {
title: `${name}的微博`,
link: `http://weibo.com/${uid}/`,
description: `${name}的微博`,
@ -39,5 +38,5 @@ module.exports = async (ctx) => {
link: `https://weibo.com/${uid}/${item.mblog.bid}`
};
}),
});
};
};

View File

@ -1,6 +1,5 @@
const { google } = require('googleapis');
const config = require('../../config');
const template = require('../../utils/template');
const youtube = google.youtube({
version: 'v3',
@ -22,7 +21,7 @@ module.exports = async (ctx) => {
});
const data = responst.data.items;
ctx.body = template({
ctx.state.data = {
title: `${data[0].snippet.channelTitle} 的 Youtube 视频`,
link: `https://www.youtube.com/channel/${id}`,
description: `${data[0].snippet.channelTitle} 的 Youtube 视频`,
@ -36,5 +35,5 @@ module.exports = async (ctx) => {
link: `https://www.youtube.com/watch?v=${snippet.resourceId.videoId}`
};
}),
});
};
};

View File

@ -1,6 +1,5 @@
const { google } = require('googleapis');
const config = require('../../config');
const template = require('../../utils/template');
const youtube = google.youtube({
version: 'v3',
@ -22,7 +21,7 @@ module.exports = async (ctx) => {
});
const data = responst.data.items;
ctx.body = template({
ctx.state.data = {
title: `${username} 的 Youtube 视频`,
link: `https://www.youtube.com/user/${username}`,
description: `${username} 的 Youtube 视频`,
@ -36,5 +35,5 @@ module.exports = async (ctx) => {
link: `https://www.youtube.com/watch?v=${snippet.resourceId.videoId}`
};
}),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -18,7 +17,7 @@ module.exports = async (ctx) => {
const data = response.data.data;
ctx.body = template({
ctx.state.data = {
title: `${data[0].actor.name}的知乎动态`,
link: `https://www.zhihu.com/people/${id}/activities`,
description: data[0].actor.headline || data[0].actor.description,
@ -75,5 +74,5 @@ module.exports = async (ctx) => {
link: url
};
}),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -18,7 +17,7 @@ module.exports = async (ctx) => {
const data = response.data.data;
ctx.body = template({
ctx.state.data = {
title: `${data[0].author.name}的知乎回答`,
link: `https://www.zhihu.com/people/${id}/answers`,
description: data[0].author.headline || data[0].author.description,
@ -28,5 +27,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.created_time * 1000).toUTCString(),
link: `https://www.zhihu.com/question/${item.question.id}/answer/${item.id}`
})),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const cheerio = require('cheerio');
const config = require('../../config');
@ -19,7 +18,7 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const list = $('div.zm-item');
ctx.body = template({
ctx.state.data = {
title: $('title').text(),
link: `https://www.zhihu.com/collection/${id}`,
description: `${$('#zh-fav-head-description').text()}`,
@ -33,5 +32,5 @@ module.exports = async (ctx) => {
link: linkUrl
};
}).get(),
});
};
};

View File

@ -1,5 +1,4 @@
const axios = require('axios');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -25,7 +24,7 @@ module.exports = async (ctx) => {
const list = listRes.data;
const info = infoRes.data;
ctx.body = template({
ctx.state.data = {
title: `知乎专栏-${info.name}`,
link: `https://zhuanlan.zhihu.com/${id}`,
description: info.description,
@ -35,5 +34,5 @@ module.exports = async (ctx) => {
pubDate: new Date(item.publishedTime).toUTCString(),
link: `https://zhuanlan.zhihu.com${item.url}`
})),
});
};
};

View File

@ -1,6 +1,5 @@
const axios = require('axios');
const qs = require('querystring');
const template = require('../../utils/template');
const config = require('../../config');
module.exports = async (ctx) => {
@ -30,7 +29,7 @@ module.exports = async (ctx) => {
//判断数据的类型,如果有数据就是数组类型的,没有数据的话,就赋值为空数组
data = (data instanceof Array) ? data : [{title:"我们找不到任何与您的搜索条件匹配的结果,但是调整您的搜索条件可能会有所帮助",room_name:"",list_img:"",city:"",id:""}];
ctx.body = template({
ctx.state.data = {
title: `自如的${keyword}${iswhole ? '整租' : '合租'}${room}室房源`,
link: `http://${domain}`,
description: `自如的${keyword}${iswhole ? '整租' : '合租'}${room}室房源`,
@ -39,5 +38,5 @@ module.exports = async (ctx) => {
description: `${item.room_name}<img referrerpolicy="no-referrer" src="${item.list_img}">`,
link: `http://${domain}/${city.toUpperCase()}/room/${item.id}.html`
})),
});
};
};